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