/** * Gets the entrySet view of the map. * Changes made via <code>setValue</code> affect this map. * To simply iterate through the entries, use {@link #mapIterator()}. * * @return the entrySet view */ @Override public Set<Map.Entry<K, V>> entrySet() { final Map.Entry<K, V> entry = new TiedMapEntry<>(this, getKey()); return Collections.singleton(entry); }
/** * Compares this <code>Map.Entry</code> with another <code>Map.Entry</code>. * <p> * Implemented per API documentation of {@link java.util.Map.Entry#equals(Object)} * * @param obj the object to compare to * @return true if equal key and value */ @Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (obj instanceof Map.Entry == false) { return false; } final Map.Entry<?,?> other = (Map.Entry<?,?>) obj; final Object value = getValue(); return (key == null ? other.getKey() == null : key.equals(other.getKey())) && (value == null ? other.getValue() == null : value.equals(other.getValue())); }
/** * Gets a hashCode compatible with the equals method. * <p> * Implemented per API documentation of {@link java.util.Map.Entry#hashCode()} * * @return a suitable hash code */ @Override public int hashCode() { final Object value = getValue(); return (getKey() == null ? 0 : getKey().hashCode()) ^ (value == null ? 0 : value.hashCode()); }