List of usage examples for java.util IdentityHashMap entrySet
Set entrySet
To view the source code for java.util IdentityHashMap entrySet.
Click Source Link
From source file:Main.java
public static void main(String[] argv) throws Exception { IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>(); Object o1 = new Integer(123); Object o2 = new Integer(123); objMap.put(o1, "first"); objMap.put(o2, "from java2s.com"); Object v1 = objMap.get(o1);//from w w w.j a v a 2 s . c o m System.out.println(v1); Object v2 = objMap.get(o2); System.out.println(v2); // create entry set from the map Set<Entry<Object, Object>> enset = objMap.entrySet(); System.out.println("Set view of the map: " + enset); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
/** * Check the state of a newly constructed, empty IdentityHashMap. * * @param hashMap//from w w w . ja v a 2s . c o m */ private static void checkEmptyHashMapAssumptions(IdentityHashMap hashMap) { assertNotNull(hashMap); assertTrue(hashMap.isEmpty()); assertNotNull(hashMap.values()); assertTrue(hashMap.values().isEmpty()); assertTrue(hashMap.values().size() == 0); assertNotNull(hashMap.keySet()); assertTrue(hashMap.keySet().isEmpty()); assertTrue(hashMap.keySet().size() == 0); assertNotNull(hashMap.entrySet()); assertTrue(hashMap.entrySet().isEmpty()); assertTrue(hashMap.entrySet().size() == 0); assertNotNull(hashMap.entrySet().iterator()); assertFalse(hashMap.entrySet().iterator().hasNext()); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
private Iterator iterateThrough(final IdentityHashMap expected) { Iterator iter = expected.entrySet().iterator(); for (int i = 0; i < expected.size(); i++) { iter.next();//from w w w . j ava2 s . com } return iter; }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testEntrySetRemove() { IdentityHashMap hashMap = new IdentityHashMap(); hashMap.put("A", "B"); IdentityHashMap dummy = new IdentityHashMap(); dummy.put("A", "b"); Entry bogus = (Entry) dummy.entrySet().iterator().next(); Set entrySet = hashMap.entrySet(); boolean removed = entrySet.remove(bogus); assertEquals(removed, false);/* w w w . jav a2 s . c o m*/ assertEquals(hashMap.get("A"), "B"); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testEntrySet() { IdentityHashMap hashMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(hashMap); Set entrySet = hashMap.entrySet(); assertNotNull(entrySet);/* w w w .ja va2 s.com*/ // Check that the entry set looks right hashMap.put(KEY_TEST_ENTRY_SET, VALUE_TEST_ENTRY_SET_1); entrySet = hashMap.entrySet(); assertEquals(entrySet.size(), SIZE_ONE); Iterator itSet = entrySet.iterator(); Map.Entry entry = (Map.Entry) itSet.next(); assertEquals(entry.getKey(), KEY_TEST_ENTRY_SET); assertEquals(entry.getValue(), VALUE_TEST_ENTRY_SET_1); // Check that entries in the entrySet are update correctly on overwrites hashMap.put(KEY_TEST_ENTRY_SET, VALUE_TEST_ENTRY_SET_2); entrySet = hashMap.entrySet(); assertEquals(entrySet.size(), SIZE_ONE); itSet = entrySet.iterator(); entry = (Map.Entry) itSet.next(); assertEquals(entry.getKey(), KEY_TEST_ENTRY_SET); assertEquals(entry.getValue(), VALUE_TEST_ENTRY_SET_2); // Check that entries are updated on removes hashMap.remove(KEY_TEST_ENTRY_SET); checkEmptyHashMapAssumptions(hashMap); }
From source file:com.google.gwt.emultest.java.util.IdentityHashMapTest.java
public void testClone() { IdentityHashMap srcMap = new IdentityHashMap(); checkEmptyHashMapAssumptions(srcMap); // Check empty clone behavior IdentityHashMap dstMap = (IdentityHashMap) srcMap.clone(); assertNotNull(dstMap);/*from www. ja v a2 s.c om*/ assertEquals(dstMap.size(), srcMap.size()); // assertTrue(dstMap.values().toArray().equals(srcMap.values().toArray())); assertTrue(dstMap.keySet().equals(srcMap.keySet())); assertTrue(dstMap.entrySet().equals(srcMap.entrySet())); // Check non-empty clone behavior srcMap.put(KEY_1, VALUE_1); srcMap.put(KEY_2, VALUE_2); srcMap.put(KEY_3, VALUE_3); dstMap = (IdentityHashMap) srcMap.clone(); assertNotNull(dstMap); assertEquals(dstMap.size(), srcMap.size()); assertTrue(dstMap.keySet().equals(srcMap.keySet())); assertTrue(dstMap.entrySet().equals(srcMap.entrySet())); }
From source file:eu.eexcess.sourceselection.redde.indexer.topterm.TopTermToWNDomain.java
/** * Aligns terms word net domains.//w w w. j a v a2 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:org.jamocha.rating.fraj.RatingProvider.java
private double rateBetaWithoutExistentials(final StatisticsProvider statisticsProvider, final PathNodeFilterSet toRate, final Map<Set<PathFilterList>, List<Pair<List<Set<PathFilterList>>, List<PathFilter>>>> componentToJoinOrder, final Map<Path, Set<PathFilterList>> pathToPreNetworkComponents) { final IdentityHashMap<Set<PathFilterList>, Data> preNetworkComponentToData = new IdentityHashMap<>(); for (final Set<PathFilterList> comp : componentToJoinOrder.keySet()) { preNetworkComponentToData.put(comp, statisticsProvider.getData(comp)); }/*from w ww. ja v a 2 s . co m*/ final double tupleSize = preNetworkComponentToData.values().stream().mapToDouble(Data::getTupleSize).sum(); final double tuplesPerPage = statisticsProvider.getPageSize() / tupleSize; final double rowCount = calcBetaUnfilteredSize(statisticsProvider, componentToJoinOrder, pathToPreNetworkComponents, componentToJoinOrder.keySet()); // joinsize is needed twice per component, thus pre-calculate it final Map<Set<PathFilterList>, Double> preNetworkComponentToJoinSize = preNetworkComponentToData.keySet() .stream() .collect(toMap(Function.identity(), component -> joinSize(statisticsProvider, component, componentToJoinOrder.get(component), componentToJoinOrder.keySet(), pathToPreNetworkComponents))); final double finsert = preNetworkComponentToData.entrySet().stream() .mapToDouble( entry -> entry.getValue().getFinsert() * preNetworkComponentToJoinSize.get(entry.getKey())) .sum(); final double fdelete = preNetworkComponentToData.values().stream().mapToDouble(Data::getFdelete).sum(); // publish information to statistics provider { final Set<PathFilterList> filters = new HashSet<>(); componentToJoinOrder.keySet().forEach(filters::addAll); filters.add(toRate); statisticsProvider.setData(filters, new Data(finsert, fdelete, rowCount, tupleSize)); } final double mxBeta = m(rowCount, tuplesPerPage); final double runtimeCost = preNetworkComponentToData.entrySet().stream().mapToDouble(entry -> { final Set<PathFilterList> component = entry.getKey(); final Data data = entry.getValue(); return data.getFinsert() * costPosInsVarI(statisticsProvider, component, componentToJoinOrder.get(component), componentToJoinOrder.keySet(), pathToPreNetworkComponents) + data.getFdelete() * (mxBeta + cardenas(mxBeta, preNetworkComponentToJoinSize.get(component))); }).sum(); final double memoryCost = rowCount * tupleSize; return cpuAndMemCostCombiner.applyAsDouble(runtimeCost, memoryCost); }