/** * Gets the total size of the map by counting all the values. * * @return the total size of the map counting all values * @since Commons Collections 3.1 */ public int totalSize() { int total = 0; Collection values = super.values(); for (Iterator it = values.iterator(); it.hasNext();) { Collection coll = (Collection) it.next(); total += coll.size(); } return total; }
private static Cluster mockCluster() { HashMap<Integer, Node> nodes = new HashMap<>(); nodes.put(0, new Node(0, "localhost", 8121)); nodes.put(1, new Node(1, "localhost", 8122)); nodes.put(2, new Node(2, "localhost", 8123)); return new Cluster("mockClusterId", nodes.values(), Collections.<PartitionInfo>emptySet(), Collections.<String>emptySet(), Collections.<String>emptySet(), nodes.get(0)); }
HashMap<String, EntityImpl> entityMap = new HashMap<String, EntityImpl>(result.size()); entityMap.put(entity.getId(), entity); EntityImpl cachedEntity = (EntityImpl) cachedObject.getEntity(); if (cachedEntityMatcher.isRetained(result, cachedObjects, cachedEntity, parameter)) { entityMap.put(cachedEntity.getId(), cachedEntity); // will overwite db version with newer version EntityImpl cachedSubclassEntity = (EntityImpl) subclassCachedObject.getEntity(); if (cachedEntityMatcher.isRetained(result, cachedObjects, cachedSubclassEntity, parameter)) { entityMap.put(cachedSubclassEntity.getId(), cachedSubclassEntity); // will overwite db version with newer version result = entityMap.values(); Iterator<EntityImpl> resultIterator = result.iterator(); while (resultIterator.hasNext()) { if (getDbSqlSession().isEntityToBeDeleted(resultIterator.next())) { resultIterator.remove();
HashMap<Integer, String> map = new HashMap<Integer, String>(); map.put (1, "Mark"); map.put (2, "Tarryn"); List<String> list = new ArrayList<String>(map.values()); for (String s : list) { System.out.println(s); }
/** * The following code is for dealing with merging data fields in beacons */ @Nullable private Beacon trackGattBeacon(@NonNull Beacon beacon) { if (beacon.isExtraBeaconData()) { updateTrackedBeacons(beacon); return null; } String key = getBeaconKey(beacon); HashMap<Integer,Beacon> matchingTrackedBeacons = mBeaconsByKey.get(key); if (null == matchingTrackedBeacons) { matchingTrackedBeacons = new HashMap<>(); } else { Beacon trackedBeacon = matchingTrackedBeacons.values().iterator().next(); beacon.setExtraDataFields(trackedBeacon.getExtraDataFields()); } matchingTrackedBeacons.put(beacon.hashCode(), beacon); mBeaconsByKey.put(key, matchingTrackedBeacons); return beacon; }
HashMap<Integer, Node> mapNodes = new HashMap<>(); mapNodes.put(stat.id, new Node(stat.id)); Node node = mapNodes.get(stat.id); Node nodeSucc = mapNodes.get(succ.id); Node node = null; for (Node nd : mapNodes.values()) { if (nd.succs.contains(nd)) { // T1 ttype = 1; Node pred = node.preds.iterator().next(); return mapNodes.size() > 1; // reducible iff one node remains
@SuppressWarnings("unchecked") public Appender<ILoggingEvent> getAppender() { Map<String, Object> omap = interpreter.getInterpretationContext().getObjectMap(); HashMap<String, Appender<?>> appenderMap = (HashMap<String, Appender<?>>) omap.get(ActionConst.APPENDER_BAG); oneAndOnlyOneCheck(appenderMap); Collection<Appender<?>> values = appenderMap.values(); if (values.size() == 0) { return null; } return (Appender<ILoggingEvent>) values.iterator().next(); } }
/** * This method pre-computes the weights of groups to speed up processing * when validating a given set. We compute the weights of groups in * different places, so we have a separate method. */ private void computeGroupWeight(){ for (Entry<Long, Long> entry : serverGroup.entrySet()) { Long sid = entry.getKey(); Long gid = entry.getValue(); if(!groupWeight.containsKey(gid)) groupWeight.put(gid, serverWeight.get(sid)); else { long totalWeight = serverWeight.get(sid) + groupWeight.get(gid); groupWeight.put(gid, totalWeight); } } /* * Do not consider groups with weight zero */ for(long weight: groupWeight.values()){ LOG.debug("Group weight: " + weight); if(weight == ((long) 0)){ numGroups--; LOG.debug("One zero-weight group: " + 1 + ", " + numGroups); } } }
public void foo() { m.put("a", "a"); Set<Map.Entry<Integer, Integer>> es = new HashSet<Map.Entry<Integer, Integer>>(); boolean b1 = m.entrySet().contains(1); // bad boolean b2 = m.keySet().contains(1); // ok boolean b3 = m.values().contains(1); // ok boolean b4 = m.entrySet().equals(es); // ok boolean b5 = m.entrySet().equals(is); // bad m.entrySet().contains(1); // bad boolean b6 = m.keySet().equals(is); // ok boolean b7 = m.values().equals(is); // ok System.out.printf("%b %b %b %b %b %b %b\n", b1, b2, b3, b4, b5, b6, b7); } }
private void removeOldTempIndexes() { if (tempObjects != null) { metaObjects.putAll(tempObjects); for (PageIndex index: tempObjects.values()) { if (index.getTable().isTemporary()) { index.truncate(pageStoreSession); index.remove(pageStoreSession); } } pageStoreSession.commit(true); tempObjects = null; } metaObjects.clear(); metaObjects.put(-1, metaIndex); }
/** * Gets the total size of the map by counting all the values. * * @return the total size of the map counting all values * @since Commons Collections 3.1 */ public int totalSize() { int total = 0; Collection values = super.values(); for (Iterator it = values.iterator(); it.hasNext();) { Collection coll = (Collection) it.next(); total += coll.size(); } return total; }
private static Cluster mockCluster(int controllerIndex) { HashMap<Integer, Node> nodes = new HashMap<>(); nodes.put(0, new Node(0, "localhost", 8121)); nodes.put(1, new Node(1, "localhost", 8122)); nodes.put(2, new Node(2, "localhost", 8123)); return new Cluster("mockClusterId", nodes.values(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), nodes.get(controllerIndex)); }
@Test public void testJUHashMap3() { final int count = 100000; final java.util.HashMap map = new java.util.HashMap(); assertNotNull( map ); for ( int idx = 0; idx < count; idx++ ) { final String key = "key" + idx; final String strval = "value" + idx; map.put( key, strval ); } final long start = System.currentTimeMillis(); final java.util.Iterator itr = map.values().iterator(); while ( itr.hasNext() ) { itr.next().hashCode(); } final long end = System.currentTimeMillis(); System.out.println( "java.util.HashMap iterate ET - " + ((end - start)) ); }
public static AnnotationMap merge(AnnotationMap primary, AnnotationMap secondary) { if (primary == null || primary._annotations == null || primary._annotations.isEmpty()) { return secondary; } if (secondary == null || secondary._annotations == null || secondary._annotations.isEmpty()) { return primary; } HashMap<Class<?>,Annotation> annotations = new HashMap<Class<?>,Annotation>(); // add secondary ones first for (Annotation ann : secondary._annotations.values()) { annotations.put(ann.annotationType(), ann); } // to be overridden by primary ones for (Annotation ann : primary._annotations.values()) { annotations.put(ann.annotationType(), ann); } return new AnnotationMap(annotations); }
this.coordinates.put(v.getCoordinate(), iV); this.vertices.put(iV, new Vertex(iV, v.getCoordinate())); iV++; HashMap<QuadEdge, Double> qeDistances = new HashMap<QuadEdge, Double>(); for (QuadEdge qe : quadEdges) { qeDistances.put(qe, qe.toLineSegment().getLength()); s.normalize(); Integer idS = this.coordinates.get(s.p0); Integer idD = this.coordinates.get(s.p1); Vertex oV = this.vertices.get(idS); Vertex eV = this.vertices.get(idD); for (Edge edge : this.edges.values()) { if (edge.getTriangles().size() > 1) { Triangle tA = edge.getTriangles().get(0); for (Edge e : this.shortLengths.values()) { LineString l = e.getGeometry().toGeometry(this.geomFactory); edges.add(l); LineString merge = (LineString)lineMerger.getMergedLineStrings().iterator().next();