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