0N/A/*
3261N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.util;
0N/Aimport java.util.Map.Entry;
0N/A
0N/A/**
0N/A * This class provides a skeletal implementation of the <tt>Map</tt>
0N/A * interface, to minimize the effort required to implement this interface.
0N/A *
0N/A * <p>To implement an unmodifiable map, the programmer needs only to extend this
0N/A * class and provide an implementation for the <tt>entrySet</tt> method, which
0N/A * returns a set-view of the map's mappings. Typically, the returned set
0N/A * will, in turn, be implemented atop <tt>AbstractSet</tt>. This set should
0N/A * not support the <tt>add</tt> or <tt>remove</tt> methods, and its iterator
0N/A * should not support the <tt>remove</tt> method.
0N/A *
0N/A * <p>To implement a modifiable map, the programmer must additionally override
0N/A * this class's <tt>put</tt> method (which otherwise throws an
0N/A * <tt>UnsupportedOperationException</tt>), and the iterator returned by
0N/A * <tt>entrySet().iterator()</tt> must additionally implement its
0N/A * <tt>remove</tt> method.
0N/A *
0N/A * <p>The programmer should generally provide a void (no argument) and map
0N/A * constructor, as per the recommendation in the <tt>Map</tt> interface
0N/A * specification.
0N/A *
0N/A * <p>The documentation for each non-abstract method in this class describes its
0N/A * implementation in detail. Each of these methods may be overridden if the
0N/A * map being implemented admits a more efficient implementation.
0N/A *
0N/A * <p>This class is a member of the
0N/A * <a href="{@docRoot}/../technotes/guides/collections/index.html">
0N/A * Java Collections Framework</a>.
0N/A *
0N/A * @param <K> the type of keys maintained by this map
0N/A * @param <V> the type of mapped values
0N/A *
0N/A * @author Josh Bloch
0N/A * @author Neal Gafter
0N/A * @see Map
0N/A * @see Collection
0N/A * @since 1.2
0N/A */
0N/A
0N/Apublic abstract class AbstractMap<K,V> implements Map<K,V> {
0N/A /**
0N/A * Sole constructor. (For invocation by subclass constructors, typically
0N/A * implicit.)
0N/A */
0N/A protected AbstractMap() {
0N/A }
0N/A
0N/A // Query Operations
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A *
0N/A * <p>This implementation returns <tt>entrySet().size()</tt>.
0N/A */
0N/A public int size() {
0N/A return entrySet().size();
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A *
0N/A * <p>This implementation returns <tt>size() == 0</tt>.
0N/A */
0N/A public boolean isEmpty() {
0N/A return size() == 0;
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A *
0N/A * <p>This implementation iterates over <tt>entrySet()</tt> searching
0N/A * for an entry with the specified value. If such an entry is found,
0N/A * <tt>true</tt> is returned. If the iteration terminates without
0N/A * finding such an entry, <tt>false</tt> is returned. Note that this
0N/A * implementation requires linear time in the size of the map.
0N/A *
0N/A * @throws ClassCastException {@inheritDoc}
0N/A * @throws NullPointerException {@inheritDoc}
0N/A */
0N/A public boolean containsValue(Object value) {
0N/A Iterator<Entry<K,V>> i = entrySet().iterator();
0N/A if (value==null) {
0N/A while (i.hasNext()) {
0N/A Entry<K,V> e = i.next();
0N/A if (e.getValue()==null)
0N/A return true;
0N/A }
0N/A } else {
0N/A while (i.hasNext()) {
0N/A Entry<K,V> e = i.next();
0N/A if (value.equals(e.getValue()))
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A *
0N/A * <p>This implementation iterates over <tt>entrySet()</tt> searching
0N/A * for an entry with the specified key. If such an entry is found,
0N/A * <tt>true</tt> is returned. If the iteration terminates without
0N/A * finding such an entry, <tt>false</tt> is returned. Note that this
0N/A * implementation requires linear time in the size of the map; many
0N/A * implementations will override this method.
0N/A *
0N/A * @throws ClassCastException {@inheritDoc}
0N/A * @throws NullPointerException {@inheritDoc}
0N/A */
0N/A public boolean containsKey(Object key) {
0N/A Iterator<Map.Entry<K,V>> i = entrySet().iterator();
0N/A if (key==null) {
0N/A while (i.hasNext()) {
0N/A Entry<K,V> e = i.next();
0N/A if (e.getKey()==null)
0N/A return true;
0N/A }
0N/A } else {
0N/A while (i.hasNext()) {
0N/A Entry<K,V> e = i.next();
0N/A if (key.equals(e.getKey()))
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A *
0N/A * <p>This implementation iterates over <tt>entrySet()</tt> searching
0N/A * for an entry with the specified key. If such an entry is found,
0N/A * the entry's value is returned. If the iteration terminates without
0N/A * finding such an entry, <tt>null</tt> is returned. Note that this
0N/A * implementation requires linear time in the size of the map; many
0N/A * implementations will override this method.
0N/A *
0N/A * @throws ClassCastException {@inheritDoc}
0N/A * @throws NullPointerException {@inheritDoc}
0N/A */
0N/A public V get(Object key) {
0N/A Iterator<Entry<K,V>> i = entrySet().iterator();
0N/A if (key==null) {
0N/A while (i.hasNext()) {
0N/A Entry<K,V> e = i.next();
0N/A if (e.getKey()==null)
0N/A return e.getValue();
0N/A }
0N/A } else {
0N/A while (i.hasNext()) {
0N/A Entry<K,V> e = i.next();
0N/A if (key.equals(e.getKey()))
0N/A return e.getValue();
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A
0N/A // Modification Operations
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A *
0N/A * <p>This implementation always throws an
0N/A * <tt>UnsupportedOperationException</tt>.
0N/A *
0N/A * @throws UnsupportedOperationException {@inheritDoc}
0N/A * @throws ClassCastException {@inheritDoc}
0N/A * @throws NullPointerException {@inheritDoc}
0N/A * @throws IllegalArgumentException {@inheritDoc}
0N/A */
0N/A public V put(K key, V value) {
0N/A throw new UnsupportedOperationException();
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A *
0N/A * <p>This implementation iterates over <tt>entrySet()</tt> searching for an
0N/A * entry with the specified key. If such an entry is found, its value is
0N/A * obtained with its <tt>getValue</tt> operation, the entry is removed
0N/A * from the collection (and the backing map) with the iterator's
0N/A * <tt>remove</tt> operation, and the saved value is returned. If the
0N/A * iteration terminates without finding such an entry, <tt>null</tt> is
0N/A * returned. Note that this implementation requires linear time in the
0N/A * size of the map; many implementations will override this method.
0N/A *
0N/A * <p>Note that this implementation throws an
0N/A * <tt>UnsupportedOperationException</tt> if the <tt>entrySet</tt>
0N/A * iterator does not support the <tt>remove</tt> method and this map
0N/A * contains a mapping for the specified key.
0N/A *
0N/A * @throws UnsupportedOperationException {@inheritDoc}
0N/A * @throws ClassCastException {@inheritDoc}
0N/A * @throws NullPointerException {@inheritDoc}
0N/A */
0N/A public V remove(Object key) {
0N/A Iterator<Entry<K,V>> i = entrySet().iterator();
0N/A Entry<K,V> correctEntry = null;
0N/A if (key==null) {
0N/A while (correctEntry==null && i.hasNext()) {
0N/A Entry<K,V> e = i.next();
0N/A if (e.getKey()==null)
0N/A correctEntry = e;
0N/A }
0N/A } else {
0N/A while (correctEntry==null && i.hasNext()) {
0N/A Entry<K,V> e = i.next();
0N/A if (key.equals(e.getKey()))
0N/A correctEntry = e;
0N/A }
0N/A }
0N/A
0N/A V oldValue = null;
0N/A if (correctEntry !=null) {
0N/A oldValue = correctEntry.getValue();
0N/A i.remove();
0N/A }
0N/A return oldValue;
0N/A }
0N/A
0N/A
0N/A // Bulk Operations
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A *
0N/A * <p>This implementation iterates over the specified map's
0N/A * <tt>entrySet()</tt> collection, and calls this map's <tt>put</tt>
0N/A * operation once for each entry returned by the iteration.
0N/A *
0N/A * <p>Note that this implementation throws an
0N/A * <tt>UnsupportedOperationException</tt> if this map does not support
0N/A * the <tt>put</tt> operation and the specified map is nonempty.
0N/A *
0N/A * @throws UnsupportedOperationException {@inheritDoc}
0N/A * @throws ClassCastException {@inheritDoc}
0N/A * @throws NullPointerException {@inheritDoc}
0N/A * @throws IllegalArgumentException {@inheritDoc}
0N/A */
0N/A public void putAll(Map<? extends K, ? extends V> m) {
0N/A for (Map.Entry<? extends K, ? extends V> e : m.entrySet())
0N/A put(e.getKey(), e.getValue());
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A *
0N/A * <p>This implementation calls <tt>entrySet().clear()</tt>.
0N/A *
0N/A * <p>Note that this implementation throws an
0N/A * <tt>UnsupportedOperationException</tt> if the <tt>entrySet</tt>
0N/A * does not support the <tt>clear</tt> operation.
0N/A *
0N/A * @throws UnsupportedOperationException {@inheritDoc}
0N/A */
0N/A public void clear() {
0N/A entrySet().clear();
0N/A }
0N/A
0N/A
0N/A // Views
0N/A
0N/A /**
0N/A * Each of these fields are initialized to contain an instance of the
0N/A * appropriate view the first time this view is requested. The views are
0N/A * stateless, so there's no reason to create more than one of each.
0N/A */
0N/A transient volatile Set<K> keySet = null;
0N/A transient volatile Collection<V> values = null;
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A *
0N/A * <p>This implementation returns a set that subclasses {@link AbstractSet}.
0N/A * The subclass's iterator method returns a "wrapper object" over this
0N/A * map's <tt>entrySet()</tt> iterator. The <tt>size</tt> method
0N/A * delegates to this map's <tt>size</tt> method and the
0N/A * <tt>contains</tt> method delegates to this map's
0N/A * <tt>containsKey</tt> method.
0N/A *
0N/A * <p>The set is created the first time this method is called,
0N/A * and returned in response to all subsequent calls. No synchronization
0N/A * is performed, so there is a slight chance that multiple calls to this
0N/A * method will not all return the same set.
0N/A */
0N/A public Set<K> keySet() {
0N/A if (keySet == null) {
0N/A keySet = new AbstractSet<K>() {
0N/A public Iterator<K> iterator() {
0N/A return new Iterator<K>() {
0N/A private Iterator<Entry<K,V>> i = entrySet().iterator();
0N/A
0N/A public boolean hasNext() {
0N/A return i.hasNext();
0N/A }
0N/A
0N/A public K next() {
0N/A return i.next().getKey();
0N/A }
0N/A
0N/A public void remove() {
0N/A i.remove();
0N/A }
0N/A };
0N/A }
0N/A
0N/A public int size() {
0N/A return AbstractMap.this.size();
0N/A }
0N/A
0N/A public boolean isEmpty() {
0N/A return AbstractMap.this.isEmpty();
0N/A }
0N/A
0N/A public void clear() {
0N/A AbstractMap.this.clear();
0N/A }
0N/A
0N/A public boolean contains(Object k) {
0N/A return AbstractMap.this.containsKey(k);
0N/A }
0N/A };
0N/A }
0N/A return keySet;
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A *
0N/A * <p>This implementation returns a collection that subclasses {@link
0N/A * AbstractCollection}. The subclass's iterator method returns a
0N/A * "wrapper object" over this map's <tt>entrySet()</tt> iterator.
0N/A * The <tt>size</tt> method delegates to this map's <tt>size</tt>
0N/A * method and the <tt>contains</tt> method delegates to this map's
0N/A * <tt>containsValue</tt> method.
0N/A *
0N/A * <p>The collection is created the first time this method is called, and
0N/A * returned in response to all subsequent calls. No synchronization is
0N/A * performed, so there is a slight chance that multiple calls to this
0N/A * method will not all return the same collection.
0N/A */
0N/A public Collection<V> values() {
0N/A if (values == null) {
0N/A values = new AbstractCollection<V>() {
0N/A public Iterator<V> iterator() {
0N/A return new Iterator<V>() {
0N/A private Iterator<Entry<K,V>> i = entrySet().iterator();
0N/A
0N/A public boolean hasNext() {
0N/A return i.hasNext();
0N/A }
0N/A
0N/A public V next() {
0N/A return i.next().getValue();
0N/A }
0N/A
0N/A public void remove() {
0N/A i.remove();
0N/A }
0N/A };
0N/A }
0N/A
0N/A public int size() {
0N/A return AbstractMap.this.size();
0N/A }
0N/A
0N/A public boolean isEmpty() {
0N/A return AbstractMap.this.isEmpty();
0N/A }
0N/A
0N/A public void clear() {
0N/A AbstractMap.this.clear();
0N/A }
0N/A
0N/A public boolean contains(Object v) {
0N/A return AbstractMap.this.containsValue(v);
0N/A }
0N/A };
0N/A }
0N/A return values;
0N/A }
0N/A
0N/A public abstract Set<Entry<K,V>> entrySet();
0N/A
0N/A
0N/A // Comparison and hashing
0N/A
0N/A /**
0N/A * Compares the specified object with this map for equality. Returns
0N/A * <tt>true</tt> if the given object is also a map and the two maps
0N/A * represent the same mappings. More formally, two maps <tt>m1</tt> and
0N/A * <tt>m2</tt> represent the same mappings if
0N/A * <tt>m1.entrySet().equals(m2.entrySet())</tt>. This ensures that the
0N/A * <tt>equals</tt> method works properly across different implementations
0N/A * of the <tt>Map</tt> interface.
0N/A *
0N/A * <p>This implementation first checks if the specified object is this map;
0N/A * if so it returns <tt>true</tt>. Then, it checks if the specified
0N/A * object is a map whose size is identical to the size of this map; if
0N/A * not, it returns <tt>false</tt>. If so, it iterates over this map's
0N/A * <tt>entrySet</tt> collection, and checks that the specified map
0N/A * contains each mapping that this map contains. If the specified map
0N/A * fails to contain such a mapping, <tt>false</tt> is returned. If the
0N/A * iteration completes, <tt>true</tt> is returned.
0N/A *
0N/A * @param o object to be compared for equality with this map
0N/A * @return <tt>true</tt> if the specified object is equal to this map
0N/A */
0N/A public boolean equals(Object o) {
0N/A if (o == this)
0N/A return true;
0N/A
0N/A if (!(o instanceof Map))
0N/A return false;
0N/A Map<K,V> m = (Map<K,V>) o;
0N/A if (m.size() != size())
0N/A return false;
0N/A
0N/A try {
0N/A Iterator<Entry<K,V>> i = entrySet().iterator();
0N/A while (i.hasNext()) {
0N/A Entry<K,V> e = i.next();
0N/A K key = e.getKey();
0N/A V value = e.getValue();
0N/A if (value == null) {
0N/A if (!(m.get(key)==null && m.containsKey(key)))
0N/A return false;
0N/A } else {
0N/A if (!value.equals(m.get(key)))
0N/A return false;
0N/A }
0N/A }
0N/A } catch (ClassCastException unused) {
0N/A return false;
0N/A } catch (NullPointerException unused) {
0N/A return false;
0N/A }
0N/A
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Returns the hash code value for this map. The hash code of a map is
0N/A * defined to be the sum of the hash codes of each entry in the map's
0N/A * <tt>entrySet()</tt> view. This ensures that <tt>m1.equals(m2)</tt>
0N/A * implies that <tt>m1.hashCode()==m2.hashCode()</tt> for any two maps
0N/A * <tt>m1</tt> and <tt>m2</tt>, as required by the general contract of
0N/A * {@link Object#hashCode}.
0N/A *
0N/A * <p>This implementation iterates over <tt>entrySet()</tt>, calling
0N/A * {@link Map.Entry#hashCode hashCode()} on each element (entry) in the
0N/A * set, and adding up the results.
0N/A *
0N/A * @return the hash code value for this map
0N/A * @see Map.Entry#hashCode()
0N/A * @see Object#equals(Object)
0N/A * @see Set#equals(Object)
0N/A */
0N/A public int hashCode() {
0N/A int h = 0;
0N/A Iterator<Entry<K,V>> i = entrySet().iterator();
0N/A while (i.hasNext())
0N/A h += i.next().hashCode();
0N/A return h;
0N/A }
0N/A
0N/A /**
0N/A * Returns a string representation of this map. The string representation
0N/A * consists of a list of key-value mappings in the order returned by the
0N/A * map's <tt>entrySet</tt> view's iterator, enclosed in braces
0N/A * (<tt>"{}"</tt>). Adjacent mappings are separated by the characters
0N/A * <tt>", "</tt> (comma and space). Each key-value mapping is rendered as
0N/A * the key followed by an equals sign (<tt>"="</tt>) followed by the
0N/A * associated value. Keys and values are converted to strings as by
0N/A * {@link String#valueOf(Object)}.
0N/A *
0N/A * @return a string representation of this map
0N/A */
0N/A public String toString() {
0N/A Iterator<Entry<K,V>> i = entrySet().iterator();
0N/A if (! i.hasNext())
0N/A return "{}";
0N/A
0N/A StringBuilder sb = new StringBuilder();
0N/A sb.append('{');
0N/A for (;;) {
0N/A Entry<K,V> e = i.next();
0N/A K key = e.getKey();
0N/A V value = e.getValue();
0N/A sb.append(key == this ? "(this Map)" : key);
0N/A sb.append('=');
0N/A sb.append(value == this ? "(this Map)" : value);
0N/A if (! i.hasNext())
0N/A return sb.append('}').toString();
3203N/A sb.append(',').append(' ');
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a shallow copy of this <tt>AbstractMap</tt> instance: the keys
0N/A * and values themselves are not cloned.
0N/A *
0N/A * @return a shallow copy of this map
0N/A */
0N/A protected Object clone() throws CloneNotSupportedException {
0N/A AbstractMap<K,V> result = (AbstractMap<K,V>)super.clone();
0N/A result.keySet = null;
0N/A result.values = null;
0N/A return result;
0N/A }
0N/A
0N/A /**
0N/A * Utility method for SimpleEntry and SimpleImmutableEntry.
0N/A * Test for equality, checking for nulls.
0N/A */
0N/A private static boolean eq(Object o1, Object o2) {
0N/A return o1 == null ? o2 == null : o1.equals(o2);
0N/A }
0N/A
0N/A // Implementation Note: SimpleEntry and SimpleImmutableEntry
0N/A // are distinct unrelated classes, even though they share
0N/A // some code. Since you can't add or subtract final-ness
0N/A // of a field in a subclass, they can't share representations,
0N/A // and the amount of duplicated code is too small to warrant
0N/A // exposing a common abstract class.
0N/A
0N/A
0N/A /**
0N/A * An Entry maintaining a key and a value. The value may be
0N/A * changed using the <tt>setValue</tt> method. This class
0N/A * facilitates the process of building custom map
0N/A * implementations. For example, it may be convenient to return
0N/A * arrays of <tt>SimpleEntry</tt> instances in method
0N/A * <tt>Map.entrySet().toArray</tt>.
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public static class SimpleEntry<K,V>
0N/A implements Entry<K,V>, java.io.Serializable
0N/A {
0N/A private static final long serialVersionUID = -8499721149061103585L;
0N/A
0N/A private final K key;
0N/A private V value;
0N/A
0N/A /**
0N/A * Creates an entry representing a mapping from the specified
0N/A * key to the specified value.
0N/A *
0N/A * @param key the key represented by this entry
0N/A * @param value the value represented by this entry
0N/A */
0N/A public SimpleEntry(K key, V value) {
0N/A this.key = key;
0N/A this.value = value;
0N/A }
0N/A
0N/A /**
0N/A * Creates an entry representing the same mapping as the
0N/A * specified entry.
0N/A *
0N/A * @param entry the entry to copy
0N/A */
0N/A public SimpleEntry(Entry<? extends K, ? extends V> entry) {
0N/A this.key = entry.getKey();
0N/A this.value = entry.getValue();
0N/A }
0N/A
0N/A /**
0N/A * Returns the key corresponding to this entry.
0N/A *
0N/A * @return the key corresponding to this entry
0N/A */
0N/A public K getKey() {
0N/A return key;
0N/A }
0N/A
0N/A /**
0N/A * Returns the value corresponding to this entry.
0N/A *
0N/A * @return the value corresponding to this entry
0N/A */
0N/A public V getValue() {
0N/A return value;
0N/A }
0N/A
0N/A /**
0N/A * Replaces the value corresponding to this entry with the specified
0N/A * value.
0N/A *
0N/A * @param value new value to be stored in this entry
0N/A * @return the old value corresponding to the entry
0N/A */
0N/A public V setValue(V value) {
0N/A V oldValue = this.value;
0N/A this.value = value;
0N/A return oldValue;
0N/A }
0N/A
0N/A /**
0N/A * Compares the specified object with this entry for equality.
0N/A * Returns {@code true} if the given object is also a map entry and
0N/A * the two entries represent the same mapping. More formally, two
0N/A * entries {@code e1} and {@code e2} represent the same mapping
0N/A * if<pre>
0N/A * (e1.getKey()==null ?
0N/A * e2.getKey()==null :
0N/A * e1.getKey().equals(e2.getKey()))
0N/A * &amp;&amp;
0N/A * (e1.getValue()==null ?
0N/A * e2.getValue()==null :
0N/A * e1.getValue().equals(e2.getValue()))</pre>
0N/A * This ensures that the {@code equals} method works properly across
0N/A * different implementations of the {@code Map.Entry} interface.
0N/A *
0N/A * @param o object to be compared for equality with this map entry
0N/A * @return {@code true} if the specified object is equal to this map
0N/A * entry
0N/A * @see #hashCode
0N/A */
0N/A public boolean equals(Object o) {
0N/A if (!(o instanceof Map.Entry))
0N/A return false;
0N/A Map.Entry e = (Map.Entry)o;
0N/A return eq(key, e.getKey()) && eq(value, e.getValue());
0N/A }
0N/A
0N/A /**
0N/A * Returns the hash code value for this map entry. The hash code
0N/A * of a map entry {@code e} is defined to be: <pre>
0N/A * (e.getKey()==null ? 0 : e.getKey().hashCode()) ^
0N/A * (e.getValue()==null ? 0 : e.getValue().hashCode())</pre>
0N/A * This ensures that {@code e1.equals(e2)} implies that
0N/A * {@code e1.hashCode()==e2.hashCode()} for any two Entries
0N/A * {@code e1} and {@code e2}, as required by the general
0N/A * contract of {@link Object#hashCode}.
0N/A *
0N/A * @return the hash code value for this map entry
0N/A * @see #equals
0N/A */
0N/A public int hashCode() {
0N/A return (key == null ? 0 : key.hashCode()) ^
0N/A (value == null ? 0 : value.hashCode());
0N/A }
0N/A
0N/A /**
0N/A * Returns a String representation of this map entry. This
0N/A * implementation returns the string representation of this
0N/A * entry's key followed by the equals character ("<tt>=</tt>")
0N/A * followed by the string representation of this entry's value.
0N/A *
0N/A * @return a String representation of this map entry
0N/A */
0N/A public String toString() {
0N/A return key + "=" + value;
0N/A }
0N/A
0N/A }
0N/A
0N/A /**
0N/A * An Entry maintaining an immutable key and value. This class
0N/A * does not support method <tt>setValue</tt>. This class may be
0N/A * convenient in methods that return thread-safe snapshots of
0N/A * key-value mappings.
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public static class SimpleImmutableEntry<K,V>
0N/A implements Entry<K,V>, java.io.Serializable
0N/A {
0N/A private static final long serialVersionUID = 7138329143949025153L;
0N/A
0N/A private final K key;
0N/A private final V value;
0N/A
0N/A /**
0N/A * Creates an entry representing a mapping from the specified
0N/A * key to the specified value.
0N/A *
0N/A * @param key the key represented by this entry
0N/A * @param value the value represented by this entry
0N/A */
0N/A public SimpleImmutableEntry(K key, V value) {
0N/A this.key = key;
0N/A this.value = value;
0N/A }
0N/A
0N/A /**
0N/A * Creates an entry representing the same mapping as the
0N/A * specified entry.
0N/A *
0N/A * @param entry the entry to copy
0N/A */
0N/A public SimpleImmutableEntry(Entry<? extends K, ? extends V> entry) {
0N/A this.key = entry.getKey();
0N/A this.value = entry.getValue();
0N/A }
0N/A
0N/A /**
0N/A * Returns the key corresponding to this entry.
0N/A *
0N/A * @return the key corresponding to this entry
0N/A */
0N/A public K getKey() {
0N/A return key;
0N/A }
0N/A
0N/A /**
0N/A * Returns the value corresponding to this entry.
0N/A *
0N/A * @return the value corresponding to this entry
0N/A */
0N/A public V getValue() {
0N/A return value;
0N/A }
0N/A
0N/A /**
0N/A * Replaces the value corresponding to this entry with the specified
0N/A * value (optional operation). This implementation simply throws
0N/A * <tt>UnsupportedOperationException</tt>, as this class implements
0N/A * an <i>immutable</i> map entry.
0N/A *
0N/A * @param value new value to be stored in this entry
0N/A * @return (Does not return)
0N/A * @throws UnsupportedOperationException always
0N/A */
0N/A public V setValue(V value) {
0N/A throw new UnsupportedOperationException();
0N/A }
0N/A
0N/A /**
0N/A * Compares the specified object with this entry for equality.
0N/A * Returns {@code true} if the given object is also a map entry and
0N/A * the two entries represent the same mapping. More formally, two
0N/A * entries {@code e1} and {@code e2} represent the same mapping
0N/A * if<pre>
0N/A * (e1.getKey()==null ?
0N/A * e2.getKey()==null :
0N/A * e1.getKey().equals(e2.getKey()))
0N/A * &amp;&amp;
0N/A * (e1.getValue()==null ?
0N/A * e2.getValue()==null :
0N/A * e1.getValue().equals(e2.getValue()))</pre>
0N/A * This ensures that the {@code equals} method works properly across
0N/A * different implementations of the {@code Map.Entry} interface.
0N/A *
0N/A * @param o object to be compared for equality with this map entry
0N/A * @return {@code true} if the specified object is equal to this map
0N/A * entry
0N/A * @see #hashCode
0N/A */
0N/A public boolean equals(Object o) {
0N/A if (!(o instanceof Map.Entry))
0N/A return false;
0N/A Map.Entry e = (Map.Entry)o;
0N/A return eq(key, e.getKey()) && eq(value, e.getValue());
0N/A }
0N/A
0N/A /**
0N/A * Returns the hash code value for this map entry. The hash code
0N/A * of a map entry {@code e} is defined to be: <pre>
0N/A * (e.getKey()==null ? 0 : e.getKey().hashCode()) ^
0N/A * (e.getValue()==null ? 0 : e.getValue().hashCode())</pre>
0N/A * This ensures that {@code e1.equals(e2)} implies that
0N/A * {@code e1.hashCode()==e2.hashCode()} for any two Entries
0N/A * {@code e1} and {@code e2}, as required by the general
0N/A * contract of {@link Object#hashCode}.
0N/A *
0N/A * @return the hash code value for this map entry
0N/A * @see #equals
0N/A */
0N/A public int hashCode() {
0N/A return (key == null ? 0 : key.hashCode()) ^
0N/A (value == null ? 0 : value.hashCode());
0N/A }
0N/A
0N/A /**
0N/A * Returns a String representation of this map entry. This
0N/A * implementation returns the string representation of this
0N/A * entry's key followed by the equals character ("<tt>=</tt>")
0N/A * followed by the string representation of this entry's value.
0N/A *
0N/A * @return a String representation of this map entry
0N/A */
0N/A public String toString() {
0N/A return key + "=" + value;
0N/A }
0N/A
0N/A }
0N/A
0N/A}