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