下面列出了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());
}
@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;
}
/**
* 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;
}
/**
* 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;
}