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);
}
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;
}
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());
}
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());
}
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();
}
});
}
Aggregations