Search in sources :

Example 81 with IdentityHashMap

use of java.util.IdentityHashMap in project j2objc by google.

the class AbstractMapTest method test_removeLjava_lang_Object.

/**
     * @tests java.util.AbstractMap#remove(java.lang.Object)
     */
public void test_removeLjava_lang_Object() {
    Object key = new Object();
    Object value = new Object();
    AbstractMap map1 = new HashMap(0);
    map1.put("key", value);
    assertSame("HashMap(0)", map1.remove("key"), value);
    AbstractMap map4 = new IdentityHashMap(1);
    map4.put(key, value);
    assertSame("IdentityHashMap", map4.remove(key), value);
    AbstractMap map5 = new LinkedHashMap(122);
    map5.put(key, value);
    assertSame("LinkedHashMap", map5.remove(key), value);
    AbstractMap map6 = new TreeMap(new Comparator() {

        // Bogus comparator
        public int compare(Object object1, Object object2) {
            return 0;
        }
    });
    map6.put(key, value);
    assertSame("TreeMap", map6.remove(key), value);
    AbstractMap aSpecialMap = new MyMap();
    aSpecialMap.put(specialKey, specialValue);
    Object valueOut = aSpecialMap.remove(specialKey);
    assertSame("MyMap", valueOut, specialValue);
}
Also used : AbstractMap(java.util.AbstractMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) Comparator(java.util.Comparator)

Example 82 with IdentityHashMap

use of java.util.IdentityHashMap in project translationstudio8 by heartsome.

the class DBOperator method getTermBaseResult.

/**
	 * 搜索术语库
	 * @param strSearch
	 *            搜索文本
	 * @param isCaseSensitive
	 *            是否区分大小写
	 * @param isApplyRegular
	 *            是否使用正则表达式
	 * @param strLang
	 *            源语言
	 * @param lstLangs
	 *            语言集合(包括源语言)
	 * @param intMatchQuality
	 *            术语相似度
	 * @param intMax
	 *            最大查找结果数
	 * @return ;
	 */
public HashMap<String, IdentityHashMap<String, String>> getTermBaseResult(String strSearch, boolean isCaseSensitive, boolean isApplyRegular, boolean isIgnoreMark, String strLang, List<String> lstLangs, int intMatchQuality) {
    String sql = getTermBaseSearchSql(strSearch, isCaseSensitive, isApplyRegular, isIgnoreMark, strLang, lstLangs);
    // System.out.println(sql);
    if (sql == null) {
        return null;
    }
    HashMap<String, IdentityHashMap<String, String>> mapTermBase = new HashMap<String, IdentityHashMap<String, String>>();
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        stmt = conn.prepareStatement(sql);
        rs = stmt.executeQuery();
        ArrayList<String> lstRemoveGroupId = new ArrayList<String>();
        boolean blnIsNext = rs.next();
        while (blnIsNext) {
            String strGroupId = rs.getString("GROUPID");
            String strLanguageString = rs.getString("LANG");
            String strTextString = rs.getString("TMTEXT");
            if (lstRemoveGroupId.contains(strGroupId)) {
                if (mapTermBase.containsKey(strGroupId)) {
                    mapTermBase.remove(strGroupId);
                }
                blnIsNext = rs.next();
                continue;
            }
            int distance = -1;
            if (!isApplyRegular) {
                if (strLanguageString.equalsIgnoreCase(strLang)) {
                    if (isCaseSensitive) {
                        distance = MatchQuality.similarity(strTextString, strSearch);
                    } else {
                        distance = MatchQuality.similarity(strTextString.toLowerCase(), strSearch.toLowerCase());
                    }
                    if (distance < intMatchQuality) {
                        if (mapTermBase.containsKey(strGroupId)) {
                            mapTermBase.remove(strGroupId);
                        }
                        lstRemoveGroupId.add(strGroupId);
                        blnIsNext = rs.next();
                        continue;
                    }
                }
            }
            if (mapTermBase.containsKey(strGroupId)) {
                mapTermBase.get(strGroupId).put(strLanguageString, strTextString);
            } else {
                IdentityHashMap<String, String> mapTemp = new IdentityHashMap<String, String>();
                mapTemp.put(strLanguageString, strTextString);
                mapTermBase.put(strGroupId, mapTemp);
            }
            if (distance > -1) {
                // 将相似度存起来用于排序
                mapTermBase.get(strGroupId).put("similarity", String.valueOf(distance));
            }
            blnIsNext = rs.next();
        }
    } catch (SQLException e) {
        LOGGER.error("", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (SQLException e) {
                LOGGER.error("", e);
            }
        }
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                LOGGER.error("", e);
            }
        }
    }
    Iterator<Entry<String, IdentityHashMap<String, String>>> it = mapTermBase.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, IdentityHashMap<String, String>> e = it.next();
        // 2 表示集合中只有源语言和 similarity 两个值
        if (e.getValue().containsKey("similarity") && e.getValue().size() <= 2) {
            it.remove();
        } else if (!e.getValue().containsKey("similarity") && e.getValue().size() == 1) {
            it.remove();
        }
    }
    return mapTermBase;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) SQLException(java.sql.SQLException) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Entry(java.util.Map.Entry) ResultSet(java.sql.ResultSet)

