java.util.Map.Entry#hashCode ( )源码实例Demo

下面列出了java.util.Map.Entry#hashCode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。


@Test
public void testMapEntryHashCode()
{
    final Entry<String, String> entry = rootMap.entrySet().iterator().next();
    final int origEntryHashCode = entry.hashCode();
    final int origMapHashCode = rootMap.hashCode();

    final String originalValue = entry.getValue();
    entry.setValue("otherValue");

    assertNotEquals(origEntryHashCode, entry.hashCode());

    entry.setValue(originalValue);

    assertEquals(origMapHashCode, rootMap.hashCode());
}
 
源代码2 项目: talkback   文件: ScreenState.java

@Override
public int hashCode() {
  int h = 0;
  Iterator<Entry<Integer, AccessibilityWindowInfo>> iterator =
      idToWindowInfoMap.entrySet().iterator();
  while (iterator.hasNext()) {
    Entry<Integer, AccessibilityWindowInfo> entry = iterator.next();
    h += entry.hashCode() ^ Objects.hashCode(getWindowTitle(entry.getKey()));
  }
  return h;
}
 
源代码3 项目: Bytecoder   文件: AbstractMap.java

/**
 * Returns the hash code value for this map.  The hash code of a map is
 * defined to be the sum of the hash codes of each entry in the map's
 * {@code entrySet()} view.  This ensures that {@code m1.equals(m2)}
 * implies that {@code m1.hashCode()==m2.hashCode()} for any two maps
 * {@code m1} and {@code m2}, as required by the general contract of
 * {@link Object#hashCode}.
 *
 * @implSpec
 * This implementation iterates over {@code entrySet()}, calling
 * {@link Map.Entry#hashCode hashCode()} on each element (entry) in the
 * set, and adding up the results.
 *
 * @return the hash code value for this map
 * @see Map.Entry#hashCode()
 * @see Object#equals(Object)
 * @see Set#equals(Object)
 */
public int hashCode() {
    int h = 0;
    for (Entry<K, V> entry : entrySet())
        h += entry.hashCode();
    return h;
}
 
源代码4 项目: openjdk-jdk9   文件: AbstractMap.java

/**
 * Returns the hash code value for this map.  The hash code of a map is
 * defined to be the sum of the hash codes of each entry in the map's
 * {@code entrySet()} view.  This ensures that {@code m1.equals(m2)}
 * implies that {@code m1.hashCode()==m2.hashCode()} for any two maps
 * {@code m1} and {@code m2}, as required by the general contract of
 * {@link Object#hashCode}.
 *
 * @implSpec
 * This implementation iterates over {@code entrySet()}, calling
 * {@link Map.Entry#hashCode hashCode()} on each element (entry) in the
 * set, and adding up the results.
 *
 * @return the hash code value for this map
 * @see Map.Entry#hashCode()
 * @see Object#equals(Object)
 * @see Set#equals(Object)
 */
public int hashCode() {
    int h = 0;
    for (Entry<K, V> entry : entrySet())
        h += entry.hashCode();
    return h;
}