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