List of usage examples for java.util IdentityHashMap put
public V put(K key, V value)
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testClear() { IdentityHashMap hashMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(hashMap); hashMap.put("Hello", "Bye"); assertFalse(hashMap.isEmpty());/*w w w .jav a 2s. c om*/ assertTrue(hashMap.size() == SIZE_ONE); hashMap.clear(); assertTrue(hashMap.isEmpty()); assertTrue(hashMap.size() == 0); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testEquals() { IdentityHashMap hashMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(hashMap); hashMap.put(KEY_KEY, VALUE_VAL); IdentityHashMap copyMap = (IdentityHashMap) hashMap.clone(); assertTrue(hashMap.equals(copyMap)); hashMap.put(VALUE_VAL, KEY_KEY);/* w w w . j a va2s. c om*/ assertFalse(hashMap.equals(copyMap)); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testPut() { IdentityHashMap hashMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(hashMap); assertNull(hashMap.put(KEY_TEST_PUT, VALUE_TEST_PUT_1)); assertEquals(hashMap.put(KEY_TEST_PUT, VALUE_TEST_PUT_2), VALUE_TEST_PUT_1); assertNull(hashMap.put(null, VALUE_TEST_PUT_1)); assertEquals(hashMap.put(null, VALUE_TEST_PUT_2), VALUE_TEST_PUT_1); }
From source file:eu.eexcess.sourceselection.redde.indexer.topterm.TopTermToWNDomain.java
/** * Aligns terms word net domains./* w w w.ja v a 2 s . c o m*/ * * @param terms * array of terms to align (must be != null) * @throws Exception */ ValueTreeNode<String> assignToDomains(String[] terms) throws Exception { this.topTerms = terms; WordnetDomainsDetector wdt = new WordnetDomainsDetector(wordnetDomainDetectorFile, wordnetDomainsPath, true); inflateDomainTree(); // construct a domain map containing terms IdentityHashMap<String, HashSet<String>> domainToTerms = new IdentityHashMap<String, HashSet<String>>(); for (String term : terms) { Set<Domain> domains = wdt.detect(term); // if domains were detected if (domains.size() > 0) { String domainName = domains.iterator().next().getName(); HashSet<String> domainTerms = domainToTerms.get(domainName); // if domain is not seen so far if (domainTerms == null) { domainTerms = new HashSet<String>(); domainTerms.add(term); domainToTerms.put(domainName, domainTerms); } else { domainTerms.add(term); } } // mount the terms on the domain tree for (Map.Entry<String, HashSet<String>> entry : domainToTerms.entrySet()) { String domainName = entry.getKey(); Set<TreeNode<String>> resultCollector = new HashSet<TreeNode<String>>(); ValueTreeNode.findFirstNode(domainName, wnDomainTree, resultCollector); // find domain in tree if (resultCollector.iterator().hasNext()) { TreeNode<String> nodeInTree = resultCollector.iterator().next(); Set<String> domainTerms = entry.getValue(); ((ValueTreeNode<String>) nodeInTree).addValues(domainTerms); } } } return wnDomainTree; }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testAddEqualKeys() { final IdentityHashMap expected = new IdentityHashMap(); assertEquals(expected.size(), 0);//ww w . java2 s. c om iterateThrough(expected); expected.put(new Long(45), new Object()); assertEquals(expected.size(), 1); iterateThrough(expected); expected.put(new Integer(45), new Object()); assertNotSame(new Integer(45), new Long(45)); assertEquals(expected.size(), 2); iterateThrough(expected); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testHashMapMap() { IdentityHashMap srcMap = new IdentityHashMap(); assertNotNull(srcMap);//from w ww .ja v a 2 s . c o m checkEmptyHashMapAssumptions(srcMap); srcMap.put(INTEGER_1, INTEGER_11); srcMap.put(INTEGER_2, INTEGER_22); srcMap.put(INTEGER_3, INTEGER_33); IdentityHashMap hashMap = new IdentityHashMap(srcMap); assertFalse(hashMap.isEmpty()); assertTrue(hashMap.size() == SIZE_THREE); Collection valColl = hashMap.values(); assertTrue(valColl.contains(INTEGER_11)); assertTrue(valColl.contains(INTEGER_22)); assertTrue(valColl.contains(INTEGER_33)); Collection keyColl = hashMap.keySet(); assertTrue(keyColl.contains(INTEGER_1)); assertTrue(keyColl.contains(INTEGER_2)); assertTrue(keyColl.contains(INTEGER_3)); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
/** * Test method for 'java.util.IdentityHashMap.remove(Object)'. *//*from w w w .j a v a2 s . co m*/ public void testRemove() { IdentityHashMap hashMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(hashMap); assertNull(hashMap.remove(null)); hashMap.put(null, VALUE_TEST_REMOVE); assertNotNull(hashMap.remove(null)); hashMap.put(KEY_TEST_REMOVE, VALUE_TEST_REMOVE); assertEquals(hashMap.remove(KEY_TEST_REMOVE), VALUE_TEST_REMOVE); assertNull(hashMap.remove(KEY_TEST_REMOVE)); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
/** * Test method for 'java.util.AbstractMap.values()'. */// w ww .ja va2s .c om public void testValues() { IdentityHashMap hashMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(hashMap); assertNotNull(hashMap.values()); hashMap.put(KEY_KEY, VALUE_VAL); Collection valColl = hashMap.values(); assertNotNull(valColl); assertEquals(valColl.size(), SIZE_ONE); Iterator itVal = valColl.iterator(); String val = (String) itVal.next(); assertEquals(val, VALUE_VAL); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
/** * Test method for 'java.util.IdentityHashMap.putAll(Map)'. *///from www . j a v a 2 s .co m public void testPutAll() { IdentityHashMap srcMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(srcMap); srcMap.put(KEY_1, VALUE_1); srcMap.put(KEY_2, VALUE_2); srcMap.put(KEY_3, VALUE_3); // Make sure that the data is copied correctly IdentityHashMap dstMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(dstMap); dstMap.putAll(srcMap); assertEquals(srcMap.size(), dstMap.size()); assertTrue(dstMap.containsKey(KEY_1)); assertTrue(dstMap.containsValue(VALUE_1)); assertFalse(dstMap.containsKey(KEY_1.toUpperCase(Locale.ROOT))); assertFalse(dstMap.containsValue(VALUE_1.toUpperCase(Locale.ROOT))); assertTrue(dstMap.containsKey(KEY_2)); assertTrue(dstMap.containsValue(VALUE_2)); assertFalse(dstMap.containsKey(KEY_2.toUpperCase(Locale.ROOT))); assertFalse(dstMap.containsValue(VALUE_2.toUpperCase(Locale.ROOT))); assertTrue(dstMap.containsKey(KEY_3)); assertTrue(dstMap.containsValue(VALUE_3)); assertFalse(dstMap.containsKey(KEY_3.toUpperCase(Locale.ROOT))); assertFalse(dstMap.containsValue(VALUE_3.toUpperCase(Locale.ROOT))); // Check that an empty map does not blow away the contents of the // destination map IdentityHashMap emptyMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(emptyMap); dstMap.putAll(emptyMap); assertTrue(dstMap.size() == srcMap.size()); // Check that put all overwrite any existing mapping in the destination map srcMap.put(KEY_1, VALUE_2); srcMap.put(KEY_2, VALUE_3); srcMap.put(KEY_3, VALUE_1); dstMap.putAll(srcMap); assertEquals(dstMap.size(), srcMap.size()); assertEquals(dstMap.get(KEY_1), VALUE_2); assertEquals(dstMap.get(KEY_2), VALUE_3); assertEquals(dstMap.get(KEY_3), VALUE_1); // Check that a putAll does adds data but does not remove it srcMap.put(KEY_4, VALUE_4); dstMap.putAll(srcMap); assertEquals(dstMap.size(), srcMap.size()); assertTrue(dstMap.containsKey(KEY_4)); assertTrue(dstMap.containsValue(VALUE_4)); assertEquals(dstMap.get(KEY_1), VALUE_2); assertEquals(dstMap.get(KEY_2), VALUE_3); assertEquals(dstMap.get(KEY_3), VALUE_1); assertEquals(dstMap.get(KEY_4), VALUE_4); dstMap.putAll(dstMap); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testGet() { IdentityHashMap hashMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(hashMap); assertNull(hashMap.get(KEY_TEST_GET)); hashMap.put(KEY_TEST_GET, VALUE_TEST_GET); assertNotNull(hashMap.get(KEY_TEST_GET)); assertNull(hashMap.get(null));/*from www .ja v a 2 s . c o m*/ hashMap.put(null, VALUE_TEST_GET); assertNotNull(hashMap.get(null)); hashMap.put(null, null); assertNull(hashMap.get(null)); }