27.07/10.33 YES 27.07/10.35 proof of /export/starexec/sandbox2/benchmark/theBenchmark.jar 27.07/10.35 # AProVE Commit ID: 48fb2092695e11cc9f56e44b17a92a5f88ffb256 marcel 20180622 unpublished dirty 27.07/10.35 27.07/10.35 27.07/10.35 termination of the given Bare JBC problem could be proven: 27.07/10.35 27.07/10.35 (0) Bare JBC problem 27.07/10.35 (1) BareJBCToJBCProof [EQUIVALENT, 96 ms] 27.07/10.35 (2) JBC problem 27.07/10.35 (3) JBCToGraph [EQUIVALENT, 3200 ms] 27.07/10.35 (4) JBCTerminationGraph 27.07/10.35 (5) TerminationGraphToSCCProof [SOUND, 0 ms] 27.07/10.35 (6) AND 27.07/10.35 (7) JBCTerminationSCC 27.07/10.35 (8) SCCToIRSProof [SOUND, 251 ms] 27.07/10.35 (9) IRSwT 27.07/10.35 (10) IRSFormatTransformerProof [EQUIVALENT, 0 ms] 27.07/10.35 (11) IRSwT 27.07/10.35 (12) IRSwTTerminationDigraphProof [EQUIVALENT, 32 ms] 27.07/10.35 (13) IRSwT 27.07/10.35 (14) IntTRSCompressionProof [EQUIVALENT, 0 ms] 27.07/10.35 (15) IRSwT 27.07/10.35 (16) TempFilterProof [SOUND, 839 ms] 27.07/10.35 (17) IRSwT 27.07/10.35 (18) IRSwTTerminationDigraphProof [EQUIVALENT, 0 ms] 27.07/10.35 (19) IRSwT 27.07/10.35 (20) IntTRSUnneededArgumentFilterProof [EQUIVALENT, 0 ms] 27.07/10.35 (21) IRSwT 27.07/10.35 (22) TempFilterProof [SOUND, 1 ms] 27.07/10.35 (23) IRSwT 27.07/10.35 (24) IRSwTToQDPProof [SOUND, 0 ms] 27.07/10.35 (25) QDP 27.07/10.35 (26) QDPSizeChangeProof [EQUIVALENT, 0 ms] 27.07/10.35 (27) YES 27.07/10.35 (28) JBCTerminationSCC 27.07/10.35 (29) SCCToIRSProof [SOUND, 195 ms] 27.07/10.35 (30) IRSwT 27.07/10.35 (31) IRSFormatTransformerProof [EQUIVALENT, 0 ms] 27.07/10.35 (32) IRSwT 27.07/10.35 (33) IRSwTTerminationDigraphProof [EQUIVALENT, 45 ms] 27.07/10.35 (34) IRSwT 27.07/10.35 (35) IntTRSCompressionProof [EQUIVALENT, 3 ms] 27.07/10.35 (36) IRSwT 27.07/10.35 (37) TempFilterProof [SOUND, 3 ms] 27.07/10.35 (38) IRSwT 27.07/10.35 (39) IRSwTToQDPProof [SOUND, 0 ms] 27.07/10.35 (40) QDP 27.07/10.35 (41) QDPSizeChangeProof [EQUIVALENT, 0 ms] 27.07/10.35 (42) YES 27.07/10.35 (43) JBCTerminationSCC 27.07/10.35 (44) SCCToIRSProof [SOUND, 192 ms] 27.07/10.35 (45) IRSwT 27.07/10.35 (46) IRSFormatTransformerProof [EQUIVALENT, 0 ms] 27.07/10.35 (47) IRSwT 27.07/10.35 (48) IRSwTTerminationDigraphProof [EQUIVALENT, 43 ms] 27.07/10.35 (49) IRSwT 27.07/10.35 (50) IntTRSCompressionProof [EQUIVALENT, 2 ms] 27.07/10.35 (51) IRSwT 27.07/10.35 (52) TempFilterProof [SOUND, 25 ms] 27.07/10.35 (53) IRSwT 27.07/10.35 (54) IRSwTToQDPProof [SOUND, 0 ms] 27.07/10.35 (55) QDP 27.07/10.35 (56) QDPSizeChangeProof [EQUIVALENT, 0 ms] 27.07/10.35 (57) YES 27.07/10.35 (58) JBCTerminationSCC 27.07/10.35 (59) SCCToIRSProof [SOUND, 731 ms] 27.07/10.35 (60) IRSwT 27.07/10.35 (61) IRSFormatTransformerProof [EQUIVALENT, 0 ms] 27.07/10.35 (62) IRSwT 27.07/10.35 (63) IRSwTTerminationDigraphProof [EQUIVALENT, 36 ms] 27.07/10.35 (64) IRSwT 27.07/10.35 (65) IntTRSCompressionProof [EQUIVALENT, 0 ms] 27.07/10.35 (66) IRSwT 27.07/10.35 (67) TempFilterProof [SOUND, 40 ms] 27.07/10.35 (68) IntTRS 27.07/10.35 (69) PolynomialOrderProcessor [EQUIVALENT, 14 ms] 27.07/10.35 (70) YES 27.07/10.35 27.07/10.35 27.07/10.35 ---------------------------------------- 27.07/10.35 27.07/10.35 (0) 27.07/10.35 Obligation: 27.07/10.35 need to prove termination of the following program: 27.07/10.35 /* 27.07/10.35 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 27.07/10.35 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 27.07/10.35 * 27.07/10.35 * This code is free software; you can redistribute it and/or modify it 27.07/10.35 * under the terms of the GNU General Public License version 2 only, as 27.07/10.35 * published by the Free Software Foundation. Sun designates this 27.07/10.35 * particular file as subject to the "Classpath" exception as provided 27.07/10.35 * by Sun in the LICENSE file that accompanied this code. 27.07/10.35 * 27.07/10.35 * This code is distributed in the hope that it will be useful, but WITHOUT 27.07/10.35 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27.07/10.35 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27.07/10.35 * version 2 for more details (a copy is included in the LICENSE file that 27.07/10.35 * accompanied this code). 27.07/10.35 * 27.07/10.35 * You should have received a copy of the GNU General Public License version 27.07/10.35 * 2 along with this work; if not, write to the Free Software Foundation, 27.07/10.35 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 27.07/10.35 * 27.07/10.35 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 27.07/10.35 * CA 95054 USA or visit www.sun.com if you need additional information or 27.07/10.35 * have any questions. 27.07/10.35 */ 27.07/10.35 27.07/10.35 package javaUtilEx; 27.07/10.35 27.07/10.35 /** 27.07/10.35 * This class provides a skeletal implementation of the Collection 27.07/10.35 * interface, to minimize the effort required to implement this interface.
27.07/10.35 * 27.07/10.35 * To implement an unmodifiable collection, the programmer needs only to 27.07/10.35 * extend this class and provide implementations for the iterator and 27.07/10.35 * size methods. (The iterator returned by the iterator 27.07/10.35 * method must implement hasNext and next.)
27.07/10.35 * 27.07/10.35 * To implement a modifiable collection, the programmer must additionally 27.07/10.35 * override this class's add method (which otherwise throws an 27.07/10.35 * UnsupportedOperationException), and the iterator returned by the 27.07/10.35 * iterator method must additionally implement its remove 27.07/10.35 * method.
27.07/10.35 * 27.07/10.35 * The programmer should generally provide a void (no argument) and 27.07/10.35 * Collection constructor, as per the recommendation in the 27.07/10.35 * Collection interface specification.
27.07/10.35 * 27.07/10.35 * The documentation for each non-abstract method in this class describes its 27.07/10.35 * implementation in detail. Each of these methods may be overridden if 27.07/10.35 * the collection being implemented admits a more efficient implementation.
27.07/10.35 *
27.07/10.35 * This class is a member of the
27.07/10.35 *
27.07/10.35 * Java Collections Framework.
27.07/10.35 *
27.07/10.35 * @author Josh Bloch
27.07/10.35 * @author Neal Gafter
27.07/10.35 * @see Collection
27.07/10.35 * @since 1.2
27.07/10.35 */
27.07/10.35
27.07/10.35 public abstract class AbstractCollection This implementation returns size() == 0.
27.07/10.35 */
27.07/10.35 public boolean isEmpty() {
27.07/10.35 return size() == 0;
27.07/10.35 }
27.07/10.35
27.07/10.35 /**
27.07/10.35 * {@inheritDoc}
27.07/10.35 *
27.07/10.35 * This implementation iterates over the elements in the collection,
27.07/10.35 * checking each element in turn for equality with the specified element.
27.07/10.35 *
27.07/10.35 * @throws ClassCastException {@inheritDoc}
27.07/10.35 * @throws NullPointerException {@inheritDoc}
27.07/10.35 */
27.07/10.35 public boolean contains(Object o) {
27.07/10.35 Iterator This implementation always throws an
27.07/10.35 * UnsupportedOperationException.
27.07/10.35 *
27.07/10.35 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.35 * @throws ClassCastException {@inheritDoc}
27.07/10.35 * @throws NullPointerException {@inheritDoc}
27.07/10.35 * @throws IllegalArgumentException {@inheritDoc}
27.07/10.35 * @throws IllegalStateException {@inheritDoc}
27.07/10.35 */
27.07/10.35 public boolean add(E e) {
27.07/10.35 throw new UnsupportedOperationException();
27.07/10.35 }
27.07/10.35
27.07/10.35 /**
27.07/10.35 * {@inheritDoc}
27.07/10.35 *
27.07/10.35 * This implementation iterates over the collection looking for the
27.07/10.35 * specified element. If it finds the element, it removes the element
27.07/10.35 * from the collection using the iterator's remove method.
27.07/10.35 *
27.07/10.35 * Note that this implementation throws an
27.07/10.35 * UnsupportedOperationException if the iterator returned by this
27.07/10.35 * collection's iterator method does not implement the remove
27.07/10.35 * method and this collection contains the specified object.
27.07/10.35 *
27.07/10.35 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.35 * @throws ClassCastException {@inheritDoc}
27.07/10.35 * @throws NullPointerException {@inheritDoc}
27.07/10.35 */
27.07/10.35 public boolean remove(Object o) {
27.07/10.35 Iterator This implementation iterates over the specified collection,
27.07/10.35 * checking each element returned by the iterator in turn to see
27.07/10.35 * if it's contained in this collection. If all elements are so
27.07/10.35 * contained true is returned, otherwise false.
27.07/10.35 *
27.07/10.35 * @throws ClassCastException {@inheritDoc}
27.07/10.35 * @throws NullPointerException {@inheritDoc}
27.07/10.35 * @see #contains(Object)
27.07/10.35 */
27.07/10.35 public boolean containsAll(Collection> c) {
27.07/10.35 Iterator> e = c.iterator();
27.07/10.35 while (e.hasNext())
27.07/10.35 if (!contains(e.next()))
27.07/10.35 return false;
27.07/10.35 return true;
27.07/10.35 }
27.07/10.35
27.07/10.35 /**
27.07/10.35 * {@inheritDoc}
27.07/10.35 *
27.07/10.35 * This implementation iterates over the specified collection, and adds
27.07/10.35 * each object returned by the iterator to this collection, in turn.
27.07/10.35 *
27.07/10.35 * Note that this implementation will throw an
27.07/10.35 * UnsupportedOperationException unless add is
27.07/10.35 * overridden (assuming the specified collection is non-empty).
27.07/10.35 *
27.07/10.35 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.35 * @throws ClassCastException {@inheritDoc}
27.07/10.35 * @throws NullPointerException {@inheritDoc}
27.07/10.35 * @throws IllegalArgumentException {@inheritDoc}
27.07/10.35 * @throws IllegalStateException {@inheritDoc}
27.07/10.35 *
27.07/10.35 * @see #add(Object)
27.07/10.35 */
27.07/10.35 public boolean addAll(Collection extends E> c) {
27.07/10.35 boolean modified = false;
27.07/10.35 Iterator extends E> e = c.iterator();
27.07/10.35 while (e.hasNext()) {
27.07/10.35 if (add(e.next()))
27.07/10.35 modified = true;
27.07/10.35 }
27.07/10.35 return modified;
27.07/10.35 }
27.07/10.35
27.07/10.35 /**
27.07/10.35 * {@inheritDoc}
27.07/10.35 *
27.07/10.35 * This implementation iterates over this collection, checking each
27.07/10.35 * element returned by the iterator in turn to see if it's contained
27.07/10.35 * in the specified collection. If it's so contained, it's removed from
27.07/10.35 * this collection with the iterator's remove method.
27.07/10.35 *
27.07/10.35 * Note that this implementation will throw an
27.07/10.35 * UnsupportedOperationException if the iterator returned by the
27.07/10.35 * iterator method does not implement the remove method
27.07/10.35 * and this collection contains one or more elements in common with the
27.07/10.35 * specified collection.
27.07/10.35 *
27.07/10.35 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.35 * @throws ClassCastException {@inheritDoc}
27.07/10.35 * @throws NullPointerException {@inheritDoc}
27.07/10.35 *
27.07/10.35 * @see #remove(Object)
27.07/10.35 * @see #contains(Object)
27.07/10.35 */
27.07/10.35 public boolean removeAll(Collection> c) {
27.07/10.35 boolean modified = false;
27.07/10.35 Iterator> e = iterator();
27.07/10.35 while (e.hasNext()) {
27.07/10.35 if (c.contains(e.next())) {
27.07/10.35 e.remove();
27.07/10.35 modified = true;
27.07/10.35 }
27.07/10.35 }
27.07/10.35 return modified;
27.07/10.35 }
27.07/10.35
27.07/10.35 /**
27.07/10.35 * {@inheritDoc}
27.07/10.35 *
27.07/10.35 * This implementation iterates over this collection, checking each
27.07/10.35 * element returned by the iterator in turn to see if it's contained
27.07/10.35 * in the specified collection. If it's not so contained, it's removed
27.07/10.35 * from this collection with the iterator's remove method.
27.07/10.35 *
27.07/10.35 * Note that this implementation will throw an
27.07/10.35 * UnsupportedOperationException if the iterator returned by the
27.07/10.35 * iterator method does not implement the remove method
27.07/10.35 * and this collection contains one or more elements not present in the
27.07/10.35 * specified collection.
27.07/10.35 *
27.07/10.35 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.35 * @throws ClassCastException {@inheritDoc}
27.07/10.35 * @throws NullPointerException {@inheritDoc}
27.07/10.35 *
27.07/10.35 * @see #remove(Object)
27.07/10.35 * @see #contains(Object)
27.07/10.35 */
27.07/10.35 public boolean retainAll(Collection> c) {
27.07/10.35 boolean modified = false;
27.07/10.35 Iterator This implementation iterates over this collection, removing each
27.07/10.35 * element using the Iterator.remove operation. Most
27.07/10.35 * implementations will probably choose to override this method for
27.07/10.35 * efficiency.
27.07/10.35 *
27.07/10.35 * Note that this implementation will throw an
27.07/10.35 * UnsupportedOperationException if the iterator returned by this
27.07/10.35 * collection's iterator method does not implement the
27.07/10.35 * remove method and this collection is non-empty.
27.07/10.35 *
27.07/10.35 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.35 */
27.07/10.35 public void clear() {
27.07/10.35 Iterator To implement an unmodifiable map, the programmer needs only to extend this
27.07/10.35 * class and provide an implementation for the entrySet method, which
27.07/10.35 * returns a set-view of the map's mappings. Typically, the returned set
27.07/10.35 * will, in turn, be implemented atop AbstractSet. This set should
27.07/10.35 * not support the add or remove methods, and its iterator
27.07/10.35 * should not support the remove method.
27.07/10.35 *
27.07/10.35 * To implement a modifiable map, the programmer must additionally override
27.07/10.35 * this class's put method (which otherwise throws an
27.07/10.35 * UnsupportedOperationException), and the iterator returned by
27.07/10.35 * entrySet().iterator() must additionally implement its
27.07/10.35 * remove method.
27.07/10.35 *
27.07/10.35 * The programmer should generally provide a void (no argument) and map
27.07/10.35 * constructor, as per the recommendation in the Map interface
27.07/10.35 * specification.
27.07/10.35 *
27.07/10.35 * The documentation for each non-abstract method in this class describes its
27.07/10.35 * implementation in detail. Each of these methods may be overridden if the
27.07/10.35 * map being implemented admits a more efficient implementation.
27.07/10.35 *
27.07/10.35 * This class is a member of the
27.07/10.35 *
27.07/10.35 * Java Collections Framework.
27.07/10.35 *
27.07/10.35 * @param This implementation returns entrySet().size().
27.07/10.35 */
27.07/10.35 public int size() {
27.07/10.35 return entrySet().size();
27.07/10.35 }
27.07/10.35
27.07/10.35 /**
27.07/10.35 * {@inheritDoc}
27.07/10.35 *
27.07/10.35 * This implementation returns size() == 0.
27.07/10.35 */
27.07/10.35 public boolean isEmpty() {
27.07/10.35 return size() == 0;
27.07/10.35 }
27.07/10.35
27.07/10.35 /**
27.07/10.35 * {@inheritDoc}
27.07/10.35 *
27.07/10.35 * This implementation iterates over entrySet() searching
27.07/10.35 * for an entry with the specified value. If such an entry is found,
27.07/10.35 * true is returned. If the iteration terminates without
27.07/10.35 * finding such an entry, false is returned. Note that this
27.07/10.35 * implementation requires linear time in the size of the map.
27.07/10.35 *
27.07/10.35 * @throws ClassCastException {@inheritDoc}
27.07/10.35 * @throws NullPointerException {@inheritDoc}
27.07/10.35 */
27.07/10.35 public boolean containsValue(Object value) {
27.07/10.35 Iterator This implementation iterates over entrySet() searching
27.07/10.35 * for an entry with the specified key. If such an entry is found,
27.07/10.35 * true is returned. If the iteration terminates without
27.07/10.35 * finding such an entry, false is returned. Note that this
27.07/10.35 * implementation requires linear time in the size of the map; many
27.07/10.35 * implementations will override this method.
27.07/10.35 *
27.07/10.35 * @throws ClassCastException {@inheritDoc}
27.07/10.35 * @throws NullPointerException {@inheritDoc}
27.07/10.35 */
27.07/10.35 public boolean containsKey(Object key) {
27.07/10.35 Iterator This implementation iterates over entrySet() searching
27.07/10.35 * for an entry with the specified key. If such an entry is found,
27.07/10.35 * the entry's value is returned. If the iteration terminates without
27.07/10.35 * finding such an entry, null is returned. Note that this
27.07/10.35 * implementation requires linear time in the size of the map; many
27.07/10.35 * implementations will override this method.
27.07/10.35 *
27.07/10.35 * @throws ClassCastException {@inheritDoc}
27.07/10.35 * @throws NullPointerException {@inheritDoc}
27.07/10.35 */
27.07/10.35 public V get(Object key) {
27.07/10.35 Iterator This implementation always throws an
27.07/10.35 * UnsupportedOperationException.
27.07/10.35 *
27.07/10.35 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.35 * @throws ClassCastException {@inheritDoc}
27.07/10.35 * @throws NullPointerException {@inheritDoc}
27.07/10.35 * @throws IllegalArgumentException {@inheritDoc}
27.07/10.35 */
27.07/10.35 public V put(K key, V value) {
27.07/10.35 throw new UnsupportedOperationException();
27.07/10.35 }
27.07/10.35
27.07/10.35 /**
27.07/10.35 * {@inheritDoc}
27.07/10.35 *
27.07/10.35 * This implementation iterates over entrySet() searching for an
27.07/10.35 * entry with the specified key. If such an entry is found, its value is
27.07/10.35 * obtained with its getValue operation, the entry is removed
27.07/10.35 * from the collection (and the backing map) with the iterator's
27.07/10.35 * remove operation, and the saved value is returned. If the
27.07/10.35 * iteration terminates without finding such an entry, null is
27.07/10.35 * returned. Note that this implementation requires linear time in the
27.07/10.35 * size of the map; many implementations will override this method.
27.07/10.35 *
27.07/10.35 * Note that this implementation throws an
27.07/10.35 * UnsupportedOperationException if the entrySet
27.07/10.35 * iterator does not support the remove method and this map
27.07/10.35 * contains a mapping for the specified key.
27.07/10.35 *
27.07/10.35 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.35 * @throws ClassCastException {@inheritDoc}
27.07/10.35 * @throws NullPointerException {@inheritDoc}
27.07/10.35 */
27.07/10.35 public V remove(Object key) {
27.07/10.35 Iterator This implementation iterates over the specified map's
27.07/10.35 * entrySet() collection, and calls this map's put
27.07/10.35 * operation once for each entry returned by the iteration.
27.07/10.35 *
27.07/10.35 * Note that this implementation throws an
27.07/10.35 * UnsupportedOperationException if this map does not support
27.07/10.35 * the put operation and the specified map is nonempty.
27.07/10.35 *
27.07/10.35 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.35 * @throws ClassCastException {@inheritDoc}
27.07/10.35 * @throws NullPointerException {@inheritDoc}
27.07/10.35 * @throws IllegalArgumentException {@inheritDoc}
27.07/10.35 */
27.07/10.35 public void putAll(Map extends K, ? extends V> m) {
27.07/10.35 Iterator it = m.entrySet().iterator();
27.07/10.35 while (it.hasNext()) {
27.07/10.35 Map.Entry e = (Map.Entry) it.next();
27.07/10.35 put((K) e.getKey(), (V) e.getValue());
27.07/10.35 }
27.07/10.35 }
27.07/10.35
27.07/10.35 /**
27.07/10.35 * {@inheritDoc}
27.07/10.35 *
27.07/10.35 * This implementation calls entrySet().clear().
27.07/10.35 *
27.07/10.35 * Note that this implementation throws an
27.07/10.35 * UnsupportedOperationException if the entrySet
27.07/10.35 * does not support the clear operation.
27.07/10.35 *
27.07/10.35 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.35 */
27.07/10.35 public void clear() {
27.07/10.35 entrySet().clear();
27.07/10.35 }
27.07/10.35
27.07/10.35
27.07/10.35 // Views
27.07/10.35
27.07/10.35 /**
27.07/10.35 * Each of these fields are initialized to contain an instance of the
27.07/10.35 * appropriate view the first time this view is requested. The views are
27.07/10.35 * stateless, so there's no reason to create more than one of each.
27.07/10.35 */
27.07/10.35 transient volatile Set This implementation returns a set that subclasses {@link AbstractSet}.
27.07/10.35 * The subclass's iterator method returns a "wrapper object" over this
27.07/10.35 * map's entrySet() iterator. The size method
27.07/10.35 * delegates to this map's size method and the
27.07/10.35 * contains method delegates to this map's
27.07/10.35 * containsKey method.
27.07/10.35 *
27.07/10.35 * The set is created the first time this method is called,
27.07/10.35 * and returned in response to all subsequent calls. No synchronization
27.07/10.35 * is performed, so there is a slight chance that multiple calls to this
27.07/10.35 * method will not all return the same set.
27.07/10.35 */
27.07/10.35 public Set This implementation returns a collection that subclasses {@link
27.07/10.35 * AbstractCollection}. The subclass's iterator method returns a
27.07/10.35 * "wrapper object" over this map's entrySet() iterator.
27.07/10.35 * The size method delegates to this map's size
27.07/10.35 * method and the contains method delegates to this map's
27.07/10.35 * containsValue method.
27.07/10.35 *
27.07/10.35 * The collection is created the first time this method is called, and
27.07/10.35 * returned in response to all subsequent calls. No synchronization is
27.07/10.35 * performed, so there is a slight chance that multiple calls to this
27.07/10.35 * method will not all return the same collection.
27.07/10.35 */
27.07/10.35 public Collection This implementation first checks if the specified object is this map;
27.07/10.35 * if so it returns true. Then, it checks if the specified
27.07/10.35 * object is a map whose size is identical to the size of this map; if
27.07/10.35 * not, it returns false. If so, it iterates over this map's
27.07/10.35 * entrySet collection, and checks that the specified map
27.07/10.35 * contains each mapping that this map contains. If the specified map
27.07/10.35 * fails to contain such a mapping, false is returned. If the
27.07/10.35 * iteration completes, true is returned.
27.07/10.35 *
27.07/10.35 * @param o object to be compared for equality with this map
27.07/10.35 * @return true if the specified object is equal to this map
27.07/10.35 */
27.07/10.35 public boolean equals(Object o) {
27.07/10.35 if (o == this)
27.07/10.35 return true;
27.07/10.35
27.07/10.35 if (!(o instanceof Map))
27.07/10.35 return false;
27.07/10.35 Map This implementation iterates over entrySet(), calling
27.07/10.35 * {@link Map.Entry#hashCode hashCode()} on each element (entry) in the
27.07/10.35 * set, and adding up the results.
27.07/10.35 *
27.07/10.35 * @return the hash code value for this map
27.07/10.35 * @see Map.Entry#hashCode()
27.07/10.35 * @see Object#equals(Object)
27.07/10.35 * @see Set#equals(Object)
27.07/10.35 */
27.07/10.35 public int hashCode() {
27.07/10.35 int h = 0;
27.07/10.35 Iterator
27.07/10.36 *
27.07/10.36 * The process of implementing a set by extending this class is identical
27.07/10.36 * to that of implementing a Collection by extending AbstractCollection,
27.07/10.36 * except that all of the methods and constructors in subclasses of this
27.07/10.36 * class must obey the additional constraints imposed by the Set
27.07/10.36 * interface (for instance, the add method must not permit addition of
27.07/10.36 * multiple instances of an object to a set).
27.07/10.36 *
27.07/10.36 * Note that this class does not override any of the implementations from
27.07/10.36 * the AbstractCollection class. It merely adds implementations
27.07/10.36 * for equals and hashCode.
27.07/10.36 *
27.07/10.36 * This class is a member of the
27.07/10.36 *
27.07/10.36 * Java Collections Framework.
27.07/10.36 *
27.07/10.36 * @param
27.07/10.36 *
27.07/10.36 * This implementation first checks if the specified object is this
27.07/10.36 * set; if so it returns true. Then, it checks if the
27.07/10.36 * specified object is a set whose size is identical to the size of
27.07/10.36 * this set; if not, it returns false. If so, it returns
27.07/10.36 * containsAll((Collection) o).
27.07/10.36 *
27.07/10.36 * @param o object to be compared for equality with this set
27.07/10.36 * @return true if the specified object is equal to this set
27.07/10.36 */
27.07/10.36 public boolean equals(Object o) {
27.07/10.36 if (o == this)
27.07/10.36 return true;
27.07/10.36
27.07/10.36 if (!(o instanceof Set))
27.07/10.36 return false;
27.07/10.36 Collection c = (Collection) o;
27.07/10.36 if (c.size() != size())
27.07/10.36 return false;
27.07/10.36 try {
27.07/10.36 return containsAll(c);
27.07/10.36 } catch (ClassCastException unused) {
27.07/10.36 return false;
27.07/10.36 } catch (NullPointerException unused) {
27.07/10.36 return false;
27.07/10.36 }
27.07/10.36 }
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Returns the hash code value for this set. The hash code of a set is
27.07/10.36 * defined to be the sum of the hash codes of the elements in the set,
27.07/10.36 * where the hash code of a null element is defined to be zero.
27.07/10.36 * This ensures that s1.equals(s2) implies that
27.07/10.36 * s1.hashCode()==s2.hashCode() for any two sets s1
27.07/10.36 * and s2, as required by the general contract of
27.07/10.36 * {@link Object#hashCode}.
27.07/10.36 *
27.07/10.36 * This implementation iterates over the set, calling the
27.07/10.36 * hashCode method on each element in the set, and adding up
27.07/10.36 * the results.
27.07/10.36 *
27.07/10.36 * @return the hash code value for this set
27.07/10.36 * @see Object#equals(Object)
27.07/10.36 * @see Set#equals(Object)
27.07/10.36 */
27.07/10.36 public int hashCode() {
27.07/10.36 int h = 0;
27.07/10.36 Iterator This implementation determines which is the smaller of this set
27.07/10.36 * and the specified collection, by invoking the size
27.07/10.36 * method on each. If this set has fewer elements, then the
27.07/10.36 * implementation iterates over this set, checking each element
27.07/10.36 * returned by the iterator in turn to see if it is contained in
27.07/10.36 * the specified collection. If it is so contained, it is removed
27.07/10.36 * from this set with the iterator's remove method. If
27.07/10.36 * the specified collection has fewer elements, then the
27.07/10.36 * implementation iterates over the specified collection, removing
27.07/10.36 * from this set each element returned by the iterator, using this
27.07/10.36 * set's remove method.
27.07/10.36 *
27.07/10.36 * Note that this implementation will throw an
27.07/10.36 * UnsupportedOperationException if the iterator returned by the
27.07/10.36 * iterator method does not implement the remove method.
27.07/10.36 *
27.07/10.36 * @param c collection containing elements to be removed from this set
27.07/10.36 * @return true if this set changed as a result of the call
27.07/10.36 * @throws UnsupportedOperationException if the removeAll operation
27.07/10.36 * is not supported by this set
27.07/10.36 * @throws ClassCastException if the class of an element of this set
27.07/10.36 * is incompatible with the specified collection (optional)
27.07/10.36 * @throws NullPointerException if this set contains a null element and the
27.07/10.36 * specified collection does not permit null elements (optional),
27.07/10.36 * or if the specified collection is null
27.07/10.36 * @see #remove(Object)
27.07/10.36 * @see #contains(Object)
27.07/10.36 */
27.07/10.36 public boolean removeAll(Collection> c) {
27.07/10.36 boolean modified = false;
27.07/10.36
27.07/10.36 if (size() > c.size()) {
27.07/10.36 for (Iterator> i = c.iterator(); i.hasNext(); )
27.07/10.36 modified |= remove(i.next());
27.07/10.36 } else {
27.07/10.36 for (Iterator> i = iterator(); i.hasNext(); ) {
27.07/10.36 if (c.contains(i.next())) {
27.07/10.36 i.remove();
27.07/10.36 modified = true;
27.07/10.36 }
27.07/10.36 }
27.07/10.36 }
27.07/10.36 return modified;
27.07/10.36 }
27.07/10.36
27.07/10.36 }
27.07/10.36
27.07/10.36
27.07/10.36 /*
27.07/10.36 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
27.07/10.36 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.07/10.36 *
27.07/10.36 * This code is free software; you can redistribute it and/or modify it
27.07/10.36 * under the terms of the GNU General Public License version 2 only, as
27.07/10.36 * published by the Free Software Foundation. Sun designates this
27.07/10.36 * particular file as subject to the "Classpath" exception as provided
27.07/10.36 * by Sun in the LICENSE file that accompanied this code.
27.07/10.36 *
27.07/10.36 * This code is distributed in the hope that it will be useful, but WITHOUT
27.07/10.36 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.07/10.36 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.07/10.36 * version 2 for more details (a copy is included in the LICENSE file that
27.07/10.36 * accompanied this code).
27.07/10.36 *
27.07/10.36 * You should have received a copy of the GNU General Public License version
27.07/10.36 * 2 along with this work; if not, write to the Free Software Foundation,
27.07/10.36 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.07/10.36 *
27.07/10.36 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27.07/10.36 * CA 95054 USA or visit www.sun.com if you need additional information or
27.07/10.36 * have any questions.
27.07/10.36 */
27.07/10.36
27.07/10.36 package javaUtilEx;
27.07/10.36
27.07/10.36 /**
27.07/10.36 * The root interface in the collection hierarchy. A collection
27.07/10.36 * represents a group of objects, known as its elements. Some
27.07/10.36 * collections allow duplicate elements and others do not. Some are ordered
27.07/10.36 * and others unordered. The JDK does not provide any direct
27.07/10.36 * implementations of this interface: it provides implementations of more
27.07/10.36 * specific subinterfaces like Set and List. This interface
27.07/10.36 * is typically used to pass collections around and manipulate them where
27.07/10.36 * maximum generality is desired.
27.07/10.36 *
27.07/10.36 * Bags or multisets (unordered collections that may contain
27.07/10.36 * duplicate elements) should implement this interface directly.
27.07/10.36 *
27.07/10.36 * All general-purpose Collection implementation classes (which
27.07/10.36 * typically implement Collection indirectly through one of its
27.07/10.36 * subinterfaces) should provide two "standard" constructors: a void (no
27.07/10.36 * arguments) constructor, which creates an empty collection, and a
27.07/10.36 * constructor with a single argument of type Collection, which
27.07/10.36 * creates a new collection with the same elements as its argument. In
27.07/10.36 * effect, the latter constructor allows the user to copy any collection,
27.07/10.36 * producing an equivalent collection of the desired implementation type.
27.07/10.36 * There is no way to enforce this convention (as interfaces cannot contain
27.07/10.36 * constructors) but all of the general-purpose Collection
27.07/10.36 * implementations in the Java platform libraries comply.
27.07/10.36 *
27.07/10.36 * The "destructive" methods contained in this interface, that is, the
27.07/10.36 * methods that modify the collection on which they operate, are specified to
27.07/10.36 * throw UnsupportedOperationException if this collection does not
27.07/10.36 * support the operation. If this is the case, these methods may, but are not
27.07/10.36 * required to, throw an UnsupportedOperationException if the
27.07/10.36 * invocation would have no effect on the collection. For example, invoking
27.07/10.36 * the {@link #addAll(Collection)} method on an unmodifiable collection may,
27.07/10.36 * but is not required to, throw the exception if the collection to be added
27.07/10.36 * is empty.
27.07/10.36 *
27.07/10.36 * Some collection implementations have restrictions on the elements that
27.07/10.36 * they may contain. For example, some implementations prohibit null elements,
27.07/10.36 * and some have restrictions on the types of their elements. Attempting to
27.07/10.36 * add an ineligible element throws an unchecked exception, typically
27.07/10.36 * NullPointerException or ClassCastException. Attempting
27.07/10.36 * to query the presence of an ineligible element may throw an exception,
27.07/10.36 * or it may simply return false; some implementations will exhibit the former
27.07/10.36 * behavior and some will exhibit the latter. More generally, attempting an
27.07/10.36 * operation on an ineligible element whose completion would not result in
27.07/10.36 * the insertion of an ineligible element into the collection may throw an
27.07/10.36 * exception or it may succeed, at the option of the implementation.
27.07/10.36 * Such exceptions are marked as "optional" in the specification for this
27.07/10.36 * interface.
27.07/10.36 *
27.07/10.36 * It is up to each collection to determine its own synchronization
27.07/10.36 * policy. In the absence of a stronger guarantee by the
27.07/10.36 * implementation, undefined behavior may result from the invocation
27.07/10.36 * of any method on a collection that is being mutated by another
27.07/10.36 * thread; this includes direct invocations, passing the collection to
27.07/10.36 * a method that might perform invocations, and using an existing
27.07/10.36 * iterator to examine the collection.
27.07/10.36 *
27.07/10.36 * Many methods in Collections Framework interfaces are defined in
27.07/10.36 * terms of the {@link Object#equals(Object) equals} method. For example,
27.07/10.36 * the specification for the {@link #contains(Object) contains(Object o)}
27.07/10.36 * method says: "returns true if and only if this collection
27.07/10.36 * contains at least one element e such that
27.07/10.36 * (o==null ? e==null : o.equals(e))." This specification should
27.07/10.36 * not be construed to imply that invoking Collection.contains
27.07/10.36 * with a non-null argument o will cause o.equals(e) to be
27.07/10.36 * invoked for any element e. Implementations are free to implement
27.07/10.36 * optimizations whereby the equals invocation is avoided, for
27.07/10.36 * example, by first comparing the hash codes of the two elements. (The
27.07/10.36 * {@link Object#hashCode()} specification guarantees that two objects with
27.07/10.36 * unequal hash codes cannot be equal.) More generally, implementations of
27.07/10.36 * the various Collections Framework interfaces are free to take advantage of
27.07/10.36 * the specified behavior of underlying {@link Object} methods wherever the
27.07/10.36 * implementor deems it appropriate.
27.07/10.36 *
27.07/10.36 * This interface is a member of the
27.07/10.36 *
27.07/10.36 * Java Collections Framework.
27.07/10.36 *
27.07/10.36 * @author Josh Bloch
27.07/10.36 * @author Neal Gafter
27.07/10.36 * @see Set
27.07/10.36 * @see List
27.07/10.36 * @see Map
27.07/10.36 * @see SortedSet
27.07/10.36 * @see SortedMap
27.07/10.36 * @see HashSet
27.07/10.36 * @see TreeSet
27.07/10.36 * @see ArrayList
27.07/10.36 * @see LinkedList
27.07/10.36 * @see Vector
27.07/10.36 * @see Collections
27.07/10.36 * @see Arrays
27.07/10.36 * @see AbstractCollection
27.07/10.36 * @since 1.2
27.07/10.36 */
27.07/10.36
27.07/10.36 public interface Collection
27.07/10.36 *
27.07/10.36 * Collections that support this operation may place limitations on what
27.07/10.36 * elements may be added to this collection. In particular, some
27.07/10.36 * collections will refuse to add null elements, and others will
27.07/10.36 * impose restrictions on the type of elements that may be added.
27.07/10.36 * Collection classes should clearly specify in their documentation any
27.07/10.36 * restrictions on what elements may be added.
27.07/10.36 *
27.07/10.36 * If a collection refuses to add a particular element for any reason
27.07/10.36 * other than that it already contains the element, it must throw
27.07/10.36 * an exception (rather than returning false). This preserves
27.07/10.36 * the invariant that a collection always contains the specified element
27.07/10.36 * after this call returns.
27.07/10.36 *
27.07/10.36 * @param e element whose presence in this collection is to be ensured
27.07/10.36 * @return true if this collection changed as a result of the
27.07/10.36 * call
27.07/10.36 * @throws UnsupportedOperationException if the add operation
27.07/10.36 * is not supported by this collection
27.07/10.36 * @throws ClassCastException if the class of the specified element
27.07/10.36 * prevents it from being added to this collection
27.07/10.36 * @throws NullPointerException if the specified element is null and this
27.07/10.36 * collection does not permit null elements
27.07/10.36 * @throws IllegalArgumentException if some property of the element
27.07/10.36 * prevents it from being added to this collection
27.07/10.36 * @throws IllegalStateException if the element cannot be added at this
27.07/10.36 * time due to insertion restrictions
27.07/10.36 */
27.07/10.36 boolean add(E e);
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Removes a single instance of the specified element from this
27.07/10.36 * collection, if it is present (optional operation). More formally,
27.07/10.36 * removes an element e such that
27.07/10.36 * (o==null ? e==null : o.equals(e)), if
27.07/10.36 * this collection contains one or more such elements. Returns
27.07/10.36 * true if this collection contained the specified element (or
27.07/10.36 * equivalently, if this collection changed as a result of the call).
27.07/10.36 *
27.07/10.36 * @param o element to be removed from this collection, if present
27.07/10.36 * @return true if an element was removed as a result of this call
27.07/10.36 * @throws ClassCastException if the type of the specified element
27.07/10.36 * is incompatible with this collection (optional)
27.07/10.36 * @throws NullPointerException if the specified element is null and this
27.07/10.36 * collection does not permit null elements (optional)
27.07/10.36 * @throws UnsupportedOperationException if the remove operation
27.07/10.36 * is not supported by this collection
27.07/10.36 */
27.07/10.36 boolean remove(Object o);
27.07/10.36
27.07/10.36
27.07/10.36 // Bulk Operations
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Returns true if this collection contains all of the elements
27.07/10.36 * in the specified collection.
27.07/10.36 *
27.07/10.36 * @param c collection to be checked for containment in this collection
27.07/10.36 * @return true if this collection contains all of the elements
27.07/10.36 * in the specified collection
27.07/10.36 * @throws ClassCastException if the types of one or more elements
27.07/10.36 * in the specified collection are incompatible with this
27.07/10.36 * collection (optional)
27.07/10.36 * @throws NullPointerException if the specified collection contains one
27.07/10.36 * or more null elements and this collection does not permit null
27.07/10.36 * elements (optional), or if the specified collection is null
27.07/10.36 * @see #contains(Object)
27.07/10.36 */
27.07/10.36 boolean containsAll(Collection> c);
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Adds all of the elements in the specified collection to this collection
27.07/10.36 * (optional operation). The behavior of this operation is undefined if
27.07/10.36 * the specified collection is modified while the operation is in progress.
27.07/10.36 * (This implies that the behavior of this call is undefined if the
27.07/10.36 * specified collection is this collection, and this collection is
27.07/10.36 * nonempty.)
27.07/10.36 *
27.07/10.36 * @param c collection containing elements to be added to this collection
27.07/10.36 * @return true if this collection changed as a result of the call
27.07/10.36 * @throws UnsupportedOperationException if the addAll operation
27.07/10.36 * is not supported by this collection
27.07/10.36 * @throws ClassCastException if the class of an element of the specified
27.07/10.36 * collection prevents it from being added to this collection
27.07/10.36 * @throws NullPointerException if the specified collection contains a
27.07/10.36 * null element and this collection does not permit null elements,
27.07/10.36 * or if the specified collection is null
27.07/10.36 * @throws IllegalArgumentException if some property of an element of the
27.07/10.36 * specified collection prevents it from being added to this
27.07/10.36 * collection
27.07/10.36 * @throws IllegalStateException if not all the elements can be added at
27.07/10.36 * this time due to insertion restrictions
27.07/10.36 * @see #add(Object)
27.07/10.36 */
27.07/10.36 boolean addAll(Collection extends E> c);
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Removes all of this collection's elements that are also contained in the
27.07/10.36 * specified collection (optional operation). After this call returns,
27.07/10.36 * this collection will contain no elements in common with the specified
27.07/10.36 * collection.
27.07/10.36 *
27.07/10.36 * @param c collection containing elements to be removed from this collection
27.07/10.36 * @return true if this collection changed as a result of the
27.07/10.36 * call
27.07/10.36 * @throws UnsupportedOperationException if the removeAll method
27.07/10.36 * is not supported by this collection
27.07/10.36 * @throws ClassCastException if the types of one or more elements
27.07/10.36 * in this collection are incompatible with the specified
27.07/10.36 * collection (optional)
27.07/10.36 * @throws NullPointerException if this collection contains one or more
27.07/10.36 * null elements and the specified collection does not support
27.07/10.36 * null elements (optional), or if the specified collection is null
27.07/10.36 * @see #remove(Object)
27.07/10.36 * @see #contains(Object)
27.07/10.36 */
27.07/10.36 boolean removeAll(Collection> c);
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Retains only the elements in this collection that are contained in the
27.07/10.36 * specified collection (optional operation). In other words, removes from
27.07/10.36 * this collection all of its elements that are not contained in the
27.07/10.36 * specified collection.
27.07/10.36 *
27.07/10.36 * @param c collection containing elements to be retained in this collection
27.07/10.36 * @return true if this collection changed as a result of the call
27.07/10.36 * @throws UnsupportedOperationException if the retainAll operation
27.07/10.36 * is not supported by this collection
27.07/10.36 * @throws ClassCastException if the types of one or more elements
27.07/10.36 * in this collection are incompatible with the specified
27.07/10.36 * collection (optional)
27.07/10.36 * @throws NullPointerException if this collection contains one or more
27.07/10.36 * null elements and the specified collection does not permit null
27.07/10.36 * elements (optional), or if the specified collection is null
27.07/10.36 * @see #remove(Object)
27.07/10.36 * @see #contains(Object)
27.07/10.36 */
27.07/10.36 boolean retainAll(Collection> c);
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Removes all of the elements from this collection (optional operation).
27.07/10.36 * The collection will be empty after this method returns.
27.07/10.36 *
27.07/10.36 * @throws UnsupportedOperationException if the clear operation
27.07/10.36 * is not supported by this collection
27.07/10.36 */
27.07/10.36 void clear();
27.07/10.36
27.07/10.36
27.07/10.36 // Comparison and hashing
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Compares the specified object with this collection for equality.
27.07/10.36 *
27.07/10.36 * While the Collection interface adds no stipulations to the
27.07/10.36 * general contract for the Object.equals, programmers who
27.07/10.36 * implement the Collection interface "directly" (in other words,
27.07/10.36 * create a class that is a Collection but is not a Set
27.07/10.36 * or a List) must exercise care if they choose to override the
27.07/10.36 * Object.equals. It is not necessary to do so, and the simplest
27.07/10.36 * course of action is to rely on Object's implementation, but
27.07/10.36 * the implementor may wish to implement a "value comparison" in place of
27.07/10.36 * the default "reference comparison." (The List and
27.07/10.36 * Set interfaces mandate such value comparisons.)
27.07/10.36 *
27.07/10.36 * The general contract for the Object.equals method states that
27.07/10.36 * equals must be symmetric (in other words, a.equals(b) if and
27.07/10.36 * only if b.equals(a)). The contracts for List.equals
27.07/10.36 * and Set.equals state that lists are only equal to other lists,
27.07/10.36 * and sets to other sets. Thus, a custom equals method for a
27.07/10.36 * collection class that implements neither the List nor
27.07/10.36 * Set interface must return false when this collection
27.07/10.36 * is compared to any list or set. (By the same logic, it is not possible
27.07/10.36 * to write a class that correctly implements both the Set and
27.07/10.36 * List interfaces.)
27.07/10.36 *
27.07/10.36 * @param o object to be compared for equality with this collection
27.07/10.36 * @return true if the specified object is equal to this
27.07/10.36 * collection
27.07/10.36 *
27.07/10.36 * @see Object#equals(Object)
27.07/10.36 * @see Set#equals(Object)
27.07/10.36 * @see List#equals(Object)
27.07/10.36 */
27.07/10.36 boolean equals(Object o);
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Returns the hash code value for this collection. While the
27.07/10.36 * Collection interface adds no stipulations to the general
27.07/10.36 * contract for the Object.hashCode method, programmers should
27.07/10.36 * take note that any class that overrides the Object.equals
27.07/10.36 * method must also override the Object.hashCode method in order
27.07/10.36 * to satisfy the general contract for the Object.hashCodemethod.
27.07/10.36 * In particular, c1.equals(c2) implies that
27.07/10.36 * c1.hashCode()==c2.hashCode().
27.07/10.36 *
27.07/10.36 * @return the hash code value for this collection
27.07/10.36 *
27.07/10.36 * @see Object#hashCode()
27.07/10.36 * @see Object#equals(Object)
27.07/10.36 */
27.07/10.36 int hashCode();
27.07/10.36 }
27.07/10.36
27.07/10.36
27.07/10.36 /*
27.07/10.36 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
27.07/10.36 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.07/10.36 *
27.07/10.36 * This code is free software; you can redistribute it and/or modify it
27.07/10.36 * under the terms of the GNU General Public License version 2 only, as
27.07/10.36 * published by the Free Software Foundation. Sun designates this
27.07/10.36 * particular file as subject to the "Classpath" exception as provided
27.07/10.36 * by Sun in the LICENSE file that accompanied this code.
27.07/10.36 *
27.07/10.36 * This code is distributed in the hope that it will be useful, but WITHOUT
27.07/10.36 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.07/10.36 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.07/10.36 * version 2 for more details (a copy is included in the LICENSE file that
27.07/10.36 * accompanied this code).
27.07/10.36 *
27.07/10.36 * You should have received a copy of the GNU General Public License version
27.07/10.36 * 2 along with this work; if not, write to the Free Software Foundation,
27.07/10.36 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.07/10.36 *
27.07/10.36 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27.07/10.36 * CA 95054 USA or visit www.sun.com if you need additional information or
27.07/10.36 * have any questions.
27.07/10.36 */
27.07/10.36
27.07/10.36 package javaUtilEx;
27.07/10.36
27.07/10.36 /**
27.07/10.36 * This exception may be thrown by methods that have detected concurrent
27.07/10.36 * modification of an object when such modification is not permissible.
27.07/10.36 *
27.07/10.36 * For example, it is not generally permissible for one thread to modify a Collection
27.07/10.36 * while another thread is iterating over it. In general, the results of the
27.07/10.36 * iteration are undefined under these circumstances. Some Iterator
27.07/10.36 * implementations (including those of all the general purpose collection implementations
27.07/10.36 * provided by the JRE) may choose to throw this exception if this behavior is
27.07/10.36 * detected. Iterators that do this are known as fail-fast iterators,
27.07/10.36 * as they fail quickly and cleanly, rather that risking arbitrary,
27.07/10.36 * non-deterministic behavior at an undetermined time in the future.
27.07/10.36 *
27.07/10.36 * Note that this exception does not always indicate that an object has
27.07/10.36 * been concurrently modified by a different thread. If a single
27.07/10.36 * thread issues a sequence of method invocations that violates the
27.07/10.36 * contract of an object, the object may throw this exception. For
27.07/10.36 * example, if a thread modifies a collection directly while it is
27.07/10.36 * iterating over the collection with a fail-fast iterator, the iterator
27.07/10.36 * will throw this exception.
27.07/10.36 *
27.07/10.36 * Note that fail-fast behavior cannot be guaranteed as it is, generally
27.07/10.36 * speaking, impossible to make any hard guarantees in the presence of
27.07/10.36 * unsynchronized concurrent modification. Fail-fast operations
27.07/10.36 * throw ConcurrentModificationException on a best-effort basis.
27.07/10.36 * Therefore, it would be wrong to write a program that depended on this
27.07/10.36 * exception for its correctness: ConcurrentModificationException
27.07/10.36 * should be used only to detect bugs.
27.07/10.36 *
27.07/10.36 * @author Josh Bloch
27.07/10.36 * @see Collection
27.07/10.36 * @see Iterator
27.07/10.36 * @see ListIterator
27.07/10.36 * @see Vector
27.07/10.36 * @see LinkedList
27.07/10.36 * @see HashSet
27.07/10.36 * @see Hashtable
27.07/10.36 * @see TreeMap
27.07/10.36 * @see AbstractList
27.07/10.36 * @since 1.2
27.07/10.36 */
27.07/10.36 public class ConcurrentModificationException extends RuntimeException {
27.07/10.36 /**
27.07/10.36 * Constructs a ConcurrentModificationException with no
27.07/10.36 * detail message.
27.07/10.36 */
27.07/10.36 public ConcurrentModificationException() {
27.07/10.36 }
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Constructs a ConcurrentModificationException with the
27.07/10.36 * specified detail message.
27.07/10.36 *
27.07/10.36 * @param message the detail message pertaining to this exception.
27.07/10.36 */
27.07/10.36 public ConcurrentModificationException(String message) {
27.07/10.36 super(message);
27.07/10.36 }
27.07/10.36 }
27.07/10.36
27.07/10.36
27.07/10.36 /*
27.07/10.36 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
27.07/10.36 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.07/10.36 *
27.07/10.36 * This code is free software; you can redistribute it and/or modify it
27.07/10.36 * under the terms of the GNU General Public License version 2 only, as
27.07/10.36 * published by the Free Software Foundation. Sun designates this
27.07/10.36 * particular file as subject to the "Classpath" exception as provided
27.07/10.36 * by Sun in the LICENSE file that accompanied this code.
27.07/10.36 *
27.07/10.36 * This code is distributed in the hope that it will be useful, but WITHOUT
27.07/10.36 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.07/10.36 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.07/10.36 * version 2 for more details (a copy is included in the LICENSE file that
27.07/10.36 * accompanied this code).
27.07/10.36 *
27.07/10.36 * You should have received a copy of the GNU General Public License version
27.07/10.36 * 2 along with this work; if not, write to the Free Software Foundation,
27.07/10.36 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.07/10.36 *
27.07/10.36 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27.07/10.36 * CA 95054 USA or visit www.sun.com if you need additional information or
27.07/10.36 * have any questions.
27.07/10.36 */
27.07/10.36
27.07/10.36 package javaUtilEx;
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Hash table based implementation of the Map interface. This
27.07/10.36 * implementation provides all of the optional map operations, and permits
27.07/10.36 * null values and the null key. (The HashMap
27.07/10.36 * class is roughly equivalent to Hashtable, except that it is
27.07/10.36 * unsynchronized and permits nulls.) This class makes no guarantees as to
27.07/10.36 * the order of the map; in particular, it does not guarantee that the order
27.07/10.36 * will remain constant over time.
27.07/10.36 *
27.07/10.36 * This implementation provides constant-time performance for the basic
27.07/10.36 * operations (get and put), assuming the hash function
27.07/10.36 * disperses the elements properly among the buckets. Iteration over
27.07/10.36 * collection views requires time proportional to the "capacity" of the
27.07/10.36 * HashMap instance (the number of buckets) plus its size (the number
27.07/10.36 * of key-value mappings). Thus, it's very important not to set the initial
27.07/10.36 * capacity too high (or the load factor too low) if iteration performance is
27.07/10.36 * important.
27.07/10.36 *
27.07/10.36 * An instance of HashMap has two parameters that affect its
27.07/10.36 * performance: initial capacity and load factor. The
27.07/10.36 * capacity is the number of buckets in the hash table, and the initial
27.07/10.36 * capacity is simply the capacity at the time the hash table is created. The
27.07/10.36 * load factor is a measure of how full the hash table is allowed to
27.07/10.36 * get before its capacity is automatically increased. When the number of
27.07/10.36 * entries in the hash table exceeds the product of the load factor and the
27.07/10.36 * current capacity, the hash table is rehashed (that is, internal data
27.07/10.36 * structures are rebuilt) so that the hash table has approximately twice the
27.07/10.36 * number of buckets.
27.07/10.36 *
27.07/10.36 * As a general rule, the default load factor (.75) offers a good tradeoff
27.07/10.36 * between time and space costs. Higher values decrease the space overhead
27.07/10.36 * but increase the lookup cost (reflected in most of the operations of the
27.07/10.36 * HashMap class, including get and put). The
27.07/10.36 * expected number of entries in the map and its load factor should be taken
27.07/10.36 * into account when setting its initial capacity, so as to minimize the
27.07/10.36 * number of rehash operations. If the initial capacity is greater
27.07/10.36 * than the maximum number of entries divided by the load factor, no
27.07/10.36 * rehash operations will ever occur.
27.07/10.36 *
27.07/10.36 * If many mappings are to be stored in a HashMap instance,
27.07/10.36 * creating it with a sufficiently large capacity will allow the mappings to
27.07/10.36 * be stored more efficiently than letting it perform automatic rehashing as
27.07/10.36 * needed to grow the table.
27.07/10.36 *
27.07/10.36 * Note that this implementation is not synchronized.
27.07/10.36 * If multiple threads access a hash map concurrently, and at least one of
27.07/10.36 * the threads modifies the map structurally, it must be
27.07/10.36 * synchronized externally. (A structural modification is any operation
27.07/10.36 * that adds or deletes one or more mappings; merely changing the value
27.07/10.36 * associated with a key that an instance already contains is not a
27.07/10.36 * structural modification.) This is typically accomplished by
27.07/10.36 * synchronizing on some object that naturally encapsulates the map.
27.07/10.36 *
27.07/10.36 * If no such object exists, the map should be "wrapped" using the
27.07/10.36 * {@link Collections#synchronizedMap Collections.synchronizedMap}
27.07/10.36 * method. This is best done at creation time, to prevent accidental
27.07/10.36 * unsynchronized access to the map: The iterators returned by all of this class's "collection view methods"
27.07/10.36 * are fail-fast: if the map is structurally modified at any time after
27.07/10.36 * the iterator is created, in any way except through the iterator's own
27.07/10.36 * remove method, the iterator will throw a
27.07/10.36 * {@link ConcurrentModificationException}. Thus, in the face of concurrent
27.07/10.36 * modification, the iterator fails quickly and cleanly, rather than risking
27.07/10.36 * arbitrary, non-deterministic behavior at an undetermined time in the
27.07/10.36 * future.
27.07/10.36 *
27.07/10.36 * Note that the fail-fast behavior of an iterator cannot be guaranteed
27.07/10.36 * as it is, generally speaking, impossible to make any hard guarantees in the
27.07/10.36 * presence of unsynchronized concurrent modification. Fail-fast iterators
27.07/10.36 * throw ConcurrentModificationException on a best-effort basis.
27.07/10.36 * Therefore, it would be wrong to write a program that depended on this
27.07/10.36 * exception for its correctness: the fail-fast behavior of iterators
27.07/10.36 * should be used only to detect bugs.
27.07/10.36 *
27.07/10.36 * This class is a member of the
27.07/10.36 *
27.07/10.36 * Java Collections Framework.
27.07/10.36 *
27.07/10.36 * @param More formally, if this map contains a mapping from a key
27.07/10.36 * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
27.07/10.36 * key.equals(k))}, then this method returns {@code v}; otherwise
27.07/10.36 * it returns {@code null}. (There can be at most one such mapping.)
27.07/10.36 *
27.07/10.36 * A return value of {@code null} does not necessarily
27.07/10.36 * indicate that the map contains no mapping for the key; it's also
27.07/10.36 * possible that the map explicitly maps the key to {@code null}.
27.07/10.36 * The {@link #containsKey containsKey} operation may be used to
27.07/10.36 * distinguish these two cases.
27.07/10.36 *
27.07/10.36 * @see #put(Object, Object)
27.07/10.36 */
27.07/10.36 public V get(Object key) {
27.07/10.36 if (key == null)
27.07/10.36 return getForNullKey();
27.07/10.36 int hash = hash(key.hashCode());
27.07/10.36 for (Entry Note that the detail message associated with Note that the detail message associated with This interface is a member of the
27.07/10.37 *
27.07/10.37 * Java Collections Framework.
27.07/10.37 *
27.07/10.37 * @author Josh Bloch
27.07/10.37 * @see Collection
27.07/10.37 * @see ListIterator
27.07/10.37 * @see Iterable
27.07/10.37 * @since 1.2
27.07/10.37 */
27.07/10.37 public interface Iterator This interface takes the place of the Dictionary class, which
27.07/10.37 * was a totally abstract class rather than an interface.
27.07/10.37 *
27.07/10.37 * The Map interface provides three collection views, which
27.07/10.37 * allow a map's contents to be viewed as a set of keys, collection of values,
27.07/10.37 * or set of key-value mappings. The order of a map is defined as
27.07/10.37 * the order in which the iterators on the map's collection views return their
27.07/10.37 * elements. Some map implementations, like the TreeMap class, make
27.07/10.37 * specific guarantees as to their order; others, like the HashMap
27.07/10.37 * class, do not.
27.07/10.37 *
27.07/10.37 * Note: great care must be exercised if mutable objects are used as map
27.07/10.37 * keys. The behavior of a map is not specified if the value of an object is
27.07/10.37 * changed in a manner that affects equals comparisons while the
27.07/10.37 * object is a key in the map. A special case of this prohibition is that it
27.07/10.37 * is not permissible for a map to contain itself as a key. While it is
27.07/10.37 * permissible for a map to contain itself as a value, extreme caution is
27.07/10.37 * advised: the equals and hashCode methods are no longer
27.07/10.37 * well defined on such a map.
27.07/10.37 *
27.07/10.37 * All general-purpose map implementation classes should provide two
27.07/10.37 * "standard" constructors: a void (no arguments) constructor which creates an
27.07/10.37 * empty map, and a constructor with a single argument of type Map,
27.07/10.37 * which creates a new map with the same key-value mappings as its argument.
27.07/10.37 * In effect, the latter constructor allows the user to copy any map,
27.07/10.37 * producing an equivalent map of the desired class. There is no way to
27.07/10.37 * enforce this recommendation (as interfaces cannot contain constructors) but
27.07/10.37 * all of the general-purpose map implementations in the JDK comply.
27.07/10.37 *
27.07/10.37 * The "destructive" methods contained in this interface, that is, the
27.07/10.37 * methods that modify the map on which they operate, are specified to throw
27.07/10.37 * UnsupportedOperationException if this map does not support the
27.07/10.37 * operation. If this is the case, these methods may, but are not required
27.07/10.37 * to, throw an UnsupportedOperationException if the invocation would
27.07/10.37 * have no effect on the map. For example, invoking the {@link #putAll(Map)}
27.07/10.37 * method on an unmodifiable map may, but is not required to, throw the
27.07/10.37 * exception if the map whose mappings are to be "superimposed" is empty.
27.07/10.37 *
27.07/10.37 * Some map implementations have restrictions on the keys and values they
27.07/10.37 * may contain. For example, some implementations prohibit null keys and
27.07/10.37 * values, and some have restrictions on the types of their keys. Attempting
27.07/10.37 * to insert an ineligible key or value throws an unchecked exception,
27.07/10.37 * typically NullPointerException or ClassCastException.
27.07/10.37 * Attempting to query the presence of an ineligible key or value may throw an
27.07/10.37 * exception, or it may simply return false; some implementations will exhibit
27.07/10.37 * the former behavior and some will exhibit the latter. More generally,
27.07/10.37 * attempting an operation on an ineligible key or value whose completion
27.07/10.37 * would not result in the insertion of an ineligible element into the map may
27.07/10.37 * throw an exception or it may succeed, at the option of the implementation.
27.07/10.37 * Such exceptions are marked as "optional" in the specification for this
27.07/10.37 * interface.
27.07/10.37 *
27.07/10.37 * This interface is a member of the
27.07/10.37 *
27.07/10.37 * Java Collections Framework.
27.07/10.37 *
27.07/10.37 * Many methods in Collections Framework interfaces are defined
27.07/10.37 * in terms of the {@link Object#equals(Object) equals} method. For
27.07/10.37 * example, the specification for the {@link #containsKey(Object)
27.07/10.37 * containsKey(Object key)} method says: "returns true if and
27.07/10.37 * only if this map contains a mapping for a key k such that
27.07/10.37 * (key==null ? k==null : key.equals(k))." This specification should
27.07/10.37 * not be construed to imply that invoking Map.containsKey
27.07/10.37 * with a non-null argument key will cause key.equals(k) to
27.07/10.37 * be invoked for any key k. Implementations are free to
27.07/10.37 * implement optimizations whereby the equals invocation is avoided,
27.07/10.37 * for example, by first comparing the hash codes of the two keys. (The
27.07/10.37 * {@link Object#hashCode()} specification guarantees that two objects with
27.07/10.37 * unequal hash codes cannot be equal.) More generally, implementations of
27.07/10.37 * the various Collections Framework interfaces are free to take advantage of
27.07/10.37 * the specified behavior of underlying {@link Object} methods wherever the
27.07/10.37 * implementor deems it appropriate.
27.07/10.37 *
27.07/10.37 * @param More formally, if this map contains a mapping from a key
27.07/10.37 * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
27.07/10.37 * key.equals(k))}, then this method returns {@code v}; otherwise
27.07/10.37 * it returns {@code null}. (There can be at most one such mapping.)
27.07/10.37 *
27.07/10.37 * If this map permits null values, then a return value of
27.07/10.37 * {@code null} does not necessarily indicate that the map
27.07/10.37 * contains no mapping for the key; it's also possible that the map
27.07/10.37 * explicitly maps the key to {@code null}. The {@link #containsKey
27.07/10.37 * containsKey} operation may be used to distinguish these two cases.
27.07/10.37 *
27.07/10.37 * @param key the key whose associated value is to be returned
27.07/10.37 * @return the value to which the specified key is mapped, or
27.07/10.37 * {@code null} if this map contains no mapping for the key
27.07/10.37 * @throws ClassCastException if the key is of an inappropriate type for
27.07/10.37 * this map (optional)
27.07/10.37 * @throws NullPointerException if the specified key is null and this map
27.07/10.37 * does not permit null keys (optional)
27.07/10.37 */
27.07/10.37 V get(Object key);
27.07/10.37
27.07/10.37 // Modification Operations
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Associates the specified value with the specified key in this map
27.07/10.37 * (optional operation). If the map previously contained a mapping for
27.07/10.37 * the key, the old value is replaced by the specified value. (A map
27.07/10.37 * m is said to contain a mapping for a key k if and only
27.07/10.37 * if {@link #containsKey(Object) m.containsKey(k)} would return
27.07/10.37 * true.)
27.07/10.37 *
27.07/10.37 * @param key key with which the specified value is to be associated
27.07/10.37 * @param value value to be associated with the specified key
27.07/10.37 * @return the previous value associated with key, or
27.07/10.37 * null if there was no mapping for key.
27.07/10.37 * (A null return can also indicate that the map
27.07/10.37 * previously associated null with key,
27.07/10.37 * if the implementation supports null values.)
27.07/10.37 * @throws UnsupportedOperationException if the put operation
27.07/10.37 * is not supported by this map
27.07/10.37 * @throws ClassCastException if the class of the specified key or value
27.07/10.37 * prevents it from being stored in this map
27.07/10.37 * @throws NullPointerException if the specified key or value is null
27.07/10.37 * and this map does not permit null keys or values
27.07/10.37 * @throws IllegalArgumentException if some property of the specified key
27.07/10.37 * or value prevents it from being stored in this map
27.07/10.37 */
27.07/10.37 V put(K key, V value);
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Removes the mapping for a key from this map if it is present
27.07/10.37 * (optional operation). More formally, if this map contains a mapping
27.07/10.37 * from key k to value v such that
27.07/10.37 * Returns the value to which this map previously associated the key,
27.07/10.37 * or null if the map contained no mapping for the key.
27.07/10.37 *
27.07/10.37 * If this map permits null values, then a return value of
27.07/10.37 * null does not necessarily indicate that the map
27.07/10.37 * contained no mapping for the key; it's also possible that the map
27.07/10.37 * explicitly mapped the key to null.
27.07/10.37 *
27.07/10.37 * The map will not contain a mapping for the specified key once the
27.07/10.37 * call returns.
27.07/10.37 *
27.07/10.37 * @param key key whose mapping is to be removed from the map
27.07/10.37 * @return the previous value associated with key, or
27.07/10.37 * null if there was no mapping for key.
27.07/10.37 * @throws UnsupportedOperationException if the remove operation
27.07/10.37 * is not supported by this map
27.07/10.37 * @throws ClassCastException if the key is of an inappropriate type for
27.07/10.37 * this map (optional)
27.07/10.37 * @throws NullPointerException if the specified key is null and this
27.07/10.37 * map does not permit null keys (optional)
27.07/10.37 */
27.07/10.37 V remove(Object key);
27.07/10.37
27.07/10.37
27.07/10.37 // Bulk Operations
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Copies all of the mappings from the specified map to this map
27.07/10.37 * (optional operation). The effect of this call is equivalent to that
27.07/10.37 * of calling {@link #put(Object,Object) put(k, v)} on this map once
27.07/10.37 * for each mapping from key k to value v in the
27.07/10.37 * specified map. The behavior of this operation is undefined if the
27.07/10.37 * specified map is modified while the operation is in progress.
27.07/10.37 *
27.07/10.37 * @param m mappings to be stored in this map
27.07/10.37 * @throws UnsupportedOperationException if the putAll operation
27.07/10.37 * is not supported by this map
27.07/10.37 * @throws ClassCastException if the class of a key or value in the
27.07/10.37 * specified map prevents it from being stored in this map
27.07/10.37 * @throws NullPointerException if the specified map is null, or if
27.07/10.37 * this map does not permit null keys or values, and the
27.07/10.37 * specified map contains null keys or values
27.07/10.37 * @throws IllegalArgumentException if some property of a key or value in
27.07/10.37 * the specified map prevents it from being stored in this map
27.07/10.37 */
27.07/10.37 void putAll(Map extends K, ? extends V> m);
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Removes all of the mappings from this map (optional operation).
27.07/10.37 * The map will be empty after this call returns.
27.07/10.37 *
27.07/10.37 * @throws UnsupportedOperationException if the clear operation
27.07/10.37 * is not supported by this map
27.07/10.37 */
27.07/10.37 void clear();
27.07/10.37
27.07/10.37
27.07/10.37 // Views
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Returns a {@link Set} view of the keys contained in this map.
27.07/10.37 * The set is backed by the map, so changes to the map are
27.07/10.37 * reflected in the set, and vice-versa. If the map is modified
27.07/10.37 * while an iteration over the set is in progress (except through
27.07/10.37 * the iterator's own remove operation), the results of
27.07/10.37 * the iteration are undefined. The set supports element removal,
27.07/10.37 * which removes the corresponding mapping from the map, via the
27.07/10.37 * Iterator.remove, Set.remove,
27.07/10.37 * removeAll, retainAll, and clear
27.07/10.37 * operations. It does not support the add or addAll
27.07/10.37 * operations.
27.07/10.37 *
27.07/10.37 * @return a set view of the keys contained in this map
27.07/10.37 */
27.07/10.37 Set The Set interface places additional stipulations, beyond those
27.07/10.37 * inherited from the Collection interface, on the contracts of all
27.07/10.37 * constructors and on the contracts of the add, equals and
27.07/10.37 * hashCode methods. Declarations for other inherited methods are
27.07/10.37 * also included here for convenience. (The specifications accompanying these
27.07/10.37 * declarations have been tailored to the Set interface, but they do
27.07/10.37 * not contain any additional stipulations.)
27.07/10.37 *
27.07/10.37 * The additional stipulation on constructors is, not surprisingly,
27.07/10.37 * that all constructors must create a set that contains no duplicate elements
27.07/10.37 * (as defined above).
27.07/10.37 *
27.07/10.37 * Note: Great care must be exercised if mutable objects are used as set
27.07/10.37 * elements. The behavior of a set is not specified if the value of an object
27.07/10.37 * is changed in a manner that affects equals comparisons while the
27.07/10.37 * object is an element in the set. A special case of this prohibition is
27.07/10.37 * that it is not permissible for a set to contain itself as an element.
27.07/10.37 *
27.07/10.37 * Some set implementations have restrictions on the elements that
27.07/10.37 * they may contain. For example, some implementations prohibit null elements,
27.07/10.37 * and some have restrictions on the types of their elements. Attempting to
27.07/10.37 * add an ineligible element throws an unchecked exception, typically
27.07/10.37 * NullPointerException or ClassCastException. Attempting
27.07/10.37 * to query the presence of an ineligible element may throw an exception,
27.07/10.37 * or it may simply return false; some implementations will exhibit the former
27.07/10.37 * behavior and some will exhibit the latter. More generally, attempting an
27.07/10.37 * operation on an ineligible element whose completion would not result in
27.07/10.37 * the insertion of an ineligible element into the set may throw an
27.07/10.37 * exception or it may succeed, at the option of the implementation.
27.07/10.37 * Such exceptions are marked as "optional" in the specification for this
27.07/10.37 * interface.
27.07/10.37 *
27.07/10.37 * This interface is a member of the
27.07/10.37 *
27.07/10.37 * Java Collections Framework.
27.07/10.37 *
27.07/10.37 * @param The returned array will be "safe" in that no references to it
27.07/10.37 * are maintained by this set. (In other words, this method must
27.07/10.37 * allocate a new array even if this set is backed by an array).
27.07/10.37 * The caller is thus free to modify the returned array.
27.07/10.37 *
27.07/10.37 * This method acts as bridge between array-based and collection-based
27.07/10.37 * APIs.
27.07/10.37 *
27.07/10.37 * @return an array containing all the elements in this set
27.07/10.37 */
27.07/10.37 Object[] toArray();
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Returns an array containing all of the elements in this set; the
27.07/10.37 * runtime type of the returned array is that of the specified array.
27.07/10.37 * If the set fits in the specified array, it is returned therein.
27.07/10.37 * Otherwise, a new array is allocated with the runtime type of the
27.07/10.37 * specified array and the size of this set.
27.07/10.37 *
27.07/10.37 * If this set fits in the specified array with room to spare
27.07/10.37 * (i.e., the array has more elements than this set), the element in
27.07/10.37 * the array immediately following the end of the set is set to
27.07/10.37 * null. (This is useful in determining the length of this
27.07/10.37 * set only if the caller knows that this set does not contain
27.07/10.37 * any null elements.)
27.07/10.37 *
27.07/10.37 * If this set makes any guarantees as to what order its elements
27.07/10.37 * are returned by its iterator, this method must return the elements
27.07/10.37 * in the same order.
27.07/10.37 *
27.07/10.37 * Like the {@link #toArray()} method, this method acts as bridge between
27.07/10.37 * array-based and collection-based APIs. Further, this method allows
27.07/10.37 * precise control over the runtime type of the output array, and may,
27.07/10.37 * under certain circumstances, be used to save allocation costs.
27.07/10.37 *
27.07/10.37 * Suppose x is a set known to contain only strings.
27.07/10.37 * The following code can be used to dump the set into a newly allocated
27.07/10.37 * array of String:
27.07/10.37 *
27.07/10.37 * The stipulation above does not imply that sets must accept all
27.07/10.37 * elements; sets may refuse to add any particular element, including
27.07/10.37 * null, and throw an exception, as described in the
27.07/10.37 * specification for {@link Collection#add Collection.add}.
27.07/10.37 * Individual set implementations should clearly document any
27.07/10.37 * restrictions on the elements that they may contain.
27.07/10.37 *
27.07/10.37 * @param e element to be added to this set
27.07/10.37 * @return true if this set did not already contain the specified
27.07/10.37 * element
27.07/10.37 * @throws UnsupportedOperationException if the add operation
27.07/10.37 * is not supported by this set
27.07/10.37 * @throws ClassCastException if the class of the specified element
27.07/10.37 * prevents it from being added to this set
27.07/10.37 * @throws NullPointerException if the specified element is null and this
27.07/10.37 * set does not permit null elements
27.07/10.37 * @throws IllegalArgumentException if some property of the specified element
27.07/10.37 * prevents it from being added to this set
27.07/10.37 */
27.07/10.37 boolean add(E e);
27.07/10.37
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Removes the specified element from this set if it is present
27.07/10.37 * (optional operation). More formally, removes an element e
27.07/10.37 * such that
27.07/10.37 * (o==null ? e==null : o.equals(e)), if
27.07/10.37 * this set contains such an element. Returns true if this set
27.07/10.37 * contained the element (or equivalently, if this set changed as a
27.07/10.37 * result of the call). (This set will not contain the element once the
27.07/10.37 * call returns.)
27.07/10.37 *
27.07/10.37 * @param o object to be removed from this set, if present
27.07/10.37 * @return true if this set contained the specified element
27.07/10.37 * @throws ClassCastException if the type of the specified element
27.07/10.37 * is incompatible with this set (optional)
27.07/10.37 * @throws NullPointerException if the specified element is null and this
27.07/10.37 * set does not permit null elements (optional)
27.07/10.37 * @throws UnsupportedOperationException if the remove operation
27.07/10.37 * is not supported by this set
27.07/10.37 */
27.07/10.37 boolean remove(Object o);
27.07/10.37
27.07/10.37
27.07/10.37 // Bulk Operations
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Returns true if this set contains all of the elements of the
27.07/10.37 * specified collection. If the specified collection is also a set, this
27.07/10.37 * method returns true if it is a subset of this set.
27.07/10.37 *
27.07/10.37 * @param c collection to be checked for containment in this set
27.07/10.37 * @return true if this set contains all of the elements of the
27.07/10.37 * specified collection
27.07/10.37 * @throws ClassCastException if the types of one or more elements
27.07/10.37 * in the specified collection are incompatible with this
27.07/10.37 * set (optional)
27.07/10.37 * @throws NullPointerException if the specified collection contains one
27.07/10.37 * or more null elements and this set does not permit null
27.07/10.37 * elements (optional), or if the specified collection is null
27.07/10.37 * @see #contains(Object)
27.07/10.37 */
27.07/10.37 boolean containsAll(Collection> c);
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Adds all of the elements in the specified collection to this set if
27.07/10.37 * they're not already present (optional operation). If the specified
27.07/10.37 * collection is also a set, the addAll operation effectively
27.07/10.37 * modifies this set so that its value is the union of the two
27.07/10.37 * sets. The behavior of this operation is undefined if the specified
27.07/10.37 * collection is modified while the operation is in progress.
27.07/10.37 *
27.07/10.37 * @param c collection containing elements to be added to this set
27.07/10.37 * @return true if this set changed as a result of the call
27.07/10.37 *
27.07/10.37 * @throws UnsupportedOperationException if the addAll operation
27.07/10.37 * is not supported by this set
27.07/10.37 * @throws ClassCastException if the class of an element of the
27.07/10.37 * specified collection prevents it from being added to this set
27.07/10.37 * @throws NullPointerException if the specified collection contains one
27.07/10.37 * or more null elements and this set does not permit null
27.07/10.37 * elements, or if the specified collection is null
27.07/10.37 * @throws IllegalArgumentException if some property of an element of the
27.07/10.37 * specified collection prevents it from being added to this set
27.07/10.37 * @see #add(Object)
27.07/10.37 */
27.07/10.37 boolean addAll(Collection extends E> c);
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Retains only the elements in this set that are contained in the
27.07/10.37 * specified collection (optional operation). In other words, removes
27.07/10.37 * from this set all of its elements that are not contained in the
27.07/10.37 * specified collection. If the specified collection is also a set, this
27.07/10.37 * operation effectively modifies this set so that its value is the
27.07/10.37 * intersection of the two sets.
27.07/10.37 *
27.07/10.37 * @param c collection containing elements to be retained in this set
27.07/10.37 * @return true if this set changed as a result of the call
27.07/10.37 * @throws UnsupportedOperationException if the retainAll operation
27.07/10.37 * is not supported by this set
27.07/10.37 * @throws ClassCastException if the class of an element of this set
27.07/10.37 * is incompatible with the specified collection (optional)
27.07/10.37 * @throws NullPointerException if this set contains a null element and the
27.07/10.37 * specified collection does not permit null elements (optional),
27.07/10.37 * or if the specified collection is null
27.07/10.37 * @see #remove(Object)
27.07/10.37 */
27.07/10.37 boolean retainAll(Collection> c);
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Removes from this set all of its elements that are contained in the
27.07/10.37 * specified collection (optional operation). If the specified
27.07/10.37 * collection is also a set, this operation effectively modifies this
27.07/10.37 * set so that its value is the asymmetric set difference of
27.07/10.37 * the two sets.
27.07/10.37 *
27.07/10.37 * @param c collection containing elements to be removed from this set
27.07/10.37 * @return true if this set changed as a result of the call
27.07/10.37 * @throws UnsupportedOperationException if the removeAll operation
27.07/10.37 * is not supported by this set
27.07/10.37 * @throws ClassCastException if the class of an element of this set
27.07/10.37 * is incompatible with the specified collection (optional)
27.07/10.37 * @throws NullPointerException if this set contains a null element and the
27.07/10.37 * specified collection does not permit null elements (optional),
27.07/10.37 * or if the specified collection is null
27.07/10.37 * @see #remove(Object)
27.07/10.37 * @see #contains(Object)
27.07/10.37 */
27.07/10.37 boolean removeAll(Collection> c);
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Removes all of the elements from this set (optional operation).
27.07/10.37 * The set will be empty after this call returns.
27.07/10.37 *
27.07/10.37 * @throws UnsupportedOperationException if the clear method
27.07/10.37 * is not supported by this set
27.07/10.37 */
27.07/10.37 void clear();
27.07/10.37
27.07/10.37
27.07/10.37 // Comparison and hashing
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Compares the specified object with this set for equality. Returns
27.07/10.37 * true if the specified object is also a set, the two sets
27.07/10.37 * have the same size, and every member of the specified set is
27.07/10.37 * contained in this set (or equivalently, every member of this set is
27.07/10.37 * contained in the specified set). This definition ensures that the
27.07/10.37 * equals method works properly across different implementations of the
27.07/10.37 * set interface.
27.07/10.37 *
27.07/10.37 * @param o object to be compared for equality with this set
27.07/10.37 * @return true if the specified object is equal to this set
27.07/10.37 */
27.07/10.37 boolean equals(Object o);
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Returns the hash code value for this set. The hash code of a set is
27.07/10.37 * defined to be the sum of the hash codes of the elements in the set,
27.07/10.37 * where the hash code of a null element is defined to be zero.
27.07/10.37 * This ensures that s1.equals(s2) implies that
27.07/10.37 * s1.hashCode()==s2.hashCode() for any two sets s1
27.07/10.37 * and s2, as required by the general contract of
27.07/10.37 * {@link Object#hashCode}.
27.07/10.37 *
27.07/10.37 * @return the hash code value for this set
27.07/10.37 * @see Object#equals(Object)
27.07/10.37 * @see Set#equals(Object)
27.07/10.37 */
27.07/10.37 int hashCode();
27.07/10.37 }
27.07/10.37
27.07/10.37
27.07/10.37 /*
27.07/10.37 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
27.07/10.37 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.07/10.37 *
27.07/10.37 * This code is free software; you can redistribute it and/or modify it
27.07/10.37 * under the terms of the GNU General Public License version 2 only, as
27.07/10.37 * published by the Free Software Foundation. Sun designates this
27.07/10.37 * particular file as subject to the "Classpath" exception as provided
27.07/10.37 * by Sun in the LICENSE file that accompanied this code.
27.07/10.37 *
27.07/10.37 * This code is distributed in the hope that it will be useful, but WITHOUT
27.07/10.37 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.07/10.37 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.07/10.37 * version 2 for more details (a copy is included in the LICENSE file that
27.07/10.37 * accompanied this code).
27.07/10.37 *
27.07/10.37 * You should have received a copy of the GNU General Public License version
27.07/10.37 * 2 along with this work; if not, write to the Free Software Foundation,
27.07/10.37 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.07/10.37 *
27.07/10.37 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27.07/10.37 * CA 95054 USA or visit www.sun.com if you need additional information or
27.07/10.37 * have any questions.
27.07/10.37 */
27.07/10.37
27.07/10.37 package javaUtilEx;
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Thrown to indicate that the requested operation is not supported.
27.07/10.37 *
27.07/10.37 * This class is a member of the
27.07/10.37 *
27.07/10.37 * Java Collections Framework.
27.07/10.37 *
27.07/10.37 * @author Josh Bloch
27.07/10.37 * @since 1.2
27.07/10.37 */
27.07/10.37 public class UnsupportedOperationException extends RuntimeException {
27.07/10.37 /**
27.07/10.37 * Constructs an UnsupportedOperationException with no detail message.
27.07/10.37 */
27.07/10.37 public UnsupportedOperationException() {
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Constructs an UnsupportedOperationException with the specified
27.07/10.37 * detail message.
27.07/10.37 *
27.07/10.37 * @param message the detail message
27.07/10.37 */
27.07/10.37 public UnsupportedOperationException(String message) {
27.07/10.37 super(message);
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Constructs a new exception with the specified detail message and
27.07/10.37 * cause.
27.07/10.37 *
27.07/10.37 * Note that the detail message associated with
27.07/10.37 *
27.07/10.37 * To implement an unmodifiable collection, the programmer needs only to
27.07/10.37 * extend this class and provide implementations for the iterator and
27.07/10.37 * size methods. (The iterator returned by the iterator
27.07/10.37 * method must implement hasNext and next.)
27.07/10.37 *
27.07/10.37 * To implement a modifiable collection, the programmer must additionally
27.07/10.37 * override this class's add method (which otherwise throws an
27.07/10.37 * UnsupportedOperationException), and the iterator returned by the
27.07/10.37 * iterator method must additionally implement its remove
27.07/10.37 * method.
27.07/10.37 *
27.07/10.37 * The programmer should generally provide a void (no argument) and
27.07/10.37 * Collection constructor, as per the recommendation in the
27.07/10.37 * Collection interface specification.
27.07/10.37 *
27.07/10.37 * The documentation for each non-abstract method in this class describes its
27.07/10.37 * implementation in detail. Each of these methods may be overridden if
27.07/10.37 * the collection being implemented admits a more efficient implementation.
27.07/10.37 *
27.07/10.37 * This class is a member of the
27.07/10.37 *
27.07/10.37 * Java Collections Framework.
27.07/10.37 *
27.07/10.37 * @author Josh Bloch
27.07/10.37 * @author Neal Gafter
27.07/10.37 * @see Collection
27.07/10.37 * @since 1.2
27.07/10.37 */
27.07/10.37
27.07/10.37 public abstract class AbstractCollection This implementation returns size() == 0.
27.07/10.37 */
27.07/10.37 public boolean isEmpty() {
27.07/10.37 return size() == 0;
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * {@inheritDoc}
27.07/10.37 *
27.07/10.37 * This implementation iterates over the elements in the collection,
27.07/10.37 * checking each element in turn for equality with the specified element.
27.07/10.37 *
27.07/10.37 * @throws ClassCastException {@inheritDoc}
27.07/10.37 * @throws NullPointerException {@inheritDoc}
27.07/10.37 */
27.07/10.37 public boolean contains(Object o) {
27.07/10.37 Iterator This implementation always throws an
27.07/10.37 * UnsupportedOperationException.
27.07/10.37 *
27.07/10.37 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.37 * @throws ClassCastException {@inheritDoc}
27.07/10.37 * @throws NullPointerException {@inheritDoc}
27.07/10.37 * @throws IllegalArgumentException {@inheritDoc}
27.07/10.37 * @throws IllegalStateException {@inheritDoc}
27.07/10.37 */
27.07/10.37 public boolean add(E e) {
27.07/10.37 throw new UnsupportedOperationException();
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * {@inheritDoc}
27.07/10.37 *
27.07/10.37 * This implementation iterates over the collection looking for the
27.07/10.37 * specified element. If it finds the element, it removes the element
27.07/10.37 * from the collection using the iterator's remove method.
27.07/10.37 *
27.07/10.37 * Note that this implementation throws an
27.07/10.37 * UnsupportedOperationException if the iterator returned by this
27.07/10.37 * collection's iterator method does not implement the remove
27.07/10.37 * method and this collection contains the specified object.
27.07/10.37 *
27.07/10.37 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.37 * @throws ClassCastException {@inheritDoc}
27.07/10.37 * @throws NullPointerException {@inheritDoc}
27.07/10.37 */
27.07/10.37 public boolean remove(Object o) {
27.07/10.37 Iterator This implementation iterates over the specified collection,
27.07/10.37 * checking each element returned by the iterator in turn to see
27.07/10.37 * if it's contained in this collection. If all elements are so
27.07/10.37 * contained true is returned, otherwise false.
27.07/10.37 *
27.07/10.37 * @throws ClassCastException {@inheritDoc}
27.07/10.37 * @throws NullPointerException {@inheritDoc}
27.07/10.37 * @see #contains(Object)
27.07/10.37 */
27.07/10.37 public boolean containsAll(Collection> c) {
27.07/10.37 Iterator> e = c.iterator();
27.07/10.37 while (e.hasNext())
27.07/10.37 if (!contains(e.next()))
27.07/10.37 return false;
27.07/10.37 return true;
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * {@inheritDoc}
27.07/10.37 *
27.07/10.37 * This implementation iterates over the specified collection, and adds
27.07/10.37 * each object returned by the iterator to this collection, in turn.
27.07/10.37 *
27.07/10.37 * Note that this implementation will throw an
27.07/10.37 * UnsupportedOperationException unless add is
27.07/10.37 * overridden (assuming the specified collection is non-empty).
27.07/10.37 *
27.07/10.37 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.37 * @throws ClassCastException {@inheritDoc}
27.07/10.37 * @throws NullPointerException {@inheritDoc}
27.07/10.37 * @throws IllegalArgumentException {@inheritDoc}
27.07/10.37 * @throws IllegalStateException {@inheritDoc}
27.07/10.37 *
27.07/10.37 * @see #add(Object)
27.07/10.37 */
27.07/10.37 public boolean addAll(Collection extends E> c) {
27.07/10.37 boolean modified = false;
27.07/10.37 Iterator extends E> e = c.iterator();
27.07/10.37 while (e.hasNext()) {
27.07/10.37 if (add(e.next()))
27.07/10.37 modified = true;
27.07/10.37 }
27.07/10.37 return modified;
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * {@inheritDoc}
27.07/10.37 *
27.07/10.37 * This implementation iterates over this collection, checking each
27.07/10.37 * element returned by the iterator in turn to see if it's contained
27.07/10.37 * in the specified collection. If it's so contained, it's removed from
27.07/10.37 * this collection with the iterator's remove method.
27.07/10.37 *
27.07/10.37 * Note that this implementation will throw an
27.07/10.37 * UnsupportedOperationException if the iterator returned by the
27.07/10.37 * iterator method does not implement the remove method
27.07/10.37 * and this collection contains one or more elements in common with the
27.07/10.37 * specified collection.
27.07/10.37 *
27.07/10.37 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.37 * @throws ClassCastException {@inheritDoc}
27.07/10.37 * @throws NullPointerException {@inheritDoc}
27.07/10.37 *
27.07/10.37 * @see #remove(Object)
27.07/10.37 * @see #contains(Object)
27.07/10.37 */
27.07/10.37 public boolean removeAll(Collection> c) {
27.07/10.37 boolean modified = false;
27.07/10.37 Iterator> e = iterator();
27.07/10.37 while (e.hasNext()) {
27.07/10.37 if (c.contains(e.next())) {
27.07/10.37 e.remove();
27.07/10.37 modified = true;
27.07/10.37 }
27.07/10.37 }
27.07/10.37 return modified;
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * {@inheritDoc}
27.07/10.37 *
27.07/10.37 * This implementation iterates over this collection, checking each
27.07/10.37 * element returned by the iterator in turn to see if it's contained
27.07/10.37 * in the specified collection. If it's not so contained, it's removed
27.07/10.37 * from this collection with the iterator's remove method.
27.07/10.37 *
27.07/10.37 * Note that this implementation will throw an
27.07/10.37 * UnsupportedOperationException if the iterator returned by the
27.07/10.37 * iterator method does not implement the remove method
27.07/10.37 * and this collection contains one or more elements not present in the
27.07/10.37 * specified collection.
27.07/10.37 *
27.07/10.37 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.37 * @throws ClassCastException {@inheritDoc}
27.07/10.37 * @throws NullPointerException {@inheritDoc}
27.07/10.37 *
27.07/10.37 * @see #remove(Object)
27.07/10.37 * @see #contains(Object)
27.07/10.37 */
27.07/10.37 public boolean retainAll(Collection> c) {
27.07/10.37 boolean modified = false;
27.07/10.37 Iterator This implementation iterates over this collection, removing each
27.07/10.37 * element using the Iterator.remove operation. Most
27.07/10.37 * implementations will probably choose to override this method for
27.07/10.37 * efficiency.
27.07/10.37 *
27.07/10.37 * Note that this implementation will throw an
27.07/10.37 * UnsupportedOperationException if the iterator returned by this
27.07/10.37 * collection's iterator method does not implement the
27.07/10.37 * remove method and this collection is non-empty.
27.07/10.37 *
27.07/10.37 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.37 */
27.07/10.37 public void clear() {
27.07/10.37 Iterator To implement an unmodifiable map, the programmer needs only to extend this
27.07/10.37 * class and provide an implementation for the entrySet method, which
27.07/10.37 * returns a set-view of the map's mappings. Typically, the returned set
27.07/10.37 * will, in turn, be implemented atop AbstractSet. This set should
27.07/10.37 * not support the add or remove methods, and its iterator
27.07/10.37 * should not support the remove method.
27.07/10.37 *
27.07/10.37 * To implement a modifiable map, the programmer must additionally override
27.07/10.37 * this class's put method (which otherwise throws an
27.07/10.37 * UnsupportedOperationException), and the iterator returned by
27.07/10.37 * entrySet().iterator() must additionally implement its
27.07/10.37 * remove method.
27.07/10.37 *
27.07/10.37 * The programmer should generally provide a void (no argument) and map
27.07/10.37 * constructor, as per the recommendation in the Map interface
27.07/10.37 * specification.
27.07/10.37 *
27.07/10.37 * The documentation for each non-abstract method in this class describes its
27.07/10.37 * implementation in detail. Each of these methods may be overridden if the
27.07/10.37 * map being implemented admits a more efficient implementation.
27.07/10.37 *
27.07/10.37 * This class is a member of the
27.07/10.37 *
27.07/10.37 * Java Collections Framework.
27.07/10.37 *
27.07/10.37 * @param This implementation returns entrySet().size().
27.07/10.37 */
27.07/10.37 public int size() {
27.07/10.37 return entrySet().size();
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * {@inheritDoc}
27.07/10.37 *
27.07/10.37 * This implementation returns size() == 0.
27.07/10.37 */
27.07/10.37 public boolean isEmpty() {
27.07/10.37 return size() == 0;
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * {@inheritDoc}
27.07/10.37 *
27.07/10.37 * This implementation iterates over entrySet() searching
27.07/10.37 * for an entry with the specified value. If such an entry is found,
27.07/10.37 * true is returned. If the iteration terminates without
27.07/10.37 * finding such an entry, false is returned. Note that this
27.07/10.37 * implementation requires linear time in the size of the map.
27.07/10.37 *
27.07/10.37 * @throws ClassCastException {@inheritDoc}
27.07/10.37 * @throws NullPointerException {@inheritDoc}
27.07/10.37 */
27.07/10.37 public boolean containsValue(Object value) {
27.07/10.37 Iterator This implementation iterates over entrySet() searching
27.07/10.37 * for an entry with the specified key. If such an entry is found,
27.07/10.37 * true is returned. If the iteration terminates without
27.07/10.37 * finding such an entry, false is returned. Note that this
27.07/10.37 * implementation requires linear time in the size of the map; many
27.07/10.37 * implementations will override this method.
27.07/10.37 *
27.07/10.37 * @throws ClassCastException {@inheritDoc}
27.07/10.37 * @throws NullPointerException {@inheritDoc}
27.07/10.37 */
27.07/10.37 public boolean containsKey(Object key) {
27.07/10.37 Iterator This implementation iterates over entrySet() searching
27.07/10.37 * for an entry with the specified key. If such an entry is found,
27.07/10.37 * the entry's value is returned. If the iteration terminates without
27.07/10.37 * finding such an entry, null is returned. Note that this
27.07/10.37 * implementation requires linear time in the size of the map; many
27.07/10.37 * implementations will override this method.
27.07/10.37 *
27.07/10.37 * @throws ClassCastException {@inheritDoc}
27.07/10.37 * @throws NullPointerException {@inheritDoc}
27.07/10.37 */
27.07/10.37 public V get(Object key) {
27.07/10.37 Iterator This implementation always throws an
27.07/10.37 * UnsupportedOperationException.
27.07/10.37 *
27.07/10.37 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.37 * @throws ClassCastException {@inheritDoc}
27.07/10.37 * @throws NullPointerException {@inheritDoc}
27.07/10.37 * @throws IllegalArgumentException {@inheritDoc}
27.07/10.37 */
27.07/10.37 public V put(K key, V value) {
27.07/10.37 throw new UnsupportedOperationException();
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * {@inheritDoc}
27.07/10.37 *
27.07/10.37 * This implementation iterates over entrySet() searching for an
27.07/10.37 * entry with the specified key. If such an entry is found, its value is
27.07/10.37 * obtained with its getValue operation, the entry is removed
27.07/10.37 * from the collection (and the backing map) with the iterator's
27.07/10.37 * remove operation, and the saved value is returned. If the
27.07/10.37 * iteration terminates without finding such an entry, null is
27.07/10.37 * returned. Note that this implementation requires linear time in the
27.07/10.37 * size of the map; many implementations will override this method.
27.07/10.37 *
27.07/10.37 * Note that this implementation throws an
27.07/10.37 * UnsupportedOperationException if the entrySet
27.07/10.37 * iterator does not support the remove method and this map
27.07/10.37 * contains a mapping for the specified key.
27.07/10.37 *
27.07/10.37 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.37 * @throws ClassCastException {@inheritDoc}
27.07/10.37 * @throws NullPointerException {@inheritDoc}
27.07/10.37 */
27.07/10.37 public V remove(Object key) {
27.07/10.37 Iterator This implementation iterates over the specified map's
27.07/10.37 * entrySet() collection, and calls this map's put
27.07/10.37 * operation once for each entry returned by the iteration.
27.07/10.37 *
27.07/10.37 * Note that this implementation throws an
27.07/10.37 * UnsupportedOperationException if this map does not support
27.07/10.37 * the put operation and the specified map is nonempty.
27.07/10.37 *
27.07/10.37 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.37 * @throws ClassCastException {@inheritDoc}
27.07/10.37 * @throws NullPointerException {@inheritDoc}
27.07/10.37 * @throws IllegalArgumentException {@inheritDoc}
27.07/10.37 */
27.07/10.37 public void putAll(Map extends K, ? extends V> m) {
27.07/10.37 Iterator it = m.entrySet().iterator();
27.07/10.37 while (it.hasNext()) {
27.07/10.37 Map.Entry e = (Map.Entry) it.next();
27.07/10.37 put((K) e.getKey(), (V) e.getValue());
27.07/10.37 }
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * {@inheritDoc}
27.07/10.37 *
27.07/10.37 * This implementation calls entrySet().clear().
27.07/10.37 *
27.07/10.37 * Note that this implementation throws an
27.07/10.37 * UnsupportedOperationException if the entrySet
27.07/10.37 * does not support the clear operation.
27.07/10.37 *
27.07/10.37 * @throws UnsupportedOperationException {@inheritDoc}
27.07/10.37 */
27.07/10.37 public void clear() {
27.07/10.37 entrySet().clear();
27.07/10.37 }
27.07/10.37
27.07/10.37
27.07/10.37 // Views
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Each of these fields are initialized to contain an instance of the
27.07/10.37 * appropriate view the first time this view is requested. The views are
27.07/10.37 * stateless, so there's no reason to create more than one of each.
27.07/10.37 */
27.07/10.37 transient volatile Set This implementation returns a set that subclasses {@link AbstractSet}.
27.07/10.37 * The subclass's iterator method returns a "wrapper object" over this
27.07/10.37 * map's entrySet() iterator. The size method
27.07/10.37 * delegates to this map's size method and the
27.07/10.37 * contains method delegates to this map's
27.07/10.37 * containsKey method.
27.07/10.37 *
27.07/10.37 * The set is created the first time this method is called,
27.07/10.37 * and returned in response to all subsequent calls. No synchronization
27.07/10.37 * is performed, so there is a slight chance that multiple calls to this
27.07/10.37 * method will not all return the same set.
27.07/10.37 */
27.07/10.37 public Set This implementation returns a collection that subclasses {@link
27.07/10.37 * AbstractCollection}. The subclass's iterator method returns a
27.07/10.37 * "wrapper object" over this map's entrySet() iterator.
27.07/10.37 * The size method delegates to this map's size
27.07/10.37 * method and the contains method delegates to this map's
27.07/10.37 * containsValue method.
27.07/10.37 *
27.07/10.37 * The collection is created the first time this method is called, and
27.07/10.37 * returned in response to all subsequent calls. No synchronization is
27.07/10.37 * performed, so there is a slight chance that multiple calls to this
27.07/10.37 * method will not all return the same collection.
27.07/10.37 */
27.07/10.37 public Collection This implementation first checks if the specified object is this map;
27.07/10.37 * if so it returns true. Then, it checks if the specified
27.07/10.37 * object is a map whose size is identical to the size of this map; if
27.07/10.37 * not, it returns false. If so, it iterates over this map's
27.07/10.37 * entrySet collection, and checks that the specified map
27.07/10.37 * contains each mapping that this map contains. If the specified map
27.07/10.37 * fails to contain such a mapping, false is returned. If the
27.07/10.37 * iteration completes, true is returned.
27.07/10.37 *
27.07/10.37 * @param o object to be compared for equality with this map
27.07/10.37 * @return true if the specified object is equal to this map
27.07/10.37 */
27.07/10.37 public boolean equals(Object o) {
27.07/10.37 if (o == this)
27.07/10.37 return true;
27.07/10.37
27.07/10.37 if (!(o instanceof Map))
27.07/10.37 return false;
27.07/10.37 Map This implementation iterates over entrySet(), calling
27.07/10.37 * {@link Map.Entry#hashCode hashCode()} on each element (entry) in the
27.07/10.37 * set, and adding up the results.
27.07/10.37 *
27.07/10.37 * @return the hash code value for this map
27.07/10.37 * @see Map.Entry#hashCode()
27.07/10.37 * @see Object#equals(Object)
27.07/10.37 * @see Set#equals(Object)
27.07/10.38 */
27.07/10.38 public int hashCode() {
27.07/10.38 int h = 0;
27.07/10.38 Iterator
27.07/10.38 *
27.07/10.38 * The process of implementing a set by extending this class is identical
27.07/10.38 * to that of implementing a Collection by extending AbstractCollection,
27.07/10.38 * except that all of the methods and constructors in subclasses of this
27.07/10.38 * class must obey the additional constraints imposed by the Set
27.07/10.38 * interface (for instance, the add method must not permit addition of
27.07/10.38 * multiple instances of an object to a set).
27.07/10.38 *
27.07/10.38 * Note that this class does not override any of the implementations from
27.07/10.38 * the AbstractCollection class. It merely adds implementations
27.07/10.38 * for equals and hashCode.
27.07/10.38 *
27.07/10.38 * This class is a member of the
27.07/10.38 *
27.07/10.38 * Java Collections Framework.
27.07/10.38 *
27.07/10.38 * @param
27.07/10.38 *
27.07/10.38 * This implementation first checks if the specified object is this
27.07/10.38 * set; if so it returns true. Then, it checks if the
27.07/10.38 * specified object is a set whose size is identical to the size of
27.07/10.38 * this set; if not, it returns false. If so, it returns
27.07/10.38 * containsAll((Collection) o).
27.07/10.38 *
27.07/10.38 * @param o object to be compared for equality with this set
27.07/10.38 * @return true if the specified object is equal to this set
27.07/10.38 */
27.07/10.38 public boolean equals(Object o) {
27.07/10.38 if (o == this)
27.07/10.38 return true;
27.07/10.38
27.07/10.38 if (!(o instanceof Set))
27.07/10.38 return false;
27.07/10.38 Collection c = (Collection) o;
27.07/10.38 if (c.size() != size())
27.07/10.38 return false;
27.07/10.38 try {
27.07/10.38 return containsAll(c);
27.07/10.38 } catch (ClassCastException unused) {
27.07/10.38 return false;
27.07/10.38 } catch (NullPointerException unused) {
27.07/10.38 return false;
27.07/10.38 }
27.07/10.38 }
27.07/10.38
27.07/10.38 /**
27.07/10.38 * Returns the hash code value for this set. The hash code of a set is
27.07/10.38 * defined to be the sum of the hash codes of the elements in the set,
27.07/10.38 * where the hash code of a null element is defined to be zero.
27.07/10.38 * This ensures that s1.equals(s2) implies that
27.07/10.38 * s1.hashCode()==s2.hashCode() for any two sets s1
27.07/10.38 * and s2, as required by the general contract of
27.07/10.38 * {@link Object#hashCode}.
27.07/10.38 *
27.07/10.38 * This implementation iterates over the set, calling the
27.07/10.38 * hashCode method on each element in the set, and adding up
27.07/10.38 * the results.
27.07/10.38 *
27.07/10.38 * @return the hash code value for this set
27.07/10.38 * @see Object#equals(Object)
27.07/10.38 * @see Set#equals(Object)
27.07/10.38 */
27.07/10.38 public int hashCode() {
27.07/10.38 int h = 0;
27.07/10.38 Iterator This implementation determines which is the smaller of this set
27.07/10.38 * and the specified collection, by invoking the size
27.07/10.38 * method on each. If this set has fewer elements, then the
27.07/10.38 * implementation iterates over this set, checking each element
27.07/10.38 * returned by the iterator in turn to see if it is contained in
27.07/10.38 * the specified collection. If it is so contained, it is removed
27.07/10.38 * from this set with the iterator's remove method. If
27.07/10.38 * the specified collection has fewer elements, then the
27.07/10.38 * implementation iterates over the specified collection, removing
27.07/10.38 * from this set each element returned by the iterator, using this
27.07/10.38 * set's remove method.
27.07/10.38 *
27.07/10.38 * Note that this implementation will throw an
27.07/10.38 * UnsupportedOperationException if the iterator returned by the
27.07/10.38 * iterator method does not implement the remove method.
27.07/10.38 *
27.07/10.38 * @param c collection containing elements to be removed from this set
27.07/10.38 * @return true if this set changed as a result of the call
27.07/10.38 * @throws UnsupportedOperationException if the removeAll operation
27.07/10.38 * is not supported by this set
27.07/10.38 * @throws ClassCastException if the class of an element of this set
27.07/10.38 * is incompatible with the specified collection (optional)
27.07/10.38 * @throws NullPointerException if this set contains a null element and the
27.07/10.38 * specified collection does not permit null elements (optional),
27.07/10.38 * or if the specified collection is null
27.07/10.38 * @see #remove(Object)
27.07/10.38 * @see #contains(Object)
27.07/10.38 */
27.07/10.38 public boolean removeAll(Collection> c) {
27.07/10.38 boolean modified = false;
27.07/10.38
27.07/10.38 if (size() > c.size()) {
27.07/10.38 for (Iterator> i = c.iterator(); i.hasNext(); )
27.07/10.38 modified |= remove(i.next());
27.07/10.38 } else {
27.07/10.38 for (Iterator> i = iterator(); i.hasNext(); ) {
27.07/10.38 if (c.contains(i.next())) {
27.07/10.38 i.remove();
27.07/10.38 modified = true;
27.07/10.38 }
27.07/10.38 }
27.07/10.38 }
27.07/10.38 return modified;
27.07/10.38 }
27.07/10.38
27.07/10.38 }
27.07/10.38
27.07/10.38
27.07/10.38 /*
27.07/10.38 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
27.07/10.38 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.07/10.38 *
27.07/10.38 * This code is free software; you can redistribute it and/or modify it
27.07/10.38 * under the terms of the GNU General Public License version 2 only, as
27.07/10.38 * published by the Free Software Foundation. Sun designates this
27.07/10.38 * particular file as subject to the "Classpath" exception as provided
27.07/10.38 * by Sun in the LICENSE file that accompanied this code.
27.07/10.38 *
27.07/10.38 * This code is distributed in the hope that it will be useful, but WITHOUT
27.07/10.38 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.07/10.38 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.07/10.38 * version 2 for more details (a copy is included in the LICENSE file that
27.07/10.38 * accompanied this code).
27.07/10.38 *
27.07/10.38 * You should have received a copy of the GNU General Public License version
27.07/10.38 * 2 along with this work; if not, write to the Free Software Foundation,
27.07/10.38 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.07/10.38 *
27.07/10.38 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27.07/10.38 * CA 95054 USA or visit www.sun.com if you need additional information or
27.07/10.38 * have any questions.
27.07/10.38 */
27.07/10.38
27.07/10.38 package javaUtilEx;
27.07/10.38
27.07/10.38 /**
27.07/10.38 * The root interface in the collection hierarchy. A collection
27.07/10.38 * represents a group of objects, known as its elements. Some
27.07/10.38 * collections allow duplicate elements and others do not. Some are ordered
27.07/10.38 * and others unordered. The JDK does not provide any direct
27.07/10.38 * implementations of this interface: it provides implementations of more
27.07/10.38 * specific subinterfaces like Set and List. This interface
27.07/10.38 * is typically used to pass collections around and manipulate them where
27.07/10.38 * maximum generality is desired.
27.07/10.38 *
27.07/10.38 * Bags or multisets (unordered collections that may contain
27.07/10.38 * duplicate elements) should implement this interface directly.
27.07/10.38 *
27.07/10.38 * All general-purpose Collection implementation classes (which
27.07/10.38 * typically implement Collection indirectly through one of its
27.07/10.38 * subinterfaces) should provide two "standard" constructors: a void (no
27.07/10.38 * arguments) constructor, which creates an empty collection, and a
27.07/10.38 * constructor with a single argument of type Collection, which
27.07/10.38 * creates a new collection with the same elements as its argument. In
27.07/10.38 * effect, the latter constructor allows the user to copy any collection,
27.07/10.38 * producing an equivalent collection of the desired implementation type.
27.07/10.38 * There is no way to enforce this convention (as interfaces cannot contain
27.07/10.38 * constructors) but all of the general-purpose Collection
27.07/10.38 * implementations in the Java platform libraries comply.
27.07/10.38 *
27.07/10.38 * The "destructive" methods contained in this interface, that is, the
27.07/10.38 * methods that modify the collection on which they operate, are specified to
27.07/10.38 * throw UnsupportedOperationException if this collection does not
27.07/10.38 * support the operation. If this is the case, these methods may, but are not
27.07/10.38 * required to, throw an UnsupportedOperationException if the
27.07/10.38 * invocation would have no effect on the collection. For example, invoking
27.07/10.38 * the {@link #addAll(Collection)} method on an unmodifiable collection may,
27.07/10.38 * but is not required to, throw the exception if the collection to be added
27.07/10.38 * is empty.
27.07/10.38 *
27.07/10.38 * Some collection implementations have restrictions on the elements that
27.07/10.38 * they may contain. For example, some implementations prohibit null elements,
27.07/10.38 * and some have restrictions on the types of their elements. Attempting to
27.07/10.38 * add an ineligible element throws an unchecked exception, typically
27.07/10.38 * NullPointerException or ClassCastException. Attempting
27.07/10.38 * to query the presence of an ineligible element may throw an exception,
27.07/10.38 * or it may simply return false; some implementations will exhibit the former
27.07/10.38 * behavior and some will exhibit the latter. More generally, attempting an
27.07/10.38 * operation on an ineligible element whose completion would not result in
27.07/10.38 * the insertion of an ineligible element into the collection may throw an
27.07/10.38 * exception or it may succeed, at the option of the implementation.
27.07/10.38 * Such exceptions are marked as "optional" in the specification for this
27.07/10.38 * interface.
27.07/10.38 *
27.07/10.38 * It is up to each collection to determine its own synchronization
27.07/10.38 * policy. In the absence of a stronger guarantee by the
27.07/10.38 * implementation, undefined behavior may result from the invocation
27.07/10.38 * of any method on a collection that is being mutated by another
27.07/10.38 * thread; this includes direct invocations, passing the collection to
27.07/10.38 * a method that might perform invocations, and using an existing
27.07/10.38 * iterator to examine the collection.
27.07/10.38 *
27.07/10.38 * Many methods in Collections Framework interfaces are defined in
27.07/10.38 * terms of the {@link Object#equals(Object) equals} method. For example,
27.07/10.38 * the specification for the {@link #contains(Object) contains(Object o)}
27.07/10.38 * method says: "returns true if and only if this collection
27.07/10.38 * contains at least one element e such that
27.07/10.38 * (o==null ? e==null : o.equals(e))." This specification should
27.07/10.38 * not be construed to imply that invoking Collection.contains
27.07/10.38 * with a non-null argument o will cause o.equals(e) to be
27.07/10.38 * invoked for any element e. Implementations are free to implement
27.07/10.38 * optimizations whereby the equals invocation is avoided, for
27.07/10.38 * example, by first comparing the hash codes of the two elements. (The
27.07/10.38 * {@link Object#hashCode()} specification guarantees that two objects with
27.07/10.38 * unequal hash codes cannot be equal.) More generally, implementations of
27.07/10.38 * the various Collections Framework interfaces are free to take advantage of
27.07/10.38 * the specified behavior of underlying {@link Object} methods wherever the
27.07/10.38 * implementor deems it appropriate.
27.07/10.38 *
27.07/10.38 * This interface is a member of the
27.07/10.38 *
27.07/10.38 * Java Collections Framework.
27.07/10.38 *
27.07/10.38 * @author Josh Bloch
27.07/10.38 * @author Neal Gafter
27.07/10.38 * @see Set
27.07/10.38 * @see List
27.07/10.38 * @see Map
27.07/10.38 * @see SortedSet
27.07/10.38 * @see SortedMap
27.07/10.38 * @see HashSet
27.07/10.38 * @see TreeSet
27.07/10.38 * @see ArrayList
27.07/10.38 * @see LinkedList
27.07/10.38 * @see Vector
27.07/10.38 * @see Collections
27.07/10.38 * @see Arrays
27.07/10.38 * @see AbstractCollection
27.07/10.38 * @since 1.2
27.07/10.38 */
27.07/10.38
27.07/10.38 public interface Collection
27.07/10.38 *
27.07/10.38 * Collections that support this operation may place limitations on what
27.07/10.38 * elements may be added to this collection. In particular, some
27.07/10.38 * collections will refuse to add
27.07/10.35 * (e1.getKey()==null ?
27.07/10.35 * e2.getKey()==null :
27.07/10.35 * e1.getKey().equals(e2.getKey()))
27.07/10.35 * &&
27.07/10.35 * (e1.getValue()==null ?
27.07/10.35 * e2.getValue()==null :
27.07/10.35 * e1.getValue().equals(e2.getValue()))
27.07/10.35 * This ensures that the {@code equals} method works properly across
27.07/10.35 * different implementations of the {@code Map.Entry} interface.
27.07/10.35 *
27.07/10.35 * @param o object to be compared for equality with this map entry
27.07/10.35 * @return {@code true} if the specified object is equal to this map
27.07/10.35 * entry
27.07/10.35 * @see #hashCode
27.07/10.35 */
27.07/10.35 public boolean equals(Object o) {
27.07/10.35 if (!(o instanceof Map.Entry))
27.07/10.35 return false;
27.07/10.35 Map.Entry e = (Map.Entry)o;
27.07/10.35 return eq(key, e.getKey()) && eq(value, e.getValue());
27.07/10.35 }
27.07/10.35
27.07/10.35 /**
27.07/10.35 * Returns the hash code value for this map entry. The hash code
27.07/10.35 * of a map entry {@code e} is defined to be:
27.07/10.35 * (e.getKey()==null ? 0 : e.getKey().hashCode()) ^
27.07/10.35 * (e.getValue()==null ? 0 : e.getValue().hashCode())
27.07/10.35 * This ensures that {@code e1.equals(e2)} implies that
27.07/10.35 * {@code e1.hashCode()==e2.hashCode()} for any two Entries
27.07/10.35 * {@code e1} and {@code e2}, as required by the general
27.07/10.35 * contract of {@link Object#hashCode}.
27.07/10.35 *
27.07/10.35 * @return the hash code value for this map entry
27.07/10.35 * @see #equals
27.07/10.35 */
27.07/10.35 public int hashCode() {
27.07/10.35 return (key == null ? 0 : key.hashCode()) ^
27.07/10.35 (value == null ? 0 : value.hashCode());
27.07/10.35 }
27.07/10.35
27.07/10.35 /**
27.07/10.35 * Returns a String representation of this map entry. This
27.07/10.35 * implementation returns the string representation of this
27.07/10.35 * entry's key followed by the equals character ("=")
27.07/10.35 * followed by the string representation of this entry's value.
27.07/10.35 *
27.07/10.35 * @return a String representation of this map entry
27.07/10.35 */
27.07/10.35 public String toString() {
27.07/10.35 return key + "=" + value;
27.07/10.35 }
27.07/10.35
27.07/10.35 }
27.07/10.35
27.07/10.35 /**
27.07/10.35 * An Entry maintaining an immutable key and value. This class
27.07/10.35 * does not support method setValue. This class may be
27.07/10.35 * convenient in methods that return thread-safe snapshots of
27.07/10.35 * key-value mappings.
27.07/10.35 *
27.07/10.35 * @since 1.6
27.07/10.35 */
27.07/10.35 public static class SimpleImmutableEntry
27.07/10.35 * (e1.getKey()==null ?
27.07/10.35 * e2.getKey()==null :
27.07/10.35 * e1.getKey().equals(e2.getKey()))
27.07/10.35 * &&
27.07/10.35 * (e1.getValue()==null ?
27.07/10.35 * e2.getValue()==null :
27.07/10.35 * e1.getValue().equals(e2.getValue()))
27.07/10.35 * This ensures that the {@code equals} method works properly across
27.07/10.35 * different implementations of the {@code Map.Entry} interface.
27.07/10.35 *
27.07/10.35 * @param o object to be compared for equality with this map entry
27.07/10.35 * @return {@code true} if the specified object is equal to this map
27.07/10.35 * entry
27.07/10.35 * @see #hashCode
27.07/10.35 */
27.07/10.35 public boolean equals(Object o) {
27.07/10.35 if (!(o instanceof Map.Entry))
27.07/10.35 return false;
27.07/10.35 Map.Entry e = (Map.Entry)o;
27.07/10.35 return eq(key, e.getKey()) && eq(value, e.getValue());
27.07/10.35 }
27.07/10.35
27.07/10.35 /**
27.07/10.35 * Returns the hash code value for this map entry. The hash code
27.07/10.35 * of a map entry {@code e} is defined to be:
27.07/10.35 * (e.getKey()==null ? 0 : e.getKey().hashCode()) ^
27.07/10.35 * (e.getValue()==null ? 0 : e.getValue().hashCode())
27.07/10.35 * This ensures that {@code e1.equals(e2)} implies that
27.07/10.35 * {@code e1.hashCode()==e2.hashCode()} for any two Entries
27.07/10.35 * {@code e1} and {@code e2}, as required by the general
27.07/10.35 * contract of {@link Object#hashCode}.
27.07/10.35 *
27.07/10.35 * @return the hash code value for this map entry
27.07/10.35 * @see #equals
27.07/10.35 */
27.07/10.35 public int hashCode() {
27.07/10.35 return (key == null ? 0 : key.hashCode()) ^
27.07/10.35 (value == null ? 0 : value.hashCode());
27.07/10.36 }
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Returns a String representation of this map entry. This
27.07/10.36 * implementation returns the string representation of this
27.07/10.36 * entry's key followed by the equals character ("=")
27.07/10.36 * followed by the string representation of this entry's value.
27.07/10.36 *
27.07/10.36 * @return a String representation of this map entry
27.07/10.36 */
27.07/10.36 public String toString() {
27.07/10.36 return key + "=" + value;
27.07/10.36 }
27.07/10.36
27.07/10.36 }
27.07/10.36
27.07/10.36 }
27.07/10.36
27.07/10.36
27.07/10.36 /*
27.07/10.36 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
27.07/10.36 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.07/10.36 *
27.07/10.36 * This code is free software; you can redistribute it and/or modify it
27.07/10.36 * under the terms of the GNU General Public License version 2 only, as
27.07/10.36 * published by the Free Software Foundation. Sun designates this
27.07/10.36 * particular file as subject to the "Classpath" exception as provided
27.07/10.36 * by Sun in the LICENSE file that accompanied this code.
27.07/10.36 *
27.07/10.36 * This code is distributed in the hope that it will be useful, but WITHOUT
27.07/10.36 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.07/10.36 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.07/10.36 * version 2 for more details (a copy is included in the LICENSE file that
27.07/10.36 * accompanied this code).
27.07/10.36 *
27.07/10.36 * You should have received a copy of the GNU General Public License version
27.07/10.36 * 2 along with this work; if not, write to the Free Software Foundation,
27.07/10.36 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.07/10.36 *
27.07/10.36 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27.07/10.36 * CA 95054 USA or visit www.sun.com if you need additional information or
27.07/10.36 * have any questions.
27.07/10.36 */
27.07/10.36
27.07/10.36 package javaUtilEx;
27.07/10.36
27.07/10.36 /**
27.07/10.36 * This class provides a skeletal implementation of the Set
27.07/10.36 * interface to minimize the effort required to implement this
27.07/10.36 * interface.
27.07/10.36 * Map m = Collections.synchronizedMap(new HashMap(...));
27.07/10.36 *
27.07/10.36 * IllegalArgumentException
with no
27.07/10.36 * detail message.
27.07/10.36 */
27.07/10.36 public IllegalArgumentException() {
27.07/10.36 super();
27.07/10.36 }
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Constructs an IllegalArgumentException
with the
27.07/10.36 * specified detail message.
27.07/10.36 *
27.07/10.36 * @param s the detail message.
27.07/10.36 */
27.07/10.36 public IllegalArgumentException(String s) {
27.07/10.36 super(s);
27.07/10.36 }
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Constructs a new exception with the specified detail message and
27.07/10.36 * cause.
27.07/10.36 *
27.07/10.36 * cause
is
27.07/10.36 * not automatically incorporated in this exception's detail
27.07/10.36 * message.
27.07/10.36 *
27.07/10.36 * @param message the detail message (which is saved for later retrieval
27.07/10.36 * by the {@link Throwable#getMessage()} method).
27.07/10.36 * @param cause the cause (which is saved for later retrieval by the
27.07/10.36 * {@link Throwable#getCause()} method). (A null value
27.07/10.36 * is permitted, and indicates that the cause is nonexistent or
27.07/10.36 * unknown.)
27.07/10.36 * @since 1.5
27.07/10.36 */
27.07/10.36 public IllegalArgumentException(String message, Throwable cause) {
27.07/10.36 super(message, cause);
27.07/10.36 }
27.07/10.36
27.07/10.36 /**
27.07/10.36 * Constructs a new exception with the specified cause and a detail
27.07/10.36 * message of (cause==null ? null : cause.toString()) (which
27.07/10.36 * typically contains the class and detail message of cause).
27.07/10.36 * This constructor is useful for exceptions that are little more than
27.07/10.36 * wrappers for other throwables (for example, {@link
27.07/10.36 * java.security.PrivilegedActionException}).
27.07/10.36 *
27.07/10.36 * @param cause the cause (which is saved for later retrieval by the
27.07/10.36 * {@link Throwable#getCause()} method). (A null value is
27.07/10.37 * permitted, and indicates that the cause is nonexistent or
27.07/10.37 * unknown.)
27.07/10.37 * @since 1.5
27.07/10.37 */
27.07/10.37 public IllegalArgumentException(Throwable cause) {
27.07/10.37 super(cause);
27.07/10.37 }
27.07/10.37
27.07/10.37 private static final long serialVersionUID = -5365630128856068164L;
27.07/10.37 }
27.07/10.37
27.07/10.37
27.07/10.37 /*
27.07/10.37 * Copyright 1996-2003 Sun Microsystems, Inc. All Rights Reserved.
27.07/10.37 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.07/10.37 *
27.07/10.37 * This code is free software; you can redistribute it and/or modify it
27.07/10.37 * under the terms of the GNU General Public License version 2 only, as
27.07/10.37 * published by the Free Software Foundation. Sun designates this
27.07/10.37 * particular file as subject to the "Classpath" exception as provided
27.07/10.37 * by Sun in the LICENSE file that accompanied this code.
27.07/10.37 *
27.07/10.37 * This code is distributed in the hope that it will be useful, but WITHOUT
27.07/10.37 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.07/10.37 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.07/10.37 * version 2 for more details (a copy is included in the LICENSE file that
27.07/10.37 * accompanied this code).
27.07/10.37 *
27.07/10.37 * You should have received a copy of the GNU General Public License version
27.07/10.37 * 2 along with this work; if not, write to the Free Software Foundation,
27.07/10.37 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.07/10.37 *
27.07/10.37 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27.07/10.37 * CA 95054 USA or visit www.sun.com if you need additional information or
27.07/10.37 * have any questions.
27.07/10.37 */
27.07/10.37
27.07/10.37 package javaUtilEx;
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Signals that a method has been invoked at an illegal or
27.07/10.37 * inappropriate time. In other words, the Java environment or
27.07/10.37 * Java application is not in an appropriate state for the requested
27.07/10.37 * operation.
27.07/10.37 *
27.07/10.37 * @author Jonni Kanerva
27.07/10.37 * @since JDK1.1
27.07/10.37 */
27.07/10.37 public
27.07/10.37 class IllegalStateException extends RuntimeException {
27.07/10.37 /**
27.07/10.37 * Constructs an IllegalStateException with no detail message.
27.07/10.37 * A detail message is a String that describes this particular exception.
27.07/10.37 */
27.07/10.37 public IllegalStateException() {
27.07/10.37 super();
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Constructs an IllegalStateException with the specified detail
27.07/10.37 * message. A detail message is a String that describes this particular
27.07/10.37 * exception.
27.07/10.37 *
27.07/10.37 * @param s the String that contains a detailed message
27.07/10.37 */
27.07/10.37 public IllegalStateException(String s) {
27.07/10.37 super(s);
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Constructs a new exception with the specified detail message and
27.07/10.37 * cause.
27.07/10.37 *
27.07/10.37 * cause
is
27.07/10.37 * not automatically incorporated in this exception's detail
27.07/10.37 * message.
27.07/10.37 *
27.07/10.37 * @param message the detail message (which is saved for later retrieval
27.07/10.37 * by the {@link Throwable#getMessage()} method).
27.07/10.37 * @param cause the cause (which is saved for later retrieval by the
27.07/10.37 * {@link Throwable#getCause()} method). (A null value
27.07/10.37 * is permitted, and indicates that the cause is nonexistent or
27.07/10.37 * unknown.)
27.07/10.37 * @since 1.5
27.07/10.37 */
27.07/10.37 public IllegalStateException(String message, Throwable cause) {
27.07/10.37 super(message, cause);
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Constructs a new exception with the specified cause and a detail
27.07/10.37 * message of (cause==null ? null : cause.toString()) (which
27.07/10.37 * typically contains the class and detail message of cause).
27.07/10.37 * This constructor is useful for exceptions that are little more than
27.07/10.37 * wrappers for other throwables (for example, {@link
27.07/10.37 * java.security.PrivilegedActionException}).
27.07/10.37 *
27.07/10.37 * @param cause the cause (which is saved for later retrieval by the
27.07/10.37 * {@link Throwable#getCause()} method). (A null value is
27.07/10.37 * permitted, and indicates that the cause is nonexistent or
27.07/10.37 * unknown.)
27.07/10.37 * @since 1.5
27.07/10.37 */
27.07/10.37 public IllegalStateException(Throwable cause) {
27.07/10.37 super(cause);
27.07/10.37 }
27.07/10.37
27.07/10.37 static final long serialVersionUID = -1848914673093119416L;
27.07/10.37 }
27.07/10.37
27.07/10.37
27.07/10.37 /*
27.07/10.37 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
27.07/10.37 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.07/10.37 *
27.07/10.37 * This code is free software; you can redistribute it and/or modify it
27.07/10.37 * under the terms of the GNU General Public License version 2 only, as
27.07/10.37 * published by the Free Software Foundation. Sun designates this
27.07/10.37 * particular file as subject to the "Classpath" exception as provided
27.07/10.37 * by Sun in the LICENSE file that accompanied this code.
27.07/10.37 *
27.07/10.37 * This code is distributed in the hope that it will be useful, but WITHOUT
27.07/10.37 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.07/10.37 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.07/10.37 * version 2 for more details (a copy is included in the LICENSE file that
27.07/10.37 * accompanied this code).
27.07/10.37 *
27.07/10.37 * You should have received a copy of the GNU General Public License version
27.07/10.37 * 2 along with this work; if not, write to the Free Software Foundation,
27.07/10.37 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.07/10.37 *
27.07/10.37 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27.07/10.37 * CA 95054 USA or visit www.sun.com if you need additional information or
27.07/10.37 * have any questions.
27.07/10.37 */
27.07/10.37
27.07/10.37 package javaUtilEx;
27.07/10.37
27.07/10.37 /**
27.07/10.37 * An iterator over a collection. {@code Iterator} takes the place of
27.07/10.37 * {@link Enumeration} in the Java Collections Framework. Iterators
27.07/10.37 * differ from enumerations in two ways:
27.07/10.37 *
27.07/10.37 *
27.07/10.37 *
27.07/10.37 *
27.07/10.37 * (key==null ? k==null : key.equals(k))
, that mapping
27.07/10.37 * is removed. (The map can contain at most one such mapping.)
27.07/10.37 *
27.07/10.37 *
27.07/10.37 * (e1.getKey()==null ?
27.07/10.37 * e2.getKey()==null : e1.getKey().equals(e2.getKey())) &&
27.07/10.37 * (e1.getValue()==null ?
27.07/10.37 * e2.getValue()==null : e1.getValue().equals(e2.getValue()))
27.07/10.37 *
27.07/10.37 * This ensures that the equals method works properly across
27.07/10.37 * different implementations of the Map.Entry interface.
27.07/10.37 *
27.07/10.37 * @param o object to be compared for equality with this map entry
27.07/10.37 * @return true if the specified object is equal to this map
27.07/10.37 * entry
27.07/10.37 */
27.07/10.37 boolean equals(Object o);
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Returns the hash code value for this map entry. The hash code
27.07/10.37 * of a map entry e is defined to be:
27.07/10.37 * (e.getKey()==null ? 0 : e.getKey().hashCode()) ^
27.07/10.37 * (e.getValue()==null ? 0 : e.getValue().hashCode())
27.07/10.37 *
27.07/10.37 * This ensures that e1.equals(e2) implies that
27.07/10.37 * e1.hashCode()==e2.hashCode() for any two Entries
27.07/10.37 * e1 and e2, as required by the general
27.07/10.37 * contract of Object.hashCode.
27.07/10.37 *
27.07/10.37 * @return the hash code value for this map entry
27.07/10.37 * @see Object#hashCode()
27.07/10.37 * @see Object#equals(Object)
27.07/10.37 * @see #equals(Object)
27.07/10.37 */
27.07/10.37 int hashCode();
27.07/10.37 }
27.07/10.37
27.07/10.37 // Comparison and hashing
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Compares the specified object with this map for equality. Returns
27.07/10.37 * true if the given object is also a map and the two maps
27.07/10.37 * represent the same mappings. More formally, two maps m1 and
27.07/10.37 * m2 represent the same mappings if
27.07/10.37 * m1.entrySet().equals(m2.entrySet()). This ensures that the
27.07/10.37 * equals method works properly across different implementations
27.07/10.37 * of the Map interface.
27.07/10.37 *
27.07/10.37 * @param o object to be compared for equality with this map
27.07/10.37 * @return true if the specified object is equal to this map
27.07/10.37 */
27.07/10.37 boolean equals(Object o);
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Returns the hash code value for this map. The hash code of a map is
27.07/10.37 * defined to be the sum of the hash codes of each entry in the map's
27.07/10.37 * entrySet() view. This ensures that m1.equals(m2)
27.07/10.37 * implies that m1.hashCode()==m2.hashCode() for any two maps
27.07/10.37 * m1 and m2, as required by the general contract of
27.07/10.37 * {@link Object#hashCode}.
27.07/10.37 *
27.07/10.37 * @return the hash code value for this map
27.07/10.37 * @see Map.Entry#hashCode()
27.07/10.37 * @see Object#equals(Object)
27.07/10.37 * @see #equals(Object)
27.07/10.37 */
27.07/10.37 int hashCode();
27.07/10.37 }
27.07/10.37
27.07/10.37
27.07/10.37 /*
27.07/10.37 * Copyright 1994-1998 Sun Microsystems, Inc. All Rights Reserved.
27.07/10.37 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.07/10.37 *
27.07/10.37 * This code is free software; you can redistribute it and/or modify it
27.07/10.37 * under the terms of the GNU General Public License version 2 only, as
27.07/10.37 * published by the Free Software Foundation. Sun designates this
27.07/10.37 * particular file as subject to the "Classpath" exception as provided
27.07/10.37 * by Sun in the LICENSE file that accompanied this code.
27.07/10.37 *
27.07/10.37 * This code is distributed in the hope that it will be useful, but WITHOUT
27.07/10.37 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.07/10.37 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.07/10.37 * version 2 for more details (a copy is included in the LICENSE file that
27.07/10.37 * accompanied this code).
27.07/10.37 *
27.07/10.37 * You should have received a copy of the GNU General Public License version
27.07/10.37 * 2 along with this work; if not, write to the Free Software Foundation,
27.07/10.37 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.07/10.37 *
27.07/10.37 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27.07/10.37 * CA 95054 USA or visit www.sun.com if you need additional information or
27.07/10.37 * have any questions.
27.07/10.37 */
27.07/10.37
27.07/10.37 package javaUtilEx;
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Thrown by the nextElement
method of an
27.07/10.37 * Enumeration
to indicate that there are no more
27.07/10.37 * elements in the enumeration.
27.07/10.37 *
27.07/10.37 * @author unascribed
27.07/10.37 * @see java.util.Enumeration
27.07/10.37 * @see java.util.Enumeration#nextElement()
27.07/10.37 * @since JDK1.0
27.07/10.37 */
27.07/10.37 public
27.07/10.37 class NoSuchElementException extends RuntimeException {
27.07/10.37 /**
27.07/10.37 * Constructs a NoSuchElementException
with null
27.07/10.37 * as its error message string.
27.07/10.37 */
27.07/10.37 public NoSuchElementException() {
27.07/10.37 super();
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Constructs a NoSuchElementException
, saving a reference
27.07/10.37 * to the error message string s for later retrieval by the
27.07/10.37 * getMessage method.
27.07/10.37 *
27.07/10.37 * @param s the detail message.
27.07/10.37 */
27.07/10.37 public NoSuchElementException(String s) {
27.07/10.37 super(s);
27.07/10.37 }
27.07/10.37 }
27.07/10.37
27.07/10.37
27.07/10.37 package javaUtilEx;
27.07/10.37
27.07/10.37 public class Random {
27.07/10.37 static String[] args;
27.07/10.37 static int index = 0;
27.07/10.37
27.07/10.37 public static int random() {
27.07/10.37 String string = args[index];
27.07/10.37 index++;
27.07/10.37 return string.length();
27.07/10.37 }
27.07/10.37 }
27.07/10.37
27.07/10.37
27.07/10.37 /*
27.07/10.37 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
27.07/10.37 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.07/10.37 *
27.07/10.37 * This code is free software; you can redistribute it and/or modify it
27.07/10.37 * under the terms of the GNU General Public License version 2 only, as
27.07/10.37 * published by the Free Software Foundation. Sun designates this
27.07/10.37 * particular file as subject to the "Classpath" exception as provided
27.07/10.37 * by Sun in the LICENSE file that accompanied this code.
27.07/10.37 *
27.07/10.37 * This code is distributed in the hope that it will be useful, but WITHOUT
27.07/10.37 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.07/10.37 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.07/10.37 * version 2 for more details (a copy is included in the LICENSE file that
27.07/10.37 * accompanied this code).
27.07/10.37 *
27.07/10.37 * You should have received a copy of the GNU General Public License version
27.07/10.37 * 2 along with this work; if not, write to the Free Software Foundation,
27.07/10.37 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.07/10.37 *
27.07/10.37 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27.07/10.37 * CA 95054 USA or visit www.sun.com if you need additional information or
27.07/10.37 * have any questions.
27.07/10.37 */
27.07/10.37
27.07/10.37 package javaUtilEx;
27.07/10.37
27.07/10.37 /**
27.07/10.37 * A collection that contains no duplicate elements. More formally, sets
27.07/10.37 * contain no pair of elements e1
and e2
such that
27.07/10.37 * e1.equals(e2)
, and at most one null element. As implied by
27.07/10.37 * its name, this interface models the mathematical set abstraction.
27.07/10.37 *
27.07/10.37 *
27.07/10.37 * String[] y = x.toArray(new String[0]);
27.07/10.37 *
27.07/10.37 * Note that toArray(new Object[0]) is identical in function to
27.07/10.37 * toArray().
27.07/10.37 *
27.07/10.37 * @param a the array into which the elements of this set are to be
27.07/10.37 * stored, if it is big enough; otherwise, a new array of the same
27.07/10.37 * runtime type is allocated for this purpose.
27.07/10.37 * @return an array containing all the elements in this set
27.07/10.37 * @throws ArrayStoreException if the runtime type of the specified array
27.07/10.37 * is not a supertype of the runtime type of every element in this
27.07/10.37 * set
27.07/10.37 * @throws NullPointerException if the specified array is null
27.07/10.37 */
27.07/10.37 cause
is
27.07/10.37 * not automatically incorporated in this exception's detail
27.07/10.37 * message.
27.07/10.37 *
27.07/10.37 * @param message the detail message (which is saved for later retrieval
27.07/10.37 * by the {@link Throwable#getMessage()} method).
27.07/10.37 * @param cause the cause (which is saved for later retrieval by the
27.07/10.37 * {@link Throwable#getCause()} method). (A null value
27.07/10.37 * is permitted, and indicates that the cause is nonexistent or
27.07/10.37 * unknown.)
27.07/10.37 * @since 1.5
27.07/10.37 */
27.07/10.37 public UnsupportedOperationException(String message, Throwable cause) {
27.07/10.37 super(message, cause);
27.07/10.37 }
27.07/10.37
27.07/10.37 /**
27.07/10.37 * Constructs a new exception with the specified cause and a detail
27.07/10.37 * message of (cause==null ? null : cause.toString()) (which
27.07/10.37 * typically contains the class and detail message of cause).
27.07/10.37 * This constructor is useful for exceptions that are little more than
27.07/10.37 * wrappers for other throwables (for example, {@link
27.07/10.37 * java.security.PrivilegedActionException}).
27.07/10.37 *
27.07/10.37 * @param cause the cause (which is saved for later retrieval by the
27.07/10.37 * {@link Throwable#getCause()} method). (A null value is
27.07/10.37 * permitted, and indicates that the cause is nonexistent or
27.07/10.37 * unknown.)
27.07/10.37 * @since 1.5
27.07/10.37 */
27.07/10.37 public UnsupportedOperationException(Throwable cause) {
27.07/10.37 super(cause);
27.07/10.37 }
27.07/10.37
27.07/10.37 static final long serialVersionUID = -1242599979055084673L;
27.07/10.37 }
27.07/10.37
27.07/10.37
27.07/10.37
27.07/10.37 ----------------------------------------
27.07/10.37
27.07/10.37 (1) BareJBCToJBCProof (EQUIVALENT)
27.07/10.37 initialized classpath
27.07/10.37 ----------------------------------------
27.07/10.37
27.07/10.37 (2)
27.07/10.37 Obligation:
27.07/10.37 need to prove termination of the following program:
27.07/10.37 /*
27.07/10.37 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
27.07/10.37 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.07/10.37 *
27.07/10.37 * This code is free software; you can redistribute it and/or modify it
27.07/10.37 * under the terms of the GNU General Public License version 2 only, as
27.07/10.37 * published by the Free Software Foundation. Sun designates this
27.07/10.37 * particular file as subject to the "Classpath" exception as provided
27.07/10.37 * by Sun in the LICENSE file that accompanied this code.
27.07/10.37 *
27.07/10.37 * This code is distributed in the hope that it will be useful, but WITHOUT
27.07/10.37 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.07/10.37 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.07/10.37 * version 2 for more details (a copy is included in the LICENSE file that
27.07/10.37 * accompanied this code).
27.07/10.37 *
27.07/10.37 * You should have received a copy of the GNU General Public License version
27.07/10.37 * 2 along with this work; if not, write to the Free Software Foundation,
27.07/10.37 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.07/10.37 *
27.07/10.37 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27.07/10.37 * CA 95054 USA or visit www.sun.com if you need additional information or
27.07/10.37 * have any questions.
27.07/10.37 */
27.07/10.37
27.07/10.37 package javaUtilEx;
27.07/10.37
27.07/10.37 /**
27.07/10.37 * This class provides a skeletal implementation of the Collection
27.07/10.37 * interface, to minimize the effort required to implement this interface.
27.07/10.38 * (e1.getKey()==null ?
27.07/10.38 * e2.getKey()==null :
27.07/10.38 * e1.getKey().equals(e2.getKey()))
27.07/10.38 * &&
27.07/10.38 * (e1.getValue()==null ?
27.07/10.38 * e2.getValue()==null :
27.07/10.38 * e1.getValue().equals(e2.getValue()))
27.07/10.38 * This ensures that the {@code equals} method works properly across
27.07/10.38 * different implementations of the {@code Map.Entry} interface.
27.07/10.38 *
27.07/10.38 * @param o object to be compared for equality with this map entry
27.07/10.38 * @return {@code true} if the specified object is equal to this map
27.07/10.38 * entry
27.07/10.38 * @see #hashCode
27.07/10.38 */
27.07/10.38 public boolean equals(Object o) {
27.07/10.38 if (!(o instanceof Map.Entry))
27.07/10.38 return false;
27.07/10.38 Map.Entry e = (Map.Entry)o;
27.07/10.38 return eq(key, e.getKey()) && eq(value, e.getValue());
27.07/10.38 }
27.07/10.38
27.07/10.38 /**
27.07/10.38 * Returns the hash code value for this map entry. The hash code
27.07/10.38 * of a map entry {@code e} is defined to be:
27.07/10.38 * (e.getKey()==null ? 0 : e.getKey().hashCode()) ^
27.07/10.38 * (e.getValue()==null ? 0 : e.getValue().hashCode())
27.07/10.38 * This ensures that {@code e1.equals(e2)} implies that
27.07/10.38 * {@code e1.hashCode()==e2.hashCode()} for any two Entries
27.07/10.38 * {@code e1} and {@code e2}, as required by the general
27.07/10.38 * contract of {@link Object#hashCode}.
27.07/10.38 *
27.07/10.38 * @return the hash code value for this map entry
27.07/10.38 * @see #equals
27.07/10.38 */
27.07/10.38 public int hashCode() {
27.07/10.38 return (key == null ? 0 : key.hashCode()) ^
27.07/10.38 (value == null ? 0 : value.hashCode());
27.07/10.38 }
27.07/10.38
27.07/10.38 /**
27.07/10.38 * Returns a String representation of this map entry. This
27.07/10.38 * implementation returns the string representation of this
27.07/10.38 * entry's key followed by the equals character ("=")
27.07/10.38 * followed by the string representation of this entry's value.
27.07/10.38 *
27.07/10.38 * @return a String representation of this map entry
27.07/10.38 */
27.07/10.38 public String toString() {
27.07/10.38 return key + "=" + value;
27.07/10.38 }
27.07/10.38
27.07/10.38 }
27.07/10.38
27.07/10.38 /**
27.07/10.38 * An Entry maintaining an immutable key and value. This class
27.07/10.38 * does not support method setValue. This class may be
27.07/10.38 * convenient in methods that return thread-safe snapshots of
27.07/10.38 * key-value mappings.
27.07/10.38 *
27.07/10.38 * @since 1.6
27.07/10.38 */
27.07/10.38 public static class SimpleImmutableEntry
27.07/10.38 * (e1.getKey()==null ?
27.07/10.38 * e2.getKey()==null :
27.07/10.38 * e1.getKey().equals(e2.getKey()))
27.07/10.38 * &&
27.07/10.38 * (e1.getValue()==null ?
27.07/10.38 * e2.getValue()==null :
27.07/10.38 * e1.getValue().equals(e2.getValue()))
27.07/10.38 * This ensures that the {@code equals} method works properly across
27.07/10.38 * different implementations of the {@code Map.Entry} interface.
27.07/10.38 *
27.07/10.38 * @param o object to be compared for equality with this map entry
27.07/10.38 * @return {@code true} if the specified object is equal to this map
27.07/10.38 * entry
27.07/10.38 * @see #hashCode
27.07/10.38 */
27.07/10.38 public boolean equals(Object o) {
27.07/10.38 if (!(o instanceof Map.Entry))
27.07/10.38 return false;
27.07/10.38 Map.Entry e = (Map.Entry)o;
27.07/10.38 return eq(key, e.getKey()) && eq(value, e.getValue());
27.07/10.38 }
27.07/10.38
27.07/10.38 /**
27.07/10.38 * Returns the hash code value for this map entry. The hash code
27.07/10.38 * of a map entry {@code e} is defined to be:
27.07/10.38 * (e.getKey()==null ? 0 : e.getKey().hashCode()) ^
27.07/10.38 * (e.getValue()==null ? 0 : e.getValue().hashCode())
27.07/10.38 * This ensures that {@code e1.equals(e2)} implies that
27.07/10.38 * {@code e1.hashCode()==e2.hashCode()} for any two Entries
27.07/10.38 * {@code e1} and {@code e2}, as required by the general
27.07/10.38 * contract of {@link Object#hashCode}.
27.07/10.38 *
27.07/10.38 * @return the hash code value for this map entry
27.07/10.38 * @see #equals
27.07/10.38 */
27.07/10.38 public int hashCode() {
27.07/10.38 return (key == null ? 0 : key.hashCode()) ^
27.07/10.38 (value == null ? 0 : value.hashCode());
27.07/10.38 }
27.07/10.38
27.07/10.38 /**
27.07/10.38 * Returns a String representation of this map entry. This
27.07/10.38 * implementation returns the string representation of this
27.07/10.38 * entry's key followed by the equals character ("=")
27.07/10.38 * followed by the string representation of this entry's value.
27.07/10.38 *
27.07/10.38 * @return a String representation of this map entry
27.07/10.38 */
27.07/10.38 public String toString() {
27.07/10.38 return key + "=" + value;
27.07/10.38 }
27.07/10.38
27.07/10.38 }
27.07/10.38
27.07/10.38 }
27.07/10.38
27.07/10.38
27.07/10.38 /*
27.07/10.38 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
27.07/10.38 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27.07/10.38 *
27.07/10.38 * This code is free software; you can redistribute it and/or modify it
27.07/10.38 * under the terms of the GNU General Public License version 2 only, as
27.07/10.38 * published by the Free Software Foundation. Sun designates this
27.07/10.38 * particular file as subject to the "Classpath" exception as provided
27.07/10.38 * by Sun in the LICENSE file that accompanied this code.
27.07/10.38 *
27.07/10.38 * This code is distributed in the hope that it will be useful, but WITHOUT
27.07/10.38 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27.07/10.38 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27.07/10.38 * version 2 for more details (a copy is included in the LICENSE file that
27.07/10.38 * accompanied this code).
27.07/10.38 *
27.07/10.38 * You should have received a copy of the GNU General Public License version
27.07/10.38 * 2 along with this work; if not, write to the Free Software Foundation,
27.07/10.38 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27.07/10.38 *
27.07/10.38 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
27.07/10.38 * CA 95054 USA or visit www.sun.com if you need additional information or
27.07/10.38 * have any questions.
27.07/10.38 */
27.07/10.38
27.07/10.38 package javaUtilEx;
27.07/10.38
27.07/10.38 /**
27.07/10.38 * This class provides a skeletal implementation of the Set
27.07/10.38 * interface to minimize the effort required to implement this
27.07/10.38 * interface.