java.util.HashMap.values()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中java.util.HashMap.values()方法的一些代码示例,展示了HashMap.values()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashMap.values()方法的具体详情如下:
包路径:java.util.HashMap
类名称:HashMap
方法名:values

HashMap.values介绍

[英]Returns a collection of the values contained in this map. The collection is backed by this map so changes to one are reflected by the other. The collection supports remove, removeAll, retainAll and clear operations, and it does not support add or addAll operations.

This method returns a collection which is the subclass of AbstractCollection. The iterator method of this subclass returns a "wrapper object" over the iterator of map's entrySet(). The sizemethod wraps the map's size method and the contains method wraps the map's containsValue method.

The collection is created when this method is called for the first time and returned in response to all subsequent calls. This method may return different collections when multiple concurrent calls occur, since no synchronization is performed.
[中]返回此映射中包含的值的集合。集合由此映射支持,因此对其中一个映射的更改将由另一个映射反映。集合支持移除、移除、保留和清除操作,不支持添加或添加所有操作。
此方法返回一个集合,该集合是AbstractCollection的子类。该子类的迭代器方法在map的entrySet()的迭代器上返回一个“包装器对象”。sizemethod包装映射的size方法,contains方法包装映射的containsValue方法。
该集合是在第一次调用此方法时创建的,并在响应所有后续调用时返回。由于不执行同步,因此当发生多个并发调用时,此方法可能返回不同的集合。

代码示例

代码示例来源:origin: prestodb/presto

/**
 * @since 2.3
 */
public Iterable<Annotation> annotations() {
  if (_annotations == null || _annotations.size() == 0) {
    return Collections.emptyList();
  }
  return _annotations.values();
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Gets the values iterator from the superclass, as used by inner class.
 *
 * @return iterator
 */
Iterator superValuesIterator() {
  return super.values().iterator();
}

代码示例来源:origin: redisson/redisson

public CtMethod[] getMethods() {
  HashMap h = new HashMap();
  getMethods0(h, this);
  return (CtMethod[])h.values().toArray(new CtMethod[h.size()]);
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * 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;
}

代码示例来源:origin: apache/kafka

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

代码示例来源:origin: Activiti/Activiti

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

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: AltBeacon/android-beacon-library

/**
 * 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;
}

代码示例来源:origin: fesh0r/fernflower

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

代码示例来源:origin: ch.qos.logback/logback-classic

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

代码示例来源:origin: apache/zookeeper

/**
 * 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);
    }
  }
}

代码示例来源:origin: org.apache.lucene/lucene-core

FieldInfos finish() {
  finished = true;
  return new FieldInfos(byName.values().toArray(new FieldInfo[byName.size()]));
 }
}

代码示例来源:origin: spotbugs/spotbugs

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

代码示例来源:origin: com.h2database/h2

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

代码示例来源:origin: wildfly/wildfly

/**
 * 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;
}

代码示例来源:origin: apache/kafka

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

代码示例来源:origin: org.drools/drools-core

@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)) );
}

代码示例来源:origin: prestodb/presto

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

代码示例来源:origin: opentripplanner/OpenTripPlanner

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

代码示例来源:origin: scouter-project/scouter

public CtMethod[] getMethods() {
  HashMap h = new HashMap();
  getMethods0(h, this);
  return (CtMethod[])h.values().toArray(new CtMethod[h.size()]);
}

相关文章