Example 83 with IdentityHashMap

use of java.util.IdentityHashMap in project j2objc by google.

the class AbstractMapTest method test_keySet.

/**
     * @tests java.util.AbstractMap#keySet()
     */
public void test_keySet() {
    AbstractMap map1 = new HashMap(0);
    assertSame("HashMap(0)", map1.keySet(), map1.keySet());
    AbstractMap map2 = new HashMap(10);
    assertSame("HashMap(10)", map2.keySet(), map2.keySet());
    Map map3 = Collections.EMPTY_MAP;
    assertSame("EMPTY_MAP", map3.keySet(), map3.keySet());
    AbstractMap map4 = new IdentityHashMap(1);
    assertSame("IdentityHashMap", map4.keySet(), map4.keySet());
    AbstractMap map5 = new LinkedHashMap(122);
    assertSame("LinkedHashMap", map5.keySet(), map5.keySet());
    AbstractMap map6 = new TreeMap();
    assertSame("TreeMap", map6.keySet(), map6.keySet());
}
Also used : AbstractMap(java.util.AbstractMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 84 with IdentityHashMap

use of java.util.IdentityHashMap in project j2objc by google.

the class AbstractMapTest method test_values.

/**
     * @tests java.util.AbstractMap#values()
     */
public void test_values() {
    AbstractMap map1 = new HashMap(0);
    assertSame("HashMap(0)", map1.values(), map1.values());
    AbstractMap map2 = new HashMap(10);
    assertSame("HashMap(10)", map2.values(), map2.values());
    Map map3 = Collections.EMPTY_MAP;
    assertSame("EMPTY_MAP", map3.values(), map3.values());
    AbstractMap map4 = new IdentityHashMap(1);
    assertSame("IdentityHashMap", map4.values(), map4.values());
    AbstractMap map5 = new LinkedHashMap(122);
    assertSame("IdentityHashMap", map5.values(), map5.values());
    AbstractMap map6 = new TreeMap();
    assertSame("TreeMap", map6.values(), map6.values());
}
Also used : AbstractMap(java.util.AbstractMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 85 with IdentityHashMap

use of java.util.IdentityHashMap in project j2objc by google.

the class RetainedWithTest method testMapChildren.

public void testMapChildren() {
    runMapTest(new MapFactory(new Object()) {

        public Map newMap() {
            return new IdentityHashMap();
        }
    });
    runMapTest(new MapFactory(new Object()) {

        public Map newMap() {
            return new WeakHashMap();
        }
    });
    runMapTest(new MapFactory(Color.RED) {

        public Map newMap() {
            return new EnumMap(Color.class);
        }
    });
    runMapTest(new MapFactory(new Object()) {

        public Map newMap() {
            return new HashMap();
        }
    });
    runMapTest(new MapFactory(5) {

        public Map newMap() {
            return new TreeMap();
        }
    });
    runMapTest(new MapFactory(new Object()) {

        public Map newMap() {
            return new Hashtable();
        }
    });
    runMapTest(new MapFactory(new Object()) {

        public Map newMap() {
            return new ConcurrentHashMap();
        }
    });
}
Also used : IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) Hashtable(java.util.Hashtable) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IdentityHashMap(java.util.IdentityHashMap) EnumMap(java.util.EnumMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) WeakHashMap(java.util.WeakHashMap) EnumMap(java.util.EnumMap) WeakHashMap(java.util.WeakHashMap)

Aggregations

IdentityHashMap (java.util.IdentityHashMap)142 Map (java.util.Map)44 HashMap (java.util.HashMap)42 ArrayList (java.util.ArrayList)31 HashSet (java.util.HashSet)20 LinkedHashMap (java.util.LinkedHashMap)18 Collection (java.util.Collection)16 Set (java.util.Set)16 TreeMap (java.util.TreeMap)16 Iterator (java.util.Iterator)14 AbstractMap (java.util.AbstractMap)13 List (java.util.List)11 Test (org.junit.Test)11 DependencyNode (org.sonatype.aether.graph.DependencyNode)10 WeakHashMap (java.util.WeakHashMap)8 LinkedList (java.util.LinkedList)7 TreeSet (java.util.TreeSet)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 Tree (edu.stanford.nlp.trees.Tree)6 IOException (java.io.IOException)6