/** * Compares the specified object with this entry for equality. * Returns true if the given object is also a map entry and * the two entries represent the same mapping. * * @param obj the object to be compared for equality with this entry. * @return true if the specified object is equal to this entry. */ @Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (!(obj instanceof Map.Entry)) { return false; } final Map.Entry<?, ?> e = (Map.Entry<?, ?>) obj; return getKey().equals(e.getKey()) && getValue().equals(e.getValue()); }
/** * @return the hash code value for this map entry. */ @Override public int hashCode() { if (!calculatedHashCode) { hashcodeValue = getKey().hashCode() ^ getValue().hashCode(); calculatedHashCode = true; } return hashcodeValue; } }
private Object getData(final DataElement dataElement) { switch (dataElement) { case KEY: return getKey(); case VALUE: return getValue(); default: throw new IllegalArgumentException(); } }
/** * Gets the value to which this map maps the specified key. * Returns null if the map contains no mapping for this key. * <p> * The key must implement <code>Comparable</code>. * * @param key key whose associated value is to be returned * @return the value to which this map maps the specified key, * or null if the map contains no mapping for this key * @throws ClassCastException if the key is of an inappropriate type * @throws NullPointerException if the key is null */ @Override public V get(final Object key) { checkKey(key); final Node<K, V> node = lookupKey(key); return node == null ? null : node.getValue(); }
private V doRemoveKey(final Object key) { final Node<K, V> node = lookupKey(key); if (node == null) { return null; } doRedBlackDelete(node); return node.getValue(); }