java.util.IdentityHashMap.keySet()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(125)

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

IdentityHashMap.keySet介绍

[英]Returns an identity-based set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear methods. It does not support the add or addAll methods.

While the object returned by this method implements the Set interface, it does not obey Set's general contract. Like its backing map, the set returned by this method defines element equality as reference-equality rather than object-equality. This affects the behavior of its contains, remove, containsAll, equals, and hashCode methods.

The equals method of the returned set returns true only if the specified object is a set containing exactly the same object references as the returned set. The symmetry and transitivity requirements of the Object.equals contract may be violated if the set returned by this method is compared to a normal set. However, the Object.equals contract is guaranteed to hold among sets returned by this method.

The hashCode method of the returned set returns the sum of the identity hashcodes of the elements in the set, rather than the sum of their hashcodes. This is mandated by the change in the semantics of the equals method, in order to enforce the general contract of the Object.hashCode method among sets returned by this method.
[中]返回此映射中包含的键的基于标识的集合视图。集合由映射支持,因此对映射的更改将反映在集合中,反之亦然。如果在对集合进行迭代时修改映射,则迭代的结果是未定义的。该集合支持元素移除,即通过迭代器从映射中移除相应的映射。移除,设置。移除、移除所有、保留和清除方法。它不支持add或addAll方法。
虽然此方法返回的对象实现了Set接口,但它不遵守Set的一般约定。与其后台映射一样,此方法返回的集合将元素相等定义为引用相等而不是对象相等。这会影响其contains、remove、containsAll、equals和hashCode方法的行为。
仅当指定的对象是包含与返回集完全相同的对象引用的集时,返回集的equals方法才会返回true。对象的对称性和及物性要求。如果将此方法返回的集合与正常集合进行比较,则可能违反equals契约。然而,这一目标是正确的。equals契约保证在该方法返回的集合之间保持不变。
返回集合的hashCode方法返回集合中元素的标识hashCode之和,而不是它们的hashCode之和。这是由equals方法的语义变化强制执行的,以便强制执行对象的一般契约。此方法返回的集合中的hashCode方法。

代码示例

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

/**
 * @return the doneList
 */
protected Set<Node> getDispatchedList() {
 return retMap.keySet();
}

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

/**
 * @return the doneList
 */
protected Set<Node> getDispatchedList() {
 return retMap.keySet();
}

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

@Override
public Collection<InternalRegion> getRegions() {
 return this.regions.keySet();
}

代码示例来源:origin: stanfordnlp/CoreNLP

/** Returns an iterator over the elements in this set. The elements are
 *  returned in no particular order.
 *
 *  @return an <code>Iterator</code> over the elements in this set.
 */
@Override
public Iterator<E> iterator() {
 return map.keySet().iterator();
}

代码示例来源:origin: hibernate/hibernate-orm

public Object[] toArray() {
  return map.keySet().toArray();
}

代码示例来源:origin: hibernate/hibernate-orm

public Iterator iterator() {
  return map.keySet().iterator();
}

代码示例来源:origin: hibernate/hibernate-orm

public Object[] toArray(Object[] a) {
  return map.keySet().toArray( a );
}

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

@Override @Nonnull
public Set<Class<?>> keySet() {
  return map.keySet();
}

代码示例来源:origin: Sable/soot

/**
 * {@inheritDoc}
 */
@Override
public String toString() {
 return delegate.keySet().toString();
}

代码示例来源:origin: Sable/soot

/**
 * {@inheritDoc}
 */
@Override
public Iterator<E> iterator() {
 return delegate.keySet().iterator();
}

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

/**
 * A single Vertex can appear once or twice. (CH graphs might have only outgoing or only
 * incoming edges.) Avoid double-counting.
 */
public Collection<Vertex> getVertices() {
  HashSet<Vertex> sv = new HashSet<Vertex>();
  sv.addAll(outgoing.keySet());
  sv.addAll(incoming.keySet());
  return sv;
}

代码示例来源:origin: Sable/soot

public java.util.Iterator iterator() { return map.keySet().iterator(); }
public int size() { return map.size(); }

代码示例来源:origin: org.apache.ant/ant

@Override
  public synchronized boolean containsAll(Collection<?> c) {
    IdentityHashMap<Object, Boolean> map = new IdentityHashMap<>();
    for (Object e : this) {
      map.put(e, Boolean.TRUE);
    }
    return map.keySet().containsAll(c);
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

public static IdentityHashMap<Tree, List<Tree>> convertToTrees(IdentityHashMap<Tree, byte[]> compressed, int numThreads) {
 return convertToTrees(compressed.keySet(), compressed, numThreads);
}

代码示例来源:origin: stanfordnlp/CoreNLP

public static Tree findRootTree(IdentityHashMap<Tree, SimpleMatrix> vectors) {
 for (Tree tree : vectors.keySet()) {
  if (tree.label().value().equals("ROOT")) {
   return tree;
  }
 }
 throw new RuntimeException("Could not find root");
}

代码示例来源:origin: real-logic/aeron

public Enumeration<NetworkInterface> getNetworkInterfaces()
{
  return Collections.enumeration(addressesByInterface.keySet());
}

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

@SuppressWarnings("unchecked")
private <T> Optional<ConsumerBase<T>> subscriptionExist(ConsumerConfigurationData<?> conf) {
  Optional<ConsumerBase<?>> subscriber = consumers.keySet().stream()
      .filter(consumerBase -> consumerBase.getSubType().equals(PulsarApi.CommandSubscribe.SubType.Shared))
      .filter(c -> c.getSubscription().equals(conf.getSubscriptionName()))
      .findFirst();
  return subscriber.map(ConsumerBase.class::cast);
}

代码示例来源:origin: stanfordnlp/CoreNLP

public double score(Tree tree, IdentityHashMap<Tree, SimpleMatrix> nodeVectors) {
 List<String> words = getContextWords(tree);
 // score of the entire tree is the sum of the scores of all of
 // its nodes
 // TODO: make the node vectors part of the tree itself?
 IdentityHashMap<Tree, Double> scores = new IdentityHashMap<>();
 try {
  forwardPropagateTree(tree, words, nodeVectors, scores);
 } catch (AssertionError e) {
  log.info("Failed to correctly process tree " + tree);
  throw e;
 }
 double score = 0.0;
 for (Tree node : scores.keySet()) {
  score += scores.get(node);
  //log.info(Double.toString(score));
 }
 return score;
}

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

public void stop() throws Exception {
 List<TezSessionPoolSession> sessionsToClose = null;
 synchronized (openSessions) {
  sessionsToClose = new ArrayList<TezSessionPoolSession>(openSessions.keySet());
 }
 for (TezSessionState sessionState : sessionsToClose) {
  sessionState.close(false);
 }
 if (expirationTracker != null) {
  expirationTracker.stop();
 }
 allocationManager.stop();
 if (wmThread != null) {
  wmThread.interrupt();
 }
 if (amComm != null) {
  amComm.stop();
 }
 workPool.shutdownNow();
 timeoutPool.shutdownNow();
 if (triggerValidatorRunnable != null) {
  stopTriggerValidator();
 }
 INSTANCE = null;
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testPopulatedIdentityMap() throws Exception {
  HasMap hasMap = (HasMap) this.beanFactory.getBean("identityMap");
  assertTrue(hasMap.getIdentityMap().size() == 2);
  HashSet set = new HashSet(hasMap.getIdentityMap().keySet());
  assertTrue(set.contains("foo"));
  assertTrue(set.contains("jenny"));
}

相关文章