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