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 implements Collection { 8.01/2.94 /** 8.01/2.94 * Sole constructor. (For invocation by subclass constructors, typically 8.01/2.94 * implicit.) 8.01/2.94 */ 8.01/2.94 protected AbstractCollection() { 8.01/2.94 } 8.01/2.94 8.01/2.94 // Query Operations 8.01/2.94 8.01/2.94 /** 8.01/2.94 * Returns an iterator over the elements contained in this collection. 8.01/2.94 * 8.01/2.94 * @return an iterator over the elements contained in this collection 8.01/2.94 */ 8.01/2.94 public abstract Iterator iterator(); 8.01/2.94 8.01/2.94 public abstract int size(); 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 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 e = iterator(); 8.01/2.94 if (o==null) { 8.01/2.94 while (e.hasNext()) 8.01/2.94 if (e.next()==null) 8.01/2.94 return true; 8.01/2.94 } else { 8.01/2.94 while (e.hasNext()) 8.01/2.94 if (o.equals(e.next())) 8.01/2.94 return true; 8.01/2.94 } 8.01/2.94 return false; 8.01/2.94 } 8.01/2.94 8.01/2.94 // Modification Operations 8.01/2.94 8.01/2.94 /** 8.01/2.94 * {@inheritDoc} 8.01/2.94 * 8.01/2.94 *

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 e = iterator(); 8.01/2.94 if (o==null) { 8.01/2.94 while (e.hasNext()) { 8.01/2.94 if (e.next()==null) { 8.01/2.94 e.remove(); 8.01/2.94 return true; 8.01/2.94 } 8.01/2.94 } 8.01/2.94 } else { 8.01/2.94 while (e.hasNext()) { 8.01/2.94 if (o.equals(e.next())) { 8.01/2.94 e.remove(); 8.01/2.94 return true; 8.01/2.94 } 8.01/2.94 } 8.01/2.94 } 8.01/2.94 return false; 8.01/2.94 } 8.01/2.94 8.01/2.94 8.01/2.94 // Bulk Operations 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, 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 c) { 8.01/2.94 boolean modified = false; 8.01/2.94 Iterator 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 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, 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 e = iterator(); 8.01/2.94 while (e.hasNext()) { 8.01/2.94 e.next(); 8.01/2.94 e.remove(); 8.01/2.94 } 8.01/2.94 } 8.01/2.94 8.01/2.94 8.01/2.94 // String conversion 8.01/2.94 8.01/2.94 /** 8.01/2.94 * Returns a string representation of this collection. The string 8.01/2.94 * representation consists of a list of the collection's elements in the 8.01/2.94 * order they are returned by its iterator, enclosed in square brackets 8.01/2.94 * ("[]"). Adjacent elements are separated by the characters 8.01/2.94 * ", " (comma and space). Elements are converted to strings as 8.01/2.94 * by {@link String#valueOf(Object)}. 8.01/2.94 * 8.01/2.94 * @return a string representation of this collection 8.01/2.94 */ 8.01/2.94 public String toString() { 8.01/2.94 Iterator i = iterator(); 8.01/2.94 if (! i.hasNext()) 8.01/2.94 return "[]"; 8.01/2.94 8.01/2.94 String sb = ""; 8.01/2.94 sb = sb + "["; 8.01/2.94 for (;;) { 8.01/2.94 E e = i.next(); 8.01/2.94 sb = sb + (e == this ? "(this Collection)" : e); 8.01/2.94 if (! i.hasNext()) { 8.01/2.94 sb = sb + "]"; 8.01/2.94 return sb; 8.01/2.94 } 8.01/2.94 sb = sb + ", "; 8.01/2.94 } 8.01/2.94 } 8.01/2.94 8.01/2.94 } 8.01/2.94 8.01/2.94 8.01/2.94 /* 8.01/2.94 * Copyright 1997-2007 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 import javaUtilEx.Map.Entry; 8.01/2.94 8.01/2.94 /** 8.01/2.94 * This class provides a skeletal implementation of the Map 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 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 the type of keys maintained by this map 8.01/2.94 * @param the type of mapped values 8.01/2.94 * 8.01/2.94 * @author Josh Bloch 8.01/2.94 * @author Neal Gafter 8.01/2.94 * @see Map 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 AbstractMap implements Map { 8.01/2.94 /** 8.01/2.94 * Sole constructor. (For invocation by subclass constructors, typically 8.01/2.94 * implicit.) 8.01/2.94 */ 8.01/2.94 protected AbstractMap() { 8.01/2.94 } 8.01/2.94 8.01/2.94 // Query Operations 8.01/2.94 8.01/2.94 /** 8.01/2.94 * {@inheritDoc} 8.01/2.94 * 8.01/2.94 *

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> i = entrySet().iterator(); 8.01/2.94 if (value==null) { 8.01/2.94 while (i.hasNext()) { 8.01/2.94 Entry e = i.next(); 8.01/2.94 if (e.getValue()==null) 8.01/2.94 return true; 8.01/2.94 } 8.01/2.94 } else { 8.01/2.94 while (i.hasNext()) { 8.01/2.94 Entry e = i.next(); 8.01/2.94 if (value.equals(e.getValue())) 8.01/2.94 return true; 8.01/2.94 } 8.01/2.94 } 8.01/2.94 return false; 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 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> i = entrySet().iterator(); 8.01/2.94 if (key==null) { 8.01/2.94 while (i.hasNext()) { 8.01/2.94 Entry e = i.next(); 8.01/2.94 if (e.getKey()==null) 8.01/2.94 return true; 8.01/2.94 } 8.01/2.94 } else { 8.01/2.94 while (i.hasNext()) { 8.01/2.94 Entry e = i.next(); 8.01/2.94 if (key.equals(e.getKey())) 8.01/2.94 return true; 8.01/2.94 } 8.01/2.94 } 8.01/2.94 return false; 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 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> i = entrySet().iterator(); 8.01/2.94 if (key==null) { 8.01/2.94 while (i.hasNext()) { 8.01/2.94 Entry e = i.next(); 8.01/2.94 if (e.getKey()==null) 8.01/2.94 return e.getValue(); 8.01/2.94 } 8.01/2.94 } else { 8.01/2.94 while (i.hasNext()) { 8.01/2.94 Entry e = i.next(); 8.01/2.94 if (key.equals(e.getKey())) 8.01/2.94 return e.getValue(); 8.01/2.94 } 8.01/2.94 } 8.01/2.94 return null; 8.01/2.94 } 8.01/2.94 8.01/2.94 8.01/2.94 // Modification Operations 8.01/2.94 8.01/2.94 /** 8.01/2.94 * {@inheritDoc} 8.01/2.94 * 8.01/2.94 *

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> i = entrySet().iterator(); 8.01/2.94 Entry correctEntry = null; 8.01/2.94 if (key==null) { 8.01/2.94 while (correctEntry==null && i.hasNext()) { 8.01/2.94 Entry e = i.next(); 8.01/2.94 if (e.getKey()==null) 8.01/2.94 correctEntry = e; 8.01/2.94 } 8.01/2.94 } else { 8.01/2.94 while (correctEntry==null && i.hasNext()) { 8.01/2.94 Entry e = i.next(); 8.01/2.94 if (key.equals(e.getKey())) 8.01/2.94 correctEntry = e; 8.01/2.94 } 8.01/2.94 } 8.01/2.94 8.01/2.94 V oldValue = null; 8.01/2.94 if (correctEntry !=null) { 8.01/2.94 oldValue = correctEntry.getValue(); 8.01/2.94 i.remove(); 8.01/2.94 } 8.01/2.94 return oldValue; 8.01/2.94 } 8.01/2.94 8.01/2.94 8.01/2.94 // Bulk Operations 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 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 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 keySet = null; 8.01/2.94 transient volatile Collection values = null; 8.01/2.94 8.01/2.94 /** 8.01/2.94 * {@inheritDoc} 8.01/2.94 * 8.01/2.94 *

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 keySet() { 8.01/2.94 if (keySet == null) { 8.01/2.94 keySet = new AbstractSet() { 8.01/2.94 public Iterator iterator() { 8.01/2.94 return new Iterator() { 8.01/2.94 private Iterator> i = entrySet().iterator(); 8.01/2.94 8.01/2.94 public boolean hasNext() { 8.01/2.94 return i.hasNext(); 8.01/2.94 } 8.01/2.94 8.01/2.94 public K next() { 8.01/2.94 return i.next().getKey(); 8.01/2.94 } 8.01/2.94 8.01/2.94 public void remove() { 8.01/2.94 i.remove(); 8.01/2.94 } 8.01/2.94 }; 8.01/2.94 } 8.01/2.94 8.01/2.94 public int size() { 8.01/2.94 return AbstractMap.this.size(); 8.01/2.94 } 8.01/2.94 8.01/2.94 public boolean isEmpty() { 8.01/2.94 return AbstractMap.this.isEmpty(); 8.01/2.94 } 8.01/2.94 8.01/2.94 public void clear() { 8.01/2.94 AbstractMap.this.clear(); 8.01/2.94 } 8.01/2.94 8.01/2.94 public boolean contains(Object k) { 8.01/2.94 return AbstractMap.this.containsKey(k); 8.01/2.94 } 8.01/2.94 8.01/2.94 public Object[] toArray() { 8.01/2.94 Object[] res = new Object[AbstractMap.this.size()]; 8.01/2.94 Iterator> it = entrySet().iterator(); 8.01/2.94 int i = 0; 8.01/2.94 while (it.hasNext()) 8.01/2.94 res[i++] = it.next().getKey(); 8.01/2.94 return res; 8.01/2.94 } 8.01/2.94 8.01/2.94 public T[] toArray(T[] a) { 8.01/2.94 a = (T[])java.lang.reflect.Array.newInstance( 8.01/2.94 a.getClass().getComponentType(), AbstractMap.this.size()); 8.01/2.94 Object[] res = a; 8.01/2.94 Iterator> it = entrySet().iterator(); 8.01/2.94 int i = 0; 8.01/2.94 while (it.hasNext()) 8.01/2.94 res[i++] = it.next().getKey(); 8.01/2.94 return a; 8.01/2.94 } 8.01/2.94 }; 8.01/2.94 } 8.01/2.94 return keySet; 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 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 values() { 8.01/2.94 if (values == null) { 8.01/2.94 values = new AbstractCollection() { 8.01/2.94 public Iterator iterator() { 8.01/2.94 return new Iterator() { 8.01/2.94 private Iterator> i = entrySet().iterator(); 8.01/2.94 8.01/2.94 public boolean hasNext() { 8.01/2.94 return i.hasNext(); 8.01/2.94 } 8.01/2.94 8.01/2.94 public V next() { 8.01/2.94 return i.next().getValue(); 8.01/2.94 } 8.01/2.94 8.01/2.94 public void remove() { 8.01/2.94 i.remove(); 8.01/2.94 } 8.01/2.94 }; 8.01/2.94 } 8.01/2.94 8.01/2.94 public int size() { 8.01/2.94 return AbstractMap.this.size(); 8.01/2.94 } 8.01/2.94 8.01/2.94 public boolean isEmpty() { 8.01/2.94 return AbstractMap.this.isEmpty(); 8.01/2.94 } 8.01/2.94 8.01/2.94 public void clear() { 8.01/2.94 AbstractMap.this.clear(); 8.01/2.94 } 8.01/2.94 8.01/2.94 public boolean contains(Object v) { 8.01/2.94 return AbstractMap.this.containsValue(v); 8.01/2.94 } 8.01/2.94 }; 8.01/2.94 } 8.01/2.94 return values; 8.01/2.94 } 8.01/2.94 8.01/2.94 public abstract Set> entrySet(); 8.01/2.94 8.01/2.94 8.01/2.94 // Comparison and hashing 8.01/2.94 8.01/2.94 /** 8.01/2.94 * Compares the specified object with this map for equality. Returns 8.01/2.94 * true if the given object is also a map and the two maps 8.01/2.94 * represent the same mappings. More formally, two maps m1 and 8.01/2.94 * m2 represent the same mappings if 8.01/2.94 * m1.entrySet().equals(m2.entrySet()). This ensures that the 8.01/2.94 * equals method works properly across different implementations 8.01/2.94 * of the Map interface. 8.01/2.94 * 8.01/2.94 *

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 m = (Map) o; 8.01/2.94 if (m.size() != size()) 8.01/2.94 return false; 8.01/2.94 8.01/2.94 try { 8.01/2.94 Iterator> i = entrySet().iterator(); 8.01/2.94 while (i.hasNext()) { 8.01/2.94 Entry e = i.next(); 8.01/2.94 K key = e.getKey(); 8.01/2.94 V value = e.getValue(); 8.01/2.94 if (value == null) { 8.01/2.94 if (!(m.get(key)==null && m.containsKey(key))) 8.01/2.94 return false; 8.01/2.94 } else { 8.01/2.94 if (!value.equals(m.get(key))) 8.01/2.94 return false; 8.01/2.94 } 8.01/2.94 } 8.01/2.94 } catch (ClassCastException unused) { 8.01/2.94 return false; 8.01/2.94 } catch (NullPointerException unused) { 8.01/2.94 return false; 8.01/2.94 } 8.01/2.94 8.01/2.94 return true; 8.01/2.94 } 8.01/2.94 8.01/2.94 /** 8.01/2.94 * Returns the hash code value for this map. The hash code of a map is 8.01/2.95 * defined to be the sum of the hash codes of each entry in the map's 8.01/2.95 * entrySet() view. This ensures that m1.equals(m2) 8.01/2.95 * implies that m1.hashCode()==m2.hashCode() for any two maps 8.01/2.95 * m1 and m2, 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 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> i = entrySet().iterator(); 8.01/2.95 while (i.hasNext()) 8.01/2.95 h += i.next().hashCode(); 8.01/2.95 return h; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns a string representation of this map. The string representation 8.01/2.95 * consists of a list of key-value mappings in the order returned by the 8.01/2.95 * map's entrySet view's iterator, enclosed in braces 8.01/2.95 * ("{}"). Adjacent mappings are separated by the characters 8.01/2.95 * ", " (comma and space). Each key-value mapping is rendered as 8.01/2.95 * the key followed by an equals sign ("=") followed by the 8.01/2.95 * associated value. Keys and values are converted to strings as by 8.01/2.95 * {@link String#valueOf(Object)}. 8.01/2.95 * 8.01/2.95 * @return a string representation of this map 8.01/2.95 */ 8.01/2.95 public String toString() { 8.01/2.95 Iterator> i = entrySet().iterator(); 8.01/2.95 if (! i.hasNext()) 8.01/2.95 return "{}"; 8.01/2.95 8.01/2.95 StringBuilder sb = new StringBuilder(); 8.01/2.95 sb.append('{'); 8.01/2.95 for (;;) { 8.01/2.95 Entry e = i.next(); 8.01/2.95 K key = e.getKey(); 8.01/2.95 V value = e.getValue(); 8.01/2.95 sb.append(key == this ? "(this Map)" : key); 8.01/2.95 sb.append('='); 8.01/2.95 sb.append(value == this ? "(this Map)" : value); 8.01/2.95 if (! i.hasNext()) 8.01/2.95 return sb.append('}').toString(); 8.01/2.95 sb.append(", "); 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns a shallow copy of this AbstractMap instance: the keys 8.01/2.95 * and values themselves are not cloned. 8.01/2.95 * 8.01/2.95 * @return a shallow copy of this map 8.01/2.95 */ 8.01/2.95 protected Object clone() throws CloneNotSupportedException { 8.01/2.95 AbstractMap result = (AbstractMap)super.clone(); 8.01/2.95 result.keySet = null; 8.01/2.95 result.values = null; 8.01/2.95 return result; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Utility method for SimpleEntry and SimpleImmutableEntry. 8.01/2.95 * Test for equality, checking for nulls. 8.01/2.95 */ 8.01/2.95 private static boolean eq(Object o1, Object o2) { 8.01/2.95 return o1 == null ? o2 == null : o1.equals(o2); 8.01/2.95 } 8.01/2.95 8.01/2.95 // Implementation Note: SimpleEntry and SimpleImmutableEntry 8.01/2.95 // are distinct unrelated classes, even though they share 8.01/2.95 // some code. Since you can't add or subtract final-ness 8.01/2.95 // of a field in a subclass, they can't share representations, 8.01/2.95 // and the amount of duplicated code is too small to warrant 8.01/2.95 // exposing a common abstract class. 8.01/2.95 8.01/2.95 8.01/2.95 /** 8.01/2.95 * An Entry maintaining a key and a value. The value may be 8.01/2.95 * changed using the setValue method. This class 8.01/2.95 * facilitates the process of building custom map 8.01/2.95 * implementations. For example, it may be convenient to return 8.01/2.95 * arrays of SimpleEntry instances in method 8.01/2.95 * Map.entrySet().toArray. 8.01/2.95 * 8.01/2.95 * @since 1.6 8.01/2.95 */ 8.01/2.95 public static class SimpleEntry 8.01/2.95 implements Entry, java.io.Serializable 8.01/2.95 { 8.01/2.95 private static final long serialVersionUID = -8499721149061103585L; 8.01/2.95 8.01/2.95 private final K key; 8.01/2.95 private V value; 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Creates an entry representing a mapping from the specified 8.01/2.95 * key to the specified value. 8.01/2.95 * 8.01/2.95 * @param key the key represented by this entry 8.01/2.95 * @param value the value represented by this entry 8.01/2.95 */ 8.01/2.95 public SimpleEntry(K key, V value) { 8.01/2.95 this.key = key; 8.01/2.95 this.value = value; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Creates an entry representing the same mapping as the 8.01/2.95 * specified entry. 8.01/2.95 * 8.01/2.95 * @param entry the entry to copy 8.01/2.95 */ 8.01/2.95 public SimpleEntry(Entry entry) { 8.01/2.95 this.key = entry.getKey(); 8.01/2.95 this.value = entry.getValue(); 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns the key corresponding to this entry. 8.01/2.95 * 8.01/2.95 * @return the key corresponding to this entry 8.01/2.95 */ 8.01/2.95 public K getKey() { 8.01/2.95 return key; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns the value corresponding to this entry. 8.01/2.95 * 8.01/2.95 * @return the value corresponding to this entry 8.01/2.95 */ 8.01/2.95 public V getValue() { 8.01/2.95 return value; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Replaces the value corresponding to this entry with the specified 8.01/2.95 * value. 8.01/2.95 * 8.01/2.95 * @param value new value to be stored in this entry 8.01/2.95 * @return the old value corresponding to the entry 8.01/2.95 */ 8.01/2.95 public V setValue(V value) { 8.01/2.95 V oldValue = this.value; 8.01/2.95 this.value = value; 8.01/2.95 return oldValue; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Compares the specified object with this entry for equality. 8.01/2.95 * Returns {@code true} if the given object is also a map entry and 8.01/2.95 * the two entries represent the same mapping. More formally, two 8.01/2.95 * entries {@code e1} and {@code e2} represent the same mapping 8.01/2.95 * if

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 implements Entry, java.io.Serializable 8.01/2.95 { 8.01/2.95 private static final long serialVersionUID = 7138329143949025153L; 8.01/2.95 8.01/2.95 private final K key; 8.01/2.95 private final V value; 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Creates an entry representing a mapping from the specified 8.01/2.95 * key to the specified value. 8.01/2.95 * 8.01/2.95 * @param key the key represented by this entry 8.01/2.95 * @param value the value represented by this entry 8.01/2.95 */ 8.01/2.95 public SimpleImmutableEntry(K key, V value) { 8.01/2.95 this.key = key; 8.01/2.95 this.value = value; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Creates an entry representing the same mapping as the 8.01/2.95 * specified entry. 8.01/2.95 * 8.01/2.95 * @param entry the entry to copy 8.01/2.95 */ 8.01/2.95 public SimpleImmutableEntry(Entry entry) { 8.01/2.95 this.key = entry.getKey(); 8.01/2.95 this.value = entry.getValue(); 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns the key corresponding to this entry. 8.01/2.95 * 8.01/2.95 * @return the key corresponding to this entry 8.01/2.95 */ 8.01/2.95 public K getKey() { 8.01/2.95 return key; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns the value corresponding to this entry. 8.01/2.95 * 8.01/2.95 * @return the value corresponding to this entry 8.01/2.95 */ 8.01/2.95 public V getValue() { 8.01/2.95 return value; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Replaces the value corresponding to this entry with the specified 8.01/2.95 * value (optional operation). This implementation simply throws 8.01/2.95 * UnsupportedOperationException, as this class implements 8.01/2.95 * an immutable map entry. 8.01/2.95 * 8.01/2.95 * @param value new value to be stored in this entry 8.01/2.95 * @return (Does not return) 8.01/2.95 * @throws UnsupportedOperationException always 8.01/2.95 */ 8.01/2.95 public V setValue(V value) { 8.01/2.95 throw new UnsupportedOperationException(); 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Compares the specified object with this entry for equality. 8.01/2.95 * Returns {@code true} if the given object is also a map entry and 8.01/2.95 * the two entries represent the same mapping. More formally, two 8.01/2.95 * entries {@code e1} and {@code e2} represent the same mapping 8.01/2.95 * if
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 * 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 the type of elements maintained by this set 8.01/2.95 * 8.01/2.95 * @author Josh Bloch 8.01/2.95 * @author Neal Gafter 8.01/2.95 * @see Collection 8.01/2.95 * @see AbstractCollection 8.01/2.95 * @see Set 8.01/2.95 * @since 1.2 8.01/2.95 */ 8.01/2.95 8.01/2.95 public abstract class AbstractSet extends AbstractCollection implements Set { 8.01/2.95 /** 8.01/2.95 * Sole constructor. (For invocation by subclass constructors, typically 8.01/2.95 * implicit.) 8.01/2.95 */ 8.01/2.95 protected AbstractSet() { 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 set for equality. Returns 8.01/2.95 * true if the given object is also a set, the two sets have 8.01/2.95 * the same size, and every member of the given set is contained in 8.01/2.95 * this set. This ensures that the equals method works 8.01/2.95 * properly across different implementations of the Set 8.01/2.95 * interface.

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 i = iterator(); 8.01/2.95 while (i.hasNext()) { 8.01/2.95 E obj = i.next(); 8.01/2.95 if (obj != null) 8.01/2.95 h += obj.hashCode(); 8.01/2.95 } 8.01/2.95 return h; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Removes from this set all of its elements that are contained in the 8.01/2.95 * specified collection (optional operation). If the specified 8.01/2.95 * collection is also a set, this operation effectively modifies this 8.01/2.95 * set so that its value is the asymmetric set difference of 8.01/2.95 * the two sets. 8.01/2.95 * 8.01/2.95 *

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 // Query Operations 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns the number of elements in this collection. If this collection 8.01/2.95 * contains more than Integer.MAX_VALUE elements, returns 8.01/2.95 * Integer.MAX_VALUE. 8.01/2.95 * 8.01/2.95 * @return the number of elements in this collection 8.01/2.95 */ 8.01/2.95 int size(); 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns true if this collection contains no elements. 8.01/2.95 * 8.01/2.95 * @return true if this collection contains no elements 8.01/2.95 */ 8.01/2.95 boolean isEmpty(); 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns true if this collection contains the specified element. 8.01/2.95 * More formally, 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)). 8.01/2.95 * 8.01/2.95 * @param o element whose presence in this collection is to be tested 8.01/2.95 * @return true if this collection contains the specified 8.01/2.95 * element 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 */ 8.01/2.95 boolean contains(Object o); 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns an iterator over the elements in this collection. There are no 8.01/2.95 * guarantees concerning the order in which the elements are returned 8.01/2.95 * (unless this collection is an instance of some class that provides a 8.01/2.95 * guarantee). 8.01/2.95 * 8.01/2.95 * @return an Iterator over the elements in this collection 8.01/2.95 */ 8.01/2.95 Iterator iterator(); 8.01/2.95 8.01/2.95 // Modification Operations 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Ensures that this collection contains the specified element (optional 8.01/2.95 * operation). Returns true if this collection changed as a 8.01/2.95 * result of the call. (Returns false if this collection does 8.01/2.95 * not permit duplicates and already contains the specified element.)

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 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:

8.01/2.95	 *   Map m = Collections.synchronizedMap(new HashMap(...));
8.01/2.95 * 8.01/2.95 *

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 the type of keys maintained by this map 8.01/2.95 * @param the type of mapped values 8.01/2.95 * 8.01/2.95 * @author Doug Lea 8.01/2.95 * @author Josh Bloch 8.01/2.95 * @author Arthur van Hoff 8.01/2.95 * @author Neal Gafter 8.01/2.95 * @see Object#hashCode() 8.01/2.95 * @see Collection 8.01/2.95 * @see Map 8.01/2.95 * @see TreeMap 8.01/2.95 * @see Hashtable 8.01/2.95 * @since 1.2 8.01/2.95 */ 8.01/2.95 8.01/2.95 public class HashMap 8.01/2.95 extends AbstractMap 8.01/2.95 implements Map, Cloneable 8.01/2.95 { 8.01/2.95 8.01/2.95 /** 8.01/2.95 * The default initial capacity - MUST be a power of two. 8.01/2.95 */ 8.01/2.95 static final int DEFAULT_INITIAL_CAPACITY = 16; 8.01/2.95 8.01/2.95 /** 8.01/2.95 * The maximum capacity, used if a higher value is implicitly specified 8.01/2.95 * by either of the constructors with arguments. 8.01/2.95 * MUST be a power of two <= 1<<30. 8.01/2.95 */ 8.01/2.95 static final int MAXIMUM_CAPACITY = 1 << 30; 8.01/2.95 8.01/2.95 /** 8.01/2.95 * The load factor used when none specified in constructor. 8.01/2.95 */ 8.01/2.95 static final float DEFAULT_LOAD_FACTOR = 0.75f; 8.01/2.95 8.01/2.95 /** 8.01/2.95 * The table, resized as necessary. Length MUST Always be a power of two. 8.01/2.95 */ 8.01/2.95 transient Entry[] table; 8.01/2.95 8.01/2.95 /** 8.01/2.95 * The number of key-value mappings contained in this map. 8.01/2.95 */ 8.01/2.95 transient int size; 8.01/2.95 8.01/2.95 /** 8.01/2.95 * The next size value at which to resize (capacity * load factor). 8.01/2.95 * @serial 8.01/2.95 */ 8.01/2.95 int threshold; 8.01/2.95 8.01/2.95 /** 8.01/2.95 * The load factor for the hash table. 8.01/2.95 * 8.01/2.95 * @serial 8.01/2.95 */ 8.01/2.95 final float loadFactor; 8.01/2.95 8.01/2.95 /** 8.01/2.95 * The number of times this HashMap has been structurally modified 8.01/2.95 * Structural modifications are those that change the number of mappings in 8.01/2.95 * the HashMap or otherwise modify its internal structure (e.g., 8.01/2.95 * rehash). This field is used to make iterators on Collection-views of 8.01/2.95 * the HashMap fail-fast. (See ConcurrentModificationException). 8.01/2.95 */ 8.01/2.95 transient volatile int modCount; 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Constructs an empty HashMap with the specified initial 8.01/2.95 * capacity and load factor. 8.01/2.95 * 8.01/2.95 * @param initialCapacity the initial capacity 8.01/2.95 * @param loadFactor the load factor 8.01/2.95 * @throws IllegalArgumentException if the initial capacity is negative 8.01/2.95 * or the load factor is nonpositive 8.01/2.95 */ 8.01/2.95 public HashMap(int initialCapacity, float loadFactor) { 8.01/2.95 if (initialCapacity < 0) 8.01/2.95 throw new IllegalArgumentException("Illegal initial capacity: " + 8.01/2.95 initialCapacity); 8.01/2.95 if (initialCapacity > MAXIMUM_CAPACITY) 8.01/2.95 initialCapacity = MAXIMUM_CAPACITY; 8.01/2.95 if (loadFactor <= 0 || Float.isNaN(loadFactor)) 8.01/2.95 throw new IllegalArgumentException("Illegal load factor: " + 8.01/2.95 loadFactor); 8.01/2.95 8.01/2.95 // Find a power of 2 >= initialCapacity 8.01/2.95 int capacity = 1; 8.01/2.95 while (capacity < initialCapacity) 8.01/2.95 capacity <<= 1; 8.01/2.95 8.01/2.95 this.loadFactor = loadFactor; 8.01/2.95 threshold = (int)(capacity * loadFactor); 8.01/2.95 table = new Entry[capacity]; 8.01/2.95 init(); 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Constructs an empty HashMap with the specified initial 8.01/2.95 * capacity and the default load factor (0.75). 8.01/2.95 * 8.01/2.95 * @param initialCapacity the initial capacity. 8.01/2.95 * @throws IllegalArgumentException if the initial capacity is negative. 8.01/2.95 */ 8.01/2.95 public HashMap(int initialCapacity) { 8.01/2.95 this(initialCapacity, DEFAULT_LOAD_FACTOR); 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Constructs an empty HashMap with the default initial capacity 8.01/2.95 * (16) and the default load factor (0.75). 8.01/2.95 */ 8.01/2.95 public HashMap() { 8.01/2.95 this.loadFactor = DEFAULT_LOAD_FACTOR; 8.01/2.95 threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR); 8.01/2.95 table = new Entry[DEFAULT_INITIAL_CAPACITY]; 8.01/2.95 init(); 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Constructs a new HashMap with the same mappings as the 8.01/2.95 * specified Map. The HashMap is created with 8.01/2.95 * default load factor (0.75) and an initial capacity sufficient to 8.01/2.95 * hold the mappings in the specified Map. 8.01/2.95 * 8.01/2.95 * @param m the map whose mappings are to be placed in this map 8.01/2.95 * @throws NullPointerException if the specified map is null 8.01/2.95 */ 8.01/2.95 public HashMap(Map m) { 8.01/2.95 this(Math.max((int) (m.size() / DEFAULT_LOAD_FACTOR) + 1, 8.01/2.95 DEFAULT_INITIAL_CAPACITY), DEFAULT_LOAD_FACTOR); 8.01/2.95 putAllForCreate(m); 8.01/2.95 } 8.01/2.95 8.01/2.95 // internal utilities 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Initialization hook for subclasses. This method is called 8.01/2.95 * in all constructors and pseudo-constructors (clone, readObject) 8.01/2.95 * after HashMap has been initialized but before any entries have 8.01/2.95 * been inserted. (In the absence of this method, readObject would 8.01/2.95 * require explicit knowledge of subclasses.) 8.01/2.95 */ 8.01/2.95 void init() { 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Applies a supplemental hash function to a given hashCode, which 8.01/2.95 * defends against poor quality hash functions. This is critical 8.01/2.95 * because HashMap uses power-of-two length hash tables, that 8.01/2.95 * otherwise encounter collisions for hashCodes that do not differ 8.01/2.95 * in lower bits. Note: Null keys always map to hash 0, thus index 0. 8.01/2.95 */ 8.01/2.95 static int hash(int h) { 8.01/2.95 // This function ensures that hashCodes that differ only by 8.01/2.95 // constant multiples at each bit position have a bounded 8.01/2.95 // number of collisions (approximately 8 at default load factor). 8.01/2.95 h ^= (h >>> 20) ^ (h >>> 12); 8.01/2.95 return h ^ (h >>> 7) ^ (h >>> 4); 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns index for hash code h. 8.01/2.95 */ 8.01/2.95 static int indexFor(int h, int length) { 8.01/2.95 return h & (length-1); 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns the number of key-value mappings in this map. 8.01/2.95 * 8.01/2.95 * @return the number of key-value mappings in this map 8.01/2.95 */ 8.01/2.95 public int size() { 8.01/2.95 return size; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns true if this map contains no key-value mappings. 8.01/2.95 * 8.01/2.95 * @return true if this map contains no key-value mappings 8.01/2.95 */ 8.01/2.95 public boolean isEmpty() { 8.01/2.95 return size == 0; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns the value to which the specified key is mapped, 8.01/2.95 * or {@code null} if this map contains no mapping for the key. 8.01/2.95 * 8.01/2.95 *

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 e = table[indexFor(hash, table.length)]; 8.01/2.95 e != null; 8.01/2.95 e = e.next) { 8.01/2.95 Object k; 8.01/2.95 if (e.hash == hash && ((k = e.key) == key || key.equals(k))) 8.01/2.95 return e.value; 8.01/2.95 } 8.01/2.95 return null; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Offloaded version of get() to look up null keys. Null keys map 8.01/2.95 * to index 0. This null case is split out into separate methods 8.01/2.95 * for the sake of performance in the two most commonly used 8.01/2.95 * operations (get and put), but incorporated with conditionals in 8.01/2.95 * others. 8.01/2.95 */ 8.01/2.95 private V getForNullKey() { 8.01/2.95 for (Entry e = table[0]; e != null; e = e.next) { 8.01/2.95 if (e.key == null) 8.01/2.95 return e.value; 8.01/2.95 } 8.01/2.95 return null; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns true if this map contains a mapping for the 8.01/2.95 * specified key. 8.01/2.95 * 8.01/2.95 * @param key The key whose presence in this map is to be tested 8.01/2.95 * @return true if this map contains a mapping for the specified 8.01/2.95 * key. 8.01/2.95 */ 8.01/2.95 public boolean containsKey(Object key) { 8.01/2.95 return getEntry(key) != null; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns the entry associated with the specified key in the 8.01/2.95 * HashMap. Returns null if the HashMap contains no mapping 8.01/2.95 * for the key. 8.01/2.95 */ 8.01/2.95 final Entry getEntry(Object key) { 8.01/2.95 int hash = (key == null) ? 0 : hash(key.hashCode()); 8.01/2.95 for (Entry e = table[indexFor(hash, table.length)]; 8.01/2.95 e != null; 8.01/2.95 e = e.next) { 8.01/2.95 Object k; 8.01/2.95 if (e.hash == hash && 8.01/2.95 ((k = e.key) == key || (key != null && key.equals(k)))) 8.01/2.95 return e; 8.01/2.95 } 8.01/2.95 return null; 8.01/2.95 } 8.01/2.95 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Associates the specified value with the specified key in this map. 8.01/2.95 * If the map previously contained a mapping for the key, the old 8.01/2.95 * value is replaced. 8.01/2.95 * 8.01/2.95 * @param key key with which the specified value is to be associated 8.01/2.95 * @param value value to be associated with the specified key 8.01/2.95 * @return the previous value associated with key, or 8.01/2.95 * null if there was no mapping for key. 8.01/2.95 * (A null return can also indicate that the map 8.01/2.95 * previously associated null with key.) 8.01/2.95 */ 8.01/2.95 public V put(K key, V value) { 8.01/2.95 if (key == null) 8.01/2.95 return putForNullKey(value); 8.01/2.95 int hash = hash(key.hashCode()); 8.01/2.95 int i = indexFor(hash, table.length); 8.01/2.95 for (Entry e = table[i]; e != null; e = e.next) { 8.01/2.95 Object k; 8.01/2.95 if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { 8.01/2.95 V oldValue = e.value; 8.01/2.95 e.value = value; 8.01/2.95 e.recordAccess(this); 8.01/2.95 return oldValue; 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 modCount++; 8.01/2.95 addEntry(hash, key, value, i); 8.01/2.95 return null; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Offloaded version of put for null keys 8.01/2.95 */ 8.01/2.95 private V putForNullKey(V value) { 8.01/2.95 for (Entry e = table[0]; e != null; e = e.next) { 8.01/2.95 if (e.key == null) { 8.01/2.95 V oldValue = e.value; 8.01/2.95 e.value = value; 8.01/2.95 e.recordAccess(this); 8.01/2.95 return oldValue; 8.01/2.95 } 8.01/2.95 } 8.01/2.95 modCount++; 8.01/2.95 addEntry(0, null, value, 0); 8.01/2.95 return null; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * This method is used instead of put by constructors and 8.01/2.95 * pseudoconstructors (clone, readObject). It does not resize the table, 8.01/2.95 * check for comodification, etc. It calls createEntry rather than 8.01/2.95 * addEntry. 8.01/2.95 */ 8.01/2.95 private void putForCreate(K key, V value) { 8.01/2.95 int hash = (key == null) ? 0 : hash(key.hashCode()); 8.01/2.95 int i = indexFor(hash, table.length); 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Look for preexisting entry for key. This will never happen for 8.01/2.95 * clone or deserialize. It will only happen for construction if the 8.01/2.95 * input Map is a sorted map whose ordering is inconsistent w/ equals. 8.01/2.95 */ 8.01/2.95 for (Entry e = table[i]; e != null; e = e.next) { 8.01/2.95 Object k; 8.01/2.95 if (e.hash == hash && 8.01/2.95 ((k = e.key) == key || (key != null && key.equals(k)))) { 8.01/2.95 e.value = value; 8.01/2.95 return; 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 createEntry(hash, key, value, i); 8.01/2.95 } 8.01/2.95 8.01/2.95 private void putAllForCreate(Map m) { 8.01/2.95 for (Iterator> i = m.entrySet().iterator(); i.hasNext(); ) { 8.01/2.95 Map.Entry e = i.next(); 8.01/2.95 putForCreate(e.getKey(), e.getValue()); 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Rehashes the contents of this map into a new array with a 8.01/2.95 * larger capacity. This method is called automatically when the 8.01/2.95 * number of keys in this map reaches its threshold. 8.01/2.95 * 8.01/2.95 * If current capacity is MAXIMUM_CAPACITY, this method does not 8.01/2.95 * resize the map, but sets threshold to Integer.MAX_VALUE. 8.01/2.95 * This has the effect of preventing future calls. 8.01/2.95 * 8.01/2.95 * @param newCapacity the new capacity, MUST be a power of two; 8.01/2.95 * must be greater than current capacity unless current 8.01/2.95 * capacity is MAXIMUM_CAPACITY (in which case value 8.01/2.95 * is irrelevant). 8.01/2.95 */ 8.01/2.95 void resize(int newCapacity) { 8.01/2.95 Entry[] oldTable = table; 8.01/2.95 int oldCapacity = oldTable.length; 8.01/2.95 if (oldCapacity == MAXIMUM_CAPACITY) { 8.01/2.95 threshold = Integer.MAX_VALUE; 8.01/2.95 return; 8.01/2.95 } 8.01/2.95 8.01/2.95 Entry[] newTable = new Entry[newCapacity]; 8.01/2.95 transfer(newTable); 8.01/2.95 table = newTable; 8.01/2.95 threshold = (int)(newCapacity * loadFactor); 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Transfers all entries from current table to newTable. 8.01/2.95 */ 8.01/2.95 void transfer(Entry[] newTable) { 8.01/2.95 Entry[] src = table; 8.01/2.95 int newCapacity = newTable.length; 8.01/2.95 for (int j = 0; j < src.length; j++) { 8.01/2.95 Entry e = src[j]; 8.01/2.95 if (e != null) { 8.01/2.95 src[j] = null; 8.01/2.95 do { 8.01/2.95 Entry next = e.next; 8.01/2.95 int i = indexFor(e.hash, newCapacity); 8.01/2.95 e.next = newTable[i]; 8.01/2.95 newTable[i] = e; 8.01/2.95 e = next; 8.01/2.95 } while (e != null); 8.01/2.95 } 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Copies all of the mappings from the specified map to this map. 8.01/2.95 * These mappings will replace any mappings that this map had for 8.01/2.95 * any of the keys currently in the specified map. 8.01/2.95 * 8.01/2.95 * @param m mappings to be stored in this map 8.01/2.95 * @throws NullPointerException if the specified map is null 8.01/2.95 */ 8.01/2.95 public void putAll(Map m) { 8.01/2.95 int numKeysToBeAdded = m.size(); 8.01/2.95 if (numKeysToBeAdded == 0) 8.01/2.95 return; 8.01/2.95 8.01/2.95 /* 8.01/2.95 * Expand the map if the map if the number of mappings to be added 8.01/2.95 * is greater than or equal to threshold. This is conservative; the 8.01/2.95 * obvious condition is (m.size() + size) >= threshold, but this 8.01/2.95 * condition could result in a map with twice the appropriate capacity, 8.01/2.95 * if the keys to be added overlap with the keys already in this map. 8.01/2.95 * By using the conservative calculation, we subject ourself 8.01/2.95 * to at most one extra resize. 8.01/2.95 */ 8.01/2.95 if (numKeysToBeAdded > threshold) { 8.01/2.95 int targetCapacity = (int)(numKeysToBeAdded / loadFactor + 1); 8.01/2.95 if (targetCapacity > MAXIMUM_CAPACITY) 8.01/2.95 targetCapacity = MAXIMUM_CAPACITY; 8.01/2.95 int newCapacity = table.length; 8.01/2.95 while (newCapacity < targetCapacity) 8.01/2.95 newCapacity <<= 1; 8.01/2.95 if (newCapacity > table.length) 8.01/2.95 resize(newCapacity); 8.01/2.95 } 8.01/2.95 8.01/2.95 for (Iterator> i = m.entrySet().iterator(); i.hasNext(); ) { 8.01/2.95 Map.Entry e = i.next(); 8.01/2.95 put(e.getKey(), e.getValue()); 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Removes the mapping for the specified key from this map if present. 8.01/2.95 * 8.01/2.95 * @param key key whose mapping is to be removed from the map 8.01/2.95 * @return the previous value associated with key, or 8.01/2.95 * null if there was no mapping for key. 8.01/2.95 * (A null return can also indicate that the map 8.01/2.95 * previously associated null with key.) 8.01/2.95 */ 8.01/2.95 public V remove(Object key) { 8.01/2.95 Entry e = removeEntryForKey(key); 8.01/2.95 return (e == null ? null : e.value); 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Removes and returns the entry associated with the specified key 8.01/2.95 * in the HashMap. Returns null if the HashMap contains no mapping 8.01/2.95 * for this key. 8.01/2.95 */ 8.01/2.95 final Entry removeEntryForKey(Object key) { 8.01/2.95 int hash = (key == null) ? 0 : hash(key.hashCode()); 8.01/2.95 int i = indexFor(hash, table.length); 8.01/2.95 Entry prev = table[i]; 8.01/2.95 Entry e = prev; 8.01/2.95 8.01/2.95 while (e != null) { 8.01/2.95 Entry next = e.next; 8.01/2.95 Object k; 8.01/2.95 if (e.hash == hash && 8.01/2.95 ((k = e.key) == key || (key != null && key.equals(k)))) { 8.01/2.95 modCount++; 8.01/2.95 size--; 8.01/2.95 if (prev == e) 8.01/2.95 table[i] = next; 8.01/2.95 else 8.01/2.95 prev.next = next; 8.01/2.95 e.recordRemoval(this); 8.01/2.95 return e; 8.01/2.95 } 8.01/2.95 prev = e; 8.01/2.95 e = next; 8.01/2.95 } 8.01/2.95 8.01/2.95 return e; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Special version of remove for EntrySet. 8.01/2.95 */ 8.01/2.95 final Entry removeMapping(Object o) { 8.01/2.95 if (!(o instanceof Map.Entry)) 8.01/2.95 return null; 8.01/2.95 8.01/2.95 Map.Entry entry = (Map.Entry) o; 8.01/2.95 Object key = entry.getKey(); 8.01/2.95 int hash = (key == null) ? 0 : hash(key.hashCode()); 8.01/2.95 int i = indexFor(hash, table.length); 8.01/2.95 Entry prev = table[i]; 8.01/2.95 Entry e = prev; 8.01/2.95 8.01/2.95 while (e != null) { 8.01/2.95 Entry next = e.next; 8.01/2.95 if (e.hash == hash && e.equals(entry)) { 8.01/2.95 modCount++; 8.01/2.95 size--; 8.01/2.95 if (prev == e) 8.01/2.95 table[i] = next; 8.01/2.95 else 8.01/2.95 prev.next = next; 8.01/2.95 e.recordRemoval(this); 8.01/2.95 return e; 8.01/2.95 } 8.01/2.95 prev = e; 8.01/2.95 e = next; 8.01/2.95 } 8.01/2.95 8.01/2.95 return e; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Removes all of the mappings from this map. 8.01/2.95 * The map will be empty after this call returns. 8.01/2.95 */ 8.01/2.95 public void clear() { 8.01/2.95 modCount++; 8.01/2.95 Entry[] tab = table; 8.01/2.95 for (int i = 0; i < tab.length; i++) 8.01/2.95 tab[i] = null; 8.01/2.95 size = 0; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns true if this map maps one or more keys to the 8.01/2.95 * specified value. 8.01/2.95 * 8.01/2.95 * @param value value whose presence in this map is to be tested 8.01/2.95 * @return true if this map maps one or more keys to the 8.01/2.95 * specified value 8.01/2.95 */ 8.01/2.95 public boolean containsValue(Object value) { 8.01/2.95 if (value == null) 8.01/2.95 return containsNullValue(); 8.01/2.95 8.01/2.95 Entry[] tab = table; 8.01/2.95 for (int i = 0; i < tab.length ; i++) 8.01/2.95 for (Entry e = tab[i] ; e != null ; e = e.next) 8.01/2.95 if (value.equals(e.value)) 8.01/2.95 return true; 8.01/2.95 return false; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Special-case code for containsValue with null argument 8.01/2.95 */ 8.01/2.95 private boolean containsNullValue() { 8.01/2.95 Entry[] tab = table; 8.01/2.95 for (int i = 0; i < tab.length ; i++) 8.01/2.95 for (Entry e = tab[i] ; e != null ; e = e.next) 8.01/2.95 if (e.value == null) 8.01/2.95 return true; 8.01/2.95 return false; 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns a shallow copy of this HashMap instance: the keys and 8.01/2.95 * values themselves are not cloned. 8.01/2.95 * 8.01/2.95 * @return a shallow copy of this map 8.01/2.95 */ 8.01/2.95 public Object clone() { 8.01/2.95 HashMap result = null; 8.01/2.95 try { 8.01/2.95 result = (HashMap)super.clone(); 8.01/2.95 } catch (CloneNotSupportedException e) { 8.01/2.95 // assert false; 8.01/2.95 } 8.01/2.95 result.table = new Entry[table.length]; 8.01/2.95 result.entrySet = null; 8.01/2.95 result.modCount = 0; 8.01/2.95 result.size = 0; 8.01/2.95 result.init(); 8.01/2.95 result.putAllForCreate(this); 8.01/2.95 8.01/2.95 return result; 8.01/2.95 } 8.01/2.95 8.01/2.95 static class Entry implements Map.Entry { 8.01/2.95 final K key; 8.01/2.95 V value; 8.01/2.95 Entry next; 8.01/2.95 final int hash; 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Creates new entry. 8.01/2.95 */ 8.01/2.95 Entry(int h, K k, V v, Entry n) { 8.01/2.95 value = v; 8.01/2.95 next = n; 8.01/2.95 key = k; 8.01/2.95 hash = h; 8.01/2.95 } 8.01/2.95 8.01/2.95 public final K getKey() { 8.01/2.95 return key; 8.01/2.95 } 8.01/2.95 8.01/2.95 public final V getValue() { 8.01/2.95 return value; 8.01/2.95 } 8.01/2.95 8.01/2.95 public final V setValue(V newValue) { 8.01/2.95 V oldValue = value; 8.01/2.95 value = newValue; 8.01/2.95 return oldValue; 8.01/2.95 } 8.01/2.95 8.01/2.95 public final 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 Object k1 = getKey(); 8.01/2.95 Object k2 = e.getKey(); 8.01/2.95 if (k1 == k2 || (k1 != null && k1.equals(k2))) { 8.01/2.95 Object v1 = getValue(); 8.01/2.95 Object v2 = e.getValue(); 8.01/2.95 if (v1 == v2 || (v1 != null && v1.equals(v2))) 8.01/2.95 return true; 8.01/2.95 } 8.01/2.95 return false; 8.01/2.95 } 8.01/2.95 8.01/2.95 public final 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 public final String toString() { 8.01/2.95 return getKey() + "=" + getValue(); 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * This method is invoked whenever the value in an entry is 8.01/2.95 * overwritten by an invocation of put(k,v) for a key k that's already 8.01/2.95 * in the HashMap. 8.01/2.95 */ 8.01/2.95 void recordAccess(HashMap m) { 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * This method is invoked whenever the entry is 8.01/2.95 * removed from the table. 8.01/2.95 */ 8.01/2.95 void recordRemoval(HashMap m) { 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Adds a new entry with the specified key, value and hash code to 8.01/2.95 * the specified bucket. It is the responsibility of this 8.01/2.95 * method to resize the table if appropriate. 8.01/2.95 * 8.01/2.95 * Subclass overrides this to alter the behavior of put method. 8.01/2.95 */ 8.01/2.95 void addEntry(int hash, K key, V value, int bucketIndex) { 8.01/2.95 Entry e = table[bucketIndex]; 8.01/2.95 table[bucketIndex] = new Entry(hash, key, value, e); 8.01/2.95 if (size++ >= threshold) 8.01/2.95 resize(2 * table.length); 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Like addEntry except that this version is used when creating entries 8.01/2.95 * as part of Map construction or "pseudo-construction" (cloning, 8.01/2.95 * deserialization). This version needn't worry about resizing the table. 8.01/2.95 * 8.01/2.95 * Subclass overrides this to alter the behavior of HashMap(Map), 8.01/2.95 * clone, and readObject. 8.01/2.95 */ 8.01/2.95 void createEntry(int hash, K key, V value, int bucketIndex) { 8.01/2.95 Entry e = table[bucketIndex]; 8.01/2.95 table[bucketIndex] = new Entry(hash, key, value, e); 8.01/2.95 size++; 8.01/2.95 } 8.01/2.95 8.01/2.95 private abstract class HashIterator implements Iterator { 8.01/2.95 Entry next; // next entry to return 8.01/2.95 int expectedModCount; // For fast-fail 8.01/2.95 int index; // current slot 8.01/2.95 Entry current; // current entry 8.01/2.95 8.01/2.95 HashIterator() { 8.01/2.95 expectedModCount = modCount; 8.01/2.95 if (size > 0) { // advance to first entry 8.01/2.95 Entry[] t = table; 8.01/2.95 while (index < t.length && (next = t[index++]) == null) 8.01/2.95 ; 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 public final boolean hasNext() { 8.01/2.95 return next != null; 8.01/2.95 } 8.01/2.95 8.01/2.95 final Entry nextEntry() { 8.01/2.95 if (modCount != expectedModCount) 8.01/2.95 throw new ConcurrentModificationException(); 8.01/2.95 Entry e = next; 8.01/2.95 if (e == null) 8.01/2.95 throw new NoSuchElementException(); 8.01/2.95 8.01/2.95 if ((next = e.next) == null) { 8.01/2.95 Entry[] t = table; 8.01/2.95 while (index < t.length && (next = t[index++]) == null) 8.01/2.95 ; 8.01/2.95 } 8.01/2.95 current = e; 8.01/2.95 return e; 8.01/2.95 } 8.01/2.95 8.01/2.95 public void remove() { 8.01/2.95 if (current == null) 8.01/2.95 throw new IllegalStateException(); 8.01/2.95 if (modCount != expectedModCount) 8.01/2.95 throw new ConcurrentModificationException(); 8.01/2.95 Object k = current.key; 8.01/2.95 current = null; 8.01/2.95 HashMap.this.removeEntryForKey(k); 8.01/2.95 expectedModCount = modCount; 8.01/2.95 } 8.01/2.95 8.01/2.95 } 8.01/2.95 8.01/2.95 private final class ValueIterator extends HashIterator { 8.01/2.95 public V next() { 8.01/2.95 return nextEntry().value; 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 private final class KeyIterator extends HashIterator { 8.01/2.95 public K next() { 8.01/2.95 return nextEntry().getKey(); 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 private final class EntryIterator extends HashIterator> { 8.01/2.95 public Map.Entry next() { 8.01/2.95 return nextEntry(); 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 // Subclass overrides these to alter behavior of views' iterator() method 8.01/2.95 Iterator newKeyIterator() { 8.01/2.95 return new KeyIterator(); 8.01/2.95 } 8.01/2.95 Iterator newValueIterator() { 8.01/2.95 return new ValueIterator(); 8.01/2.95 } 8.01/2.95 Iterator> newEntryIterator() { 8.01/2.95 return new EntryIterator(); 8.01/2.95 } 8.01/2.95 8.01/2.95 8.01/2.95 // Views 8.01/2.95 8.01/2.95 private transient Set> entrySet = null; 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns a {@link Set} view of the keys contained in this map. 8.01/2.95 * The set is backed by the map, so changes to the map are 8.01/2.95 * reflected in the set, and vice-versa. If the map is modified 8.01/2.95 * while an iteration over the set is in progress (except through 8.01/2.95 * the iterator's own remove operation), the results of 8.01/2.95 * the iteration are undefined. The set supports element removal, 8.01/2.95 * which removes the corresponding mapping from the map, via the 8.01/2.95 * Iterator.remove, Set.remove, 8.01/2.95 * removeAll, retainAll, and clear 8.01/2.95 * operations. It does not support the add or addAll 8.01/2.95 * operations. 8.01/2.95 */ 8.01/2.95 public Set keySet() { 8.01/2.95 Set ks = keySet; 8.01/2.95 return (ks != null ? ks : (keySet = new KeySet())); 8.01/2.95 } 8.01/2.95 8.01/2.95 private final class KeySet extends AbstractSet { 8.01/2.95 public Iterator iterator() { 8.01/2.95 return newKeyIterator(); 8.01/2.95 } 8.01/2.95 public int size() { 8.01/2.95 return size; 8.01/2.95 } 8.01/2.95 public boolean contains(Object o) { 8.01/2.95 return containsKey(o); 8.01/2.95 } 8.01/2.95 public boolean remove(Object o) { 8.01/2.95 return HashMap.this.removeEntryForKey(o) != null; 8.01/2.95 } 8.01/2.95 public void clear() { 8.01/2.95 HashMap.this.clear(); 8.01/2.95 } 8.01/2.95 public Object[] toArray() { 8.01/2.95 Object[] res = new Object[size]; 8.01/2.95 Iterator it = iterator(); 8.01/2.95 int i = 0; 8.01/2.95 while (it.hasNext()) 8.01/2.95 res[i++] = it.next(); 8.01/2.95 return res; 8.01/2.95 } 8.01/2.95 public T[] toArray(T[] a) { 8.01/2.95 a = (T[])java.lang.reflect.Array.newInstance( 8.01/2.95 a.getClass().getComponentType(), size); 8.01/2.95 Object[] res = a; 8.01/2.95 Iterator it = iterator(); 8.01/2.95 int i = 0; 8.01/2.95 while (it.hasNext()) 8.01/2.95 res[i++] = it.next(); 8.01/2.95 return a; 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns a {@link Collection} view of the values contained in this map. 8.01/2.95 * The collection is backed by the map, so changes to the map are 8.01/2.95 * reflected in the collection, and vice-versa. If the map is 8.01/2.95 * modified while an iteration over the collection is in progress 8.01/2.95 * (except through the iterator's own remove operation), 8.01/2.95 * the results of the iteration are undefined. The collection 8.01/2.95 * supports element removal, which removes the corresponding 8.01/2.95 * mapping from the map, via the Iterator.remove, 8.01/2.95 * Collection.remove, removeAll, 8.01/2.95 * retainAll and clear operations. It does not 8.01/2.95 * support the add or addAll operations. 8.01/2.95 */ 8.01/2.95 public Collection values() { 8.01/2.95 Collection vs = values; 8.01/2.95 return (vs != null ? vs : (values = new Values())); 8.01/2.95 } 8.01/2.95 8.01/2.95 private final class Values extends AbstractCollection { 8.01/2.95 public Iterator iterator() { 8.01/2.95 return newValueIterator(); 8.01/2.95 } 8.01/2.95 public int size() { 8.01/2.95 return size; 8.01/2.95 } 8.01/2.95 public boolean contains(Object o) { 8.01/2.95 return containsValue(o); 8.01/2.95 } 8.01/2.95 public void clear() { 8.01/2.95 HashMap.this.clear(); 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 /** 8.01/2.95 * Returns a {@link Set} view of the mappings contained in this map. 8.01/2.95 * The set is backed by the map, so changes to the map are 8.01/2.95 * reflected in the set, and vice-versa. If the map is modified 8.01/2.95 * while an iteration over the set is in progress (except through 8.01/2.95 * the iterator's own remove operation, or through the 8.01/2.95 * setValue operation on a map entry returned by the 8.01/2.95 * iterator) the results of the iteration are undefined. The set 8.01/2.95 * supports element removal, which removes the corresponding 8.01/2.95 * mapping from the map, via the Iterator.remove, 8.01/2.95 * Set.remove, removeAll, retainAll and 8.01/2.95 * clear operations. It does not support the 8.01/2.95 * add or addAll operations. 8.01/2.95 * 8.01/2.95 * @return a set view of the mappings contained in this map 8.01/2.95 */ 8.01/2.95 public Set> entrySet() { 8.01/2.95 return entrySet0(); 8.01/2.95 } 8.01/2.95 8.01/2.95 private Set> entrySet0() { 8.01/2.95 Set> es = entrySet; 8.01/2.95 return es != null ? es : (entrySet = new EntrySet()); 8.01/2.95 } 8.01/2.95 8.01/2.95 private final class EntrySet extends AbstractSet> { 8.01/2.95 public Iterator> iterator() { 8.01/2.95 return newEntryIterator(); 8.01/2.95 } 8.01/2.95 public boolean contains(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 Entry candidate = getEntry(e.getKey()); 8.01/2.95 return candidate != null && candidate.equals(e); 8.01/2.95 } 8.01/2.95 public boolean remove(Object o) { 8.01/2.95 return removeMapping(o) != null; 8.01/2.95 } 8.01/2.95 public int size() { 8.01/2.95 return size; 8.01/2.95 } 8.01/2.95 public void clear() { 8.01/2.95 HashMap.this.clear(); 8.01/2.95 } 8.01/2.95 public Object[] toArray() { 8.01/2.95 Object[] res = new Object[size]; 8.01/2.95 Iterator> it = iterator(); 8.01/2.95 int i = 0; 8.01/2.95 while (it.hasNext()) 8.01/2.95 res[i++] = it.next(); 8.01/2.95 return res; 8.01/2.95 } 8.01/2.95 public T[] toArray(T[] a) { 8.01/2.95 a = (T[])java.lang.reflect.Array.newInstance( 8.01/2.95 a.getClass().getComponentType(), size); 8.01/2.95 Object[] res = a; 8.01/2.95 Iterator> it = iterator(); 8.01/2.95 int i = 0; 8.01/2.95 while (it.hasNext()) 8.01/2.95 res[i++] = it.next(); 8.01/2.95 return a; 8.01/2.95 } 8.01/2.95 } 8.01/2.95 8.01/2.95 private static final long serialVersionUID = 362498820763181265L; 8.01/2.95 } 8.01/2.95 8.01/2.95 8.01/2.95 /* 8.01/2.95 * Copyright 1994-2003 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 * Thrown to indicate that a method has been passed an illegal or 8.01/2.95 * inappropriate argument. 8.01/2.95 * 8.01/2.95 * @author unascribed 8.01/2.95 * @see java.lang.Thread#setPriority(int) 8.01/2.95 * @since JDK1.0 8.01/2.95 */ 8.01/2.95 public 8.01/2.95 class IllegalArgumentException extends RuntimeException { 8.01/2.96 /** 8.01/2.96 * Constructs an 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 *

Note that the detail message associated with 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 *

Note that the detail message associated with 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 *

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 { 8.01/2.96 /** 8.01/2.96 * Returns {@code true} if the iteration has more elements. 8.01/2.96 * (In other words, returns {@code true} if {@link #next} would 8.01/2.96 * return an element rather than throwing an exception.) 8.01/2.96 * 8.01/2.96 * @return {@code true} if the iteration has more elements 8.01/2.96 */ 8.01/2.96 boolean hasNext(); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns the next element in the iteration. 8.01/2.96 * 8.01/2.96 * @return the next element in the iteration 8.01/2.96 * @throws NoSuchElementException if the iteration has no more elements 8.01/2.96 */ 8.01/2.96 E next(); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Removes from the underlying collection the last element returned 8.01/2.96 * by this iterator (optional operation). This method can be called 8.01/2.96 * only once per call to {@link #next}. The behavior of an iterator 8.01/2.96 * is unspecified if the underlying collection is modified while the 8.01/2.96 * iteration is in progress in any way other than by calling this 8.01/2.96 * method. 8.01/2.96 * 8.01/2.96 * @throws UnsupportedOperationException if the {@code remove} 8.01/2.96 * operation is not supported by this iterator 8.01/2.96 * 8.01/2.96 * @throws IllegalStateException if the {@code next} method has not 8.01/2.96 * yet been called, or the {@code remove} method has already 8.01/2.96 * been called after the last call to the {@code next} 8.01/2.96 * method 8.01/2.96 */ 8.01/2.96 void remove(); 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 juHashMapCreatePutAll { 8.01/2.96 public static void main(String[] args) { 8.01/2.96 Random.args = args; 8.01/2.96 8.01/2.96 HashMap m1 = createMap(Random.random()); 8.01/2.96 HashMap m2 = createMap(Random.random()); 8.01/2.96 m1.putAll(m2); 8.01/2.96 } 8.01/2.96 8.01/2.96 public static HashMap createMap(int n) { 8.01/2.96 HashMap m = new HashMap(); 8.01/2.96 while (n > 0) { 8.01/2.96 Content key = new Content(Random.random()); 8.01/2.96 Content val = new Content(Random.random()); 8.01/2.96 m.put(key, val); 8.01/2.96 n--; 8.01/2.96 } 8.01/2.96 return m; 8.01/2.96 } 8.01/2.96 } 8.01/2.96 8.01/2.96 final class Content { 8.01/2.96 int val; 8.01/2.96 8.01/2.96 public Content(int v) { 8.01/2.96 this.val = v; 8.01/2.96 } 8.01/2.96 8.01/2.96 public int hashCode() { 8.01/2.96 return val^31; 8.01/2.96 } 8.01/2.96 8.01/2.96 public boolean equals(Object o) { 8.01/2.96 if (o instanceof Content) { 8.01/2.96 return this.val == ((Content) o).val; 8.01/2.96 } 8.01/2.96 return false; 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 * An object that maps keys to values. A map cannot contain duplicate keys; 8.01/2.96 * each key can map to at most one value. 8.01/2.96 * 8.01/2.96 *

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 the type of keys maintained by this map 8.01/2.96 * @param the type of mapped values 8.01/2.96 * 8.01/2.96 * @author Josh Bloch 8.01/2.96 * @see HashMap 8.01/2.96 * @see TreeMap 8.01/2.96 * @see Hashtable 8.01/2.96 * @see SortedMap 8.01/2.96 * @see Collection 8.01/2.96 * @see Set 8.01/2.96 * @since 1.2 8.01/2.96 */ 8.01/2.96 public interface Map { 8.01/2.96 // Query Operations 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns the number of key-value mappings in this map. If the 8.01/2.96 * map contains more than Integer.MAX_VALUE elements, returns 8.01/2.96 * Integer.MAX_VALUE. 8.01/2.96 * 8.01/2.96 * @return the number of key-value mappings in this map 8.01/2.96 */ 8.01/2.96 int size(); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns true if this map contains no key-value mappings. 8.01/2.96 * 8.01/2.96 * @return true if this map contains no key-value mappings 8.01/2.96 */ 8.01/2.96 boolean isEmpty(); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns true if this map contains a mapping for the specified 8.01/2.96 * key. More formally, returns true if and only if 8.01/2.96 * this map contains a mapping for a key k such that 8.01/2.96 * (key==null ? k==null : key.equals(k)). (There can be 8.01/2.96 * at most one such mapping.) 8.01/2.96 * 8.01/2.96 * @param key key whose presence in this map is to be tested 8.01/2.96 * @return true if this map contains a mapping for the specified 8.01/2.96 * 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 boolean containsKey(Object key); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns true if this map maps one or more keys to the 8.01/2.96 * specified value. More formally, returns true if and only if 8.01/2.96 * this map contains at least one mapping to a value v such that 8.01/2.96 * (value==null ? v==null : value.equals(v)). This operation 8.01/2.96 * will probably require time linear in the map size for most 8.01/2.96 * implementations of the Map interface. 8.01/2.96 * 8.01/2.96 * @param value value whose presence in this map is to be tested 8.01/2.96 * @return true if this map maps one or more keys to the 8.01/2.96 * specified value 8.01/2.96 * @throws ClassCastException if the value is of an inappropriate type for 8.01/2.96 * this map (optional) 8.01/2.96 * @throws NullPointerException if the specified value is null and this 8.01/2.96 * map does not permit null values (optional) 8.01/2.96 */ 8.01/2.96 boolean containsValue(Object value); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns the value to which the specified key is mapped, 8.01/2.96 * or {@code null} if this map contains no mapping for the key. 8.01/2.96 * 8.01/2.96 *

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 * (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 *

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 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 keySet(); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns a {@link Collection} view of the values contained in this map. 8.01/2.96 * The collection is backed by the map, so changes to the map are 8.01/2.96 * reflected in the collection, and vice-versa. If the map is 8.01/2.96 * modified while an iteration over the collection is in progress 8.01/2.96 * (except through the iterator's own remove operation), 8.01/2.96 * the results of the iteration are undefined. The collection 8.01/2.96 * supports element removal, which removes the corresponding 8.01/2.96 * mapping from the map, via the Iterator.remove, 8.01/2.96 * Collection.remove, removeAll, 8.01/2.96 * retainAll and clear operations. It does not 8.01/2.96 * support the add or addAll operations. 8.01/2.96 * 8.01/2.96 * @return a collection view of the values contained in this map 8.01/2.96 */ 8.01/2.96 Collection values(); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns a {@link Set} view of the mappings 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, or through the 8.01/2.96 * setValue operation on a map entry returned by the 8.01/2.96 * iterator) the results of the iteration are undefined. The set 8.01/2.96 * supports element removal, which removes the corresponding 8.01/2.96 * mapping from the map, via the Iterator.remove, 8.01/2.96 * Set.remove, removeAll, retainAll and 8.01/2.96 * clear operations. It does not support the 8.01/2.96 * add or addAll operations. 8.01/2.96 * 8.01/2.96 * @return a set view of the mappings contained in this map 8.01/2.96 */ 8.01/2.96 Set> entrySet(); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * A map entry (key-value pair). The Map.entrySet method returns 8.01/2.96 * a collection-view of the map, whose elements are of this class. The 8.01/2.96 * only way to obtain a reference to a map entry is from the 8.01/2.96 * iterator of this collection-view. These Map.Entry objects are 8.01/2.96 * valid only for the duration of the iteration; more formally, 8.01/2.96 * the behavior of a map entry is undefined if the backing map has been 8.01/2.96 * modified after the entry was returned by the iterator, except through 8.01/2.96 * the setValue operation on the map entry. 8.01/2.96 * 8.01/2.96 * @see Map#entrySet() 8.01/2.96 * @since 1.2 8.01/2.96 */ 8.01/2.96 interface Entry { 8.01/2.96 /** 8.01/2.96 * Returns the key corresponding to this entry. 8.01/2.96 * 8.01/2.96 * @return the key corresponding to this entry 8.01/2.96 * @throws IllegalStateException implementations may, but are not 8.01/2.96 * required to, throw this exception if the entry has been 8.01/2.96 * removed from the backing map. 8.01/2.96 */ 8.01/2.96 K getKey(); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns the value corresponding to this entry. If the mapping 8.01/2.96 * has been removed from the backing map (by the iterator's 8.01/2.96 * remove operation), the results of this call are undefined. 8.01/2.96 * 8.01/2.96 * @return the value corresponding to this entry 8.01/2.96 * @throws IllegalStateException implementations may, but are not 8.01/2.96 * required to, throw this exception if the entry has been 8.01/2.96 * removed from the backing map. 8.01/2.96 */ 8.01/2.96 V getValue(); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Replaces the value corresponding to this entry with the specified 8.01/2.96 * value (optional operation). (Writes through to the map.) The 8.01/2.96 * behavior of this call is undefined if the mapping has already been 8.01/2.96 * removed from the map (by the iterator's remove operation). 8.01/2.96 * 8.01/2.96 * @param value new value to be stored in this entry 8.01/2.96 * @return old value corresponding to the entry 8.01/2.96 * @throws UnsupportedOperationException if the put operation 8.01/2.96 * is not supported by the backing map 8.01/2.96 * @throws ClassCastException if the class of the specified value 8.01/2.96 * prevents it from being stored in the backing map 8.01/2.96 * @throws NullPointerException if the backing map does not permit 8.01/2.96 * null values, and the specified value is null 8.01/2.96 * @throws IllegalArgumentException if some property of this value 8.01/2.96 * prevents it from being stored in the backing map 8.01/2.96 * @throws IllegalStateException implementations may, but are not 8.01/2.96 * required to, throw this exception if the entry has been 8.01/2.96 * removed from the backing map. 8.01/2.96 */ 8.01/2.96 V setValue(V value); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Compares the specified object with this entry for equality. 8.01/2.96 * Returns true if the given object is also a map entry and 8.01/2.96 * the two entries represent the same mapping. More formally, two 8.01/2.96 * entries e1 and e2 represent the same mapping 8.01/2.96 * if

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 *

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 type of elements maintained by this set 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 * @see List 8.01/2.96 * @see SortedSet 8.01/2.96 * @see HashSet 8.01/2.96 * @see TreeSet 8.01/2.96 * @see AbstractSet 8.01/2.96 * @see Collections#singleton(java.lang.Object) 8.01/2.96 * @see Collections#EMPTY_SET 8.01/2.96 * @since 1.2 8.01/2.96 */ 8.01/2.96 8.01/2.96 public interface Set extends Collection { 8.01/2.96 // Query Operations 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns the number of elements in this set (its cardinality). If this 8.01/2.96 * set contains more than Integer.MAX_VALUE elements, returns 8.01/2.96 * Integer.MAX_VALUE. 8.01/2.96 * 8.01/2.96 * @return the number of elements in this set (its cardinality) 8.01/2.96 */ 8.01/2.96 int size(); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns true if this set contains no elements. 8.01/2.96 * 8.01/2.96 * @return true if this set contains no elements 8.01/2.96 */ 8.01/2.96 boolean isEmpty(); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns true if this set contains the specified element. 8.01/2.96 * More formally, returns true if and only if this set 8.01/2.96 * contains an element e such that 8.01/2.96 * (o==null ? e==null : o.equals(e)). 8.01/2.96 * 8.01/2.96 * @param o element whose presence in this set is to be tested 8.01/2.96 * @return true if this set contains 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 */ 8.01/2.96 boolean contains(Object o); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns an iterator over the elements in this set. The elements are 8.01/2.96 * returned in no particular order (unless this set is an instance of some 8.01/2.96 * class that provides a guarantee). 8.01/2.96 * 8.01/2.96 * @return an iterator over the elements in this set 8.01/2.96 */ 8.01/2.96 Iterator iterator(); 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns an array containing all of the elements in this set. 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 8.01/2.96 * elements in the same order. 8.01/2.96 * 8.01/2.96 *

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 *

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 T[] toArray(T[] a); 8.01/2.96 8.01/2.96 8.01/2.96 // Modification Operations 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Adds the specified element to this set if it is not already present 8.01/2.96 * (optional operation). More formally, adds the specified element 8.01/2.96 * e to this set if the set contains no element e2 8.01/2.96 * such that 8.01/2.96 * (e==null ? e2==null : e.equals(e2)). 8.01/2.96 * If this set already contains the element, the call leaves the set 8.01/2.96 * unchanged and returns false. In combination with the 8.01/2.96 * restriction on constructors, this ensures that sets never contain 8.01/2.96 * duplicate elements. 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 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 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.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 implements Collection { 8.01/2.96 /** 8.01/2.96 * Sole constructor. (For invocation by subclass constructors, typically 8.01/2.96 * implicit.) 8.01/2.96 */ 8.01/2.96 protected AbstractCollection() { 8.01/2.96 } 8.01/2.96 8.01/2.96 // Query Operations 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns an iterator over the elements contained in this collection. 8.01/2.96 * 8.01/2.96 * @return an iterator over the elements contained in this collection 8.01/2.96 */ 8.01/2.96 public abstract Iterator iterator(); 8.01/2.96 8.01/2.96 public abstract int size(); 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 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 e = iterator(); 8.01/2.96 if (o==null) { 8.01/2.96 while (e.hasNext()) 8.01/2.96 if (e.next()==null) 8.01/2.96 return true; 8.01/2.96 } else { 8.01/2.96 while (e.hasNext()) 8.01/2.96 if (o.equals(e.next())) 8.01/2.96 return true; 8.01/2.96 } 8.01/2.96 return false; 8.01/2.96 } 8.01/2.96 8.01/2.96 // Modification Operations 8.01/2.96 8.01/2.96 /** 8.01/2.96 * {@inheritDoc} 8.01/2.96 * 8.01/2.96 *

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 e = iterator(); 8.01/2.96 if (o==null) { 8.01/2.96 while (e.hasNext()) { 8.01/2.96 if (e.next()==null) { 8.01/2.96 e.remove(); 8.01/2.96 return true; 8.01/2.96 } 8.01/2.96 } 8.01/2.96 } else { 8.01/2.96 while (e.hasNext()) { 8.01/2.96 if (o.equals(e.next())) { 8.01/2.96 e.remove(); 8.01/2.96 return true; 8.01/2.96 } 8.01/2.96 } 8.01/2.96 } 8.01/2.96 return false; 8.01/2.96 } 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 * {@inheritDoc} 8.01/2.96 * 8.01/2.96 *

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 c) { 8.01/2.96 boolean modified = false; 8.01/2.96 Iterator 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 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, 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 e = iterator(); 8.01/2.96 while (e.hasNext()) { 8.01/2.96 e.next(); 8.01/2.96 e.remove(); 8.01/2.96 } 8.01/2.96 } 8.01/2.96 8.01/2.96 8.01/2.96 // String conversion 8.01/2.96 8.01/2.96 /** 8.01/2.96 * Returns a string representation of this collection. The string 8.01/2.96 * representation consists of a list of the collection's elements in the 8.01/2.96 * order they are returned by its iterator, enclosed in square brackets 8.01/2.96 * ("[]"). Adjacent elements are separated by the characters 8.01/2.96 * ", " (comma and space). Elements are converted to strings as 8.01/2.96 * by {@link String#valueOf(Object)}. 8.01/2.96 * 8.01/2.96 * @return a string representation of this collection 8.01/2.96 */ 8.01/2.96 public String toString() { 8.01/2.96 Iterator i = iterator(); 8.01/2.96 if (! i.hasNext()) 8.01/2.96 return "[]"; 8.01/2.96 8.01/2.96 String sb = ""; 8.01/2.96 sb = sb + "["; 8.01/2.96 for (;;) { 8.01/2.96 E e = i.next(); 8.01/2.96 sb = sb + (e == this ? "(this Collection)" : e); 8.01/2.96 if (! i.hasNext()) { 8.01/2.96 sb = sb + "]"; 8.01/2.96 return sb; 8.01/2.96 } 8.01/2.96 sb = sb + ", "; 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 /* 8.01/2.96 * Copyright 1997-2007 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 import javaUtilEx.Map.Entry; 8.01/2.96 8.01/2.96 /** 8.01/2.96 * This class provides a skeletal implementation of the Map 8.01/2.96 * interface, to minimize the effort required to implement this interface. 8.01/2.96 * 8.01/2.96 *

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 the type of keys maintained by this map 8.01/2.96 * @param the type of mapped values 8.01/2.96 * 8.01/2.96 * @author Josh Bloch 8.01/2.96 * @author Neal Gafter 8.01/2.96 * @see Map 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 AbstractMap implements Map { 8.01/2.96 /** 8.01/2.96 * Sole constructor. (For invocation by subclass constructors, typically 8.01/2.96 * implicit.) 8.01/2.96 */ 8.01/2.96 protected AbstractMap() { 8.01/2.96 } 8.01/2.96 8.01/2.96 // Query Operations 8.01/2.96 8.01/2.96 /** 8.01/2.96 * {@inheritDoc} 8.01/2.96 * 8.01/2.96 *

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> i = entrySet().iterator(); 8.01/2.96 if (value==null) { 8.01/2.96 while (i.hasNext()) { 8.01/2.96 Entry e = i.next(); 8.01/2.96 if (e.getValue()==null) 8.01/2.96 return true; 8.01/2.96 } 8.01/2.96 } else { 8.01/2.96 while (i.hasNext()) { 8.01/2.96 Entry e = i.next(); 8.01/2.96 if (value.equals(e.getValue())) 8.01/2.96 return true; 8.01/2.96 } 8.01/2.96 } 8.01/2.96 return false; 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 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> i = entrySet().iterator(); 8.01/2.96 if (key==null) { 8.01/2.96 while (i.hasNext()) { 8.01/2.96 Entry e = i.next(); 8.01/2.96 if (e.getKey()==null) 8.01/2.96 return true; 8.01/2.96 } 8.01/2.96 } else { 8.01/2.96 while (i.hasNext()) { 8.01/2.96 Entry e = i.next(); 8.01/2.96 if (key.equals(e.getKey())) 8.01/2.96 return true; 8.01/2.96 } 8.01/2.96 } 8.01/2.96 return false; 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 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> i = entrySet().iterator(); 8.01/2.96 if (key==null) { 8.01/2.96 while (i.hasNext()) { 8.01/2.96 Entry e = i.next(); 8.01/2.96 if (e.getKey()==null) 8.01/2.96 return e.getValue(); 8.01/2.96 } 8.01/2.96 } else { 8.01/2.96 while (i.hasNext()) { 8.01/2.96 Entry e = i.next(); 8.01/2.96 if (key.equals(e.getKey())) 8.01/2.96 return e.getValue(); 8.01/2.96 } 8.01/2.96 } 8.01/2.96 return null; 8.01/2.96 } 8.01/2.96 8.01/2.96 8.01/2.96 // Modification Operations 8.01/2.96 8.01/2.96 /** 8.01/2.96 * {@inheritDoc} 8.01/2.96 * 8.01/2.96 *

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> i = entrySet().iterator(); 8.01/2.96 Entry correctEntry = null; 8.01/2.96 if (key==null) { 8.01/2.96 while (correctEntry==null && i.hasNext()) { 8.01/2.96 Entry e = i.next(); 8.01/2.96 if (e.getKey()==null) 8.01/2.96 correctEntry = e; 8.01/2.96 } 8.01/2.96 } else { 8.01/2.96 while (correctEntry==null && i.hasNext()) { 8.01/2.96 Entry e = i.next(); 8.01/2.96 if (key.equals(e.getKey())) 8.01/2.96 correctEntry = e; 8.01/2.96 } 8.01/2.96 } 8.01/2.96 8.01/2.96 V oldValue = null; 8.01/2.96 if (correctEntry !=null) { 8.01/2.96 oldValue = correctEntry.getValue(); 8.01/2.96 i.remove(); 8.01/2.96 } 8.01/2.96 return oldValue; 8.01/2.96 } 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 * {@inheritDoc} 8.01/2.96 * 8.01/2.96 *

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 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 keySet = null; 8.01/2.96 transient volatile Collection values = null; 8.01/2.96 8.01/2.96 /** 8.01/2.96 * {@inheritDoc} 8.01/2.96 * 8.01/2.96 *

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 keySet() { 8.01/2.96 if (keySet == null) { 8.01/2.96 keySet = new AbstractSet() { 8.01/2.96 public Iterator iterator() { 8.01/2.96 return new Iterator() { 8.01/2.96 private Iterator> i = entrySet().iterator(); 8.01/2.96 8.01/2.96 public boolean hasNext() { 8.01/2.96 return i.hasNext(); 8.01/2.96 } 8.01/2.96 8.01/2.96 public K next() { 8.01/2.96 return i.next().getKey(); 8.01/2.96 } 8.01/2.96 8.01/2.96 public void remove() { 8.01/2.96 i.remove(); 8.01/2.96 } 8.01/2.96 }; 8.01/2.96 } 8.01/2.96 8.01/2.96 public int size() { 8.01/2.96 return AbstractMap.this.size(); 8.01/2.96 } 8.01/2.96 8.01/2.96 public boolean isEmpty() { 8.01/2.96 return AbstractMap.this.isEmpty(); 8.01/2.96 } 8.01/2.96 8.01/2.96 public void clear() { 8.01/2.96 AbstractMap.this.clear(); 8.01/2.96 } 8.01/2.96 8.01/2.96 public boolean contains(Object k) { 8.01/2.96 return AbstractMap.this.containsKey(k); 8.01/2.96 } 8.01/2.96 8.01/2.96 public Object[] toArray() { 8.01/2.96 Object[] res = new Object[AbstractMap.this.size()]; 8.01/2.96 Iterator> it = entrySet().iterator(); 8.01/2.96 int i = 0; 8.01/2.96 while (it.hasNext()) 8.01/2.96 res[i++] = it.next().getKey(); 8.01/2.96 return res; 8.01/2.96 } 8.01/2.96 8.01/2.96 public T[] toArray(T[] a) { 8.01/2.96 a = (T[])java.lang.reflect.Array.newInstance( 8.01/2.96 a.getClass().getComponentType(), AbstractMap.this.size()); 8.01/2.96 Object[] res = a; 8.01/2.96 Iterator> it = entrySet().iterator(); 8.01/2.96 int i = 0; 8.01/2.96 while (it.hasNext()) 8.01/2.96 res[i++] = it.next().getKey(); 8.01/2.96 return a; 8.01/2.96 } 8.01/2.96 }; 8.01/2.96 } 8.01/2.96 return keySet; 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 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 values() { 8.01/2.96 if (values == null) { 8.01/2.96 values = new AbstractCollection() { 8.01/2.96 public Iterator iterator() { 8.01/2.96 return new Iterator() { 8.01/2.96 private Iterator> i = entrySet().iterator(); 8.01/2.96 8.01/2.96 public boolean hasNext() { 8.01/2.96 return i.hasNext(); 8.01/2.96 } 8.01/2.96 8.01/2.96 public V next() { 8.01/2.96 return i.next().getValue(); 8.01/2.96 } 8.01/2.96 8.01/2.96 public void remove() { 8.01/2.96 i.remove(); 8.01/2.96 } 8.01/2.96 }; 8.01/2.96 } 8.01/2.96 8.01/2.96 public int size() { 8.01/2.96 return AbstractMap.this.size(); 8.01/2.96 } 8.01/2.96 8.01/2.96 public boolean isEmpty() { 8.01/2.96 return AbstractMap.this.isEmpty(); 8.01/2.96 } 8.01/2.96 8.01/2.96 public void clear() { 8.01/2.96 AbstractMap.this.clear(); 8.01/2.96 } 8.01/2.96 8.01/2.96 public boolean contains(Object v) { 8.01/2.96 return AbstractMap.this.containsValue(v); 8.01/2.96 } 8.01/2.96 }; 8.01/2.96 } 8.01/2.96 return values; 8.01/2.96 } 8.01/2.96 8.01/2.96 public abstract Set> entrySet(); 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.97 * true if the given object is also a map and the two maps 8.01/2.97 * represent the same mappings. More formally, two maps m1 and 8.01/2.97 * m2 represent the same mappings if 8.01/2.97 * m1.entrySet().equals(m2.entrySet()). This ensures that the 8.01/2.97 * equals method works properly across different implementations 8.01/2.97 * of the Map interface. 8.01/2.97 * 8.01/2.97 *

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 m = (Map) o; 8.01/2.97 if (m.size() != size()) 8.01/2.97 return false; 8.01/2.97 8.01/2.97 try { 8.01/2.97 Iterator> i = entrySet().iterator(); 8.01/2.97 while (i.hasNext()) { 8.01/2.97 Entry e = i.next(); 8.01/2.97 K key = e.getKey(); 8.01/2.97 V value = e.getValue(); 8.01/2.97 if (value == null) { 8.01/2.97 if (!(m.get(key)==null && m.containsKey(key))) 8.01/2.97 return false; 8.01/2.97 } else { 8.01/2.97 if (!value.equals(m.get(key))) 8.01/2.97 return false; 8.01/2.97 } 8.01/2.97 } 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 return true; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns the hash code value for this map. The hash code of a map is 8.01/2.97 * defined to be the sum of the hash codes of each entry in the map's 8.01/2.97 * entrySet() view. This ensures that m1.equals(m2) 8.01/2.97 * implies that m1.hashCode()==m2.hashCode() for any two maps 8.01/2.97 * m1 and m2, 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 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> i = entrySet().iterator(); 8.01/2.97 while (i.hasNext()) 8.01/2.97 h += i.next().hashCode(); 8.01/2.97 return h; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns a string representation of this map. The string representation 8.01/2.97 * consists of a list of key-value mappings in the order returned by the 8.01/2.97 * map's entrySet view's iterator, enclosed in braces 8.01/2.97 * ("{}"). Adjacent mappings are separated by the characters 8.01/2.97 * ", " (comma and space). Each key-value mapping is rendered as 8.01/2.97 * the key followed by an equals sign ("=") followed by the 8.01/2.97 * associated value. Keys and values are converted to strings as by 8.01/2.97 * {@link String#valueOf(Object)}. 8.01/2.97 * 8.01/2.97 * @return a string representation of this map 8.01/2.97 */ 8.01/2.97 public String toString() { 8.01/2.97 Iterator> i = entrySet().iterator(); 8.01/2.97 if (! i.hasNext()) 8.01/2.97 return "{}"; 8.01/2.97 8.01/2.97 StringBuilder sb = new StringBuilder(); 8.01/2.97 sb.append('{'); 8.01/2.97 for (;;) { 8.01/2.97 Entry e = i.next(); 8.01/2.97 K key = e.getKey(); 8.01/2.97 V value = e.getValue(); 8.01/2.97 sb.append(key == this ? "(this Map)" : key); 8.01/2.97 sb.append('='); 8.01/2.97 sb.append(value == this ? "(this Map)" : value); 8.01/2.97 if (! i.hasNext()) 8.01/2.97 return sb.append('}').toString(); 8.01/2.97 sb.append(", "); 8.01/2.97 } 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns a shallow copy of this AbstractMap instance: the keys 8.01/2.97 * and values themselves are not cloned. 8.01/2.97 * 8.01/2.97 * @return a shallow copy of this map 8.01/2.97 */ 8.01/2.97 protected Object clone() throws CloneNotSupportedException { 8.01/2.97 AbstractMap result = (AbstractMap)super.clone(); 8.01/2.97 result.keySet = null; 8.01/2.97 result.values = null; 8.01/2.97 return result; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Utility method for SimpleEntry and SimpleImmutableEntry. 8.01/2.97 * Test for equality, checking for nulls. 8.01/2.97 */ 8.01/2.97 private static boolean eq(Object o1, Object o2) { 8.01/2.97 return o1 == null ? o2 == null : o1.equals(o2); 8.01/2.97 } 8.01/2.97 8.01/2.97 // Implementation Note: SimpleEntry and SimpleImmutableEntry 8.01/2.97 // are distinct unrelated classes, even though they share 8.01/2.97 // some code. Since you can't add or subtract final-ness 8.01/2.97 // of a field in a subclass, they can't share representations, 8.01/2.97 // and the amount of duplicated code is too small to warrant 8.01/2.97 // exposing a common abstract class. 8.01/2.97 8.01/2.97 8.01/2.97 /** 8.01/2.97 * An Entry maintaining a key and a value. The value may be 8.01/2.97 * changed using the setValue method. This class 8.01/2.97 * facilitates the process of building custom map 8.01/2.97 * implementations. For example, it may be convenient to return 8.01/2.97 * arrays of SimpleEntry instances in method 8.01/2.97 * Map.entrySet().toArray. 8.01/2.97 * 8.01/2.97 * @since 1.6 8.01/2.97 */ 8.01/2.97 public static class SimpleEntry 8.01/2.97 implements Entry, java.io.Serializable 8.01/2.97 { 8.01/2.97 private static final long serialVersionUID = -8499721149061103585L; 8.01/2.97 8.01/2.97 private final K key; 8.01/2.97 private V value; 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Creates an entry representing a mapping from the specified 8.01/2.97 * key to the specified value. 8.01/2.97 * 8.01/2.97 * @param key the key represented by this entry 8.01/2.97 * @param value the value represented by this entry 8.01/2.97 */ 8.01/2.97 public SimpleEntry(K key, V value) { 8.01/2.97 this.key = key; 8.01/2.97 this.value = value; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Creates an entry representing the same mapping as the 8.01/2.97 * specified entry. 8.01/2.97 * 8.01/2.97 * @param entry the entry to copy 8.01/2.97 */ 8.01/2.97 public SimpleEntry(Entry entry) { 8.01/2.97 this.key = entry.getKey(); 8.01/2.97 this.value = entry.getValue(); 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns the key corresponding to this entry. 8.01/2.97 * 8.01/2.97 * @return the key corresponding to this entry 8.01/2.97 */ 8.01/2.97 public K getKey() { 8.01/2.97 return key; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns the value corresponding to this entry. 8.01/2.97 * 8.01/2.97 * @return the value corresponding to this entry 8.01/2.97 */ 8.01/2.97 public V getValue() { 8.01/2.97 return value; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Replaces the value corresponding to this entry with the specified 8.01/2.97 * value. 8.01/2.97 * 8.01/2.97 * @param value new value to be stored in this entry 8.01/2.97 * @return the old value corresponding to the entry 8.01/2.97 */ 8.01/2.97 public V setValue(V value) { 8.01/2.97 V oldValue = this.value; 8.01/2.97 this.value = value; 8.01/2.97 return oldValue; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Compares the specified object with this entry for equality. 8.01/2.97 * Returns {@code true} if the given object is also a map entry and 8.01/2.97 * the two entries represent the same mapping. More formally, two 8.01/2.97 * entries {@code e1} and {@code e2} represent the same mapping 8.01/2.97 * if

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 implements Entry, java.io.Serializable 8.01/2.97 { 8.01/2.97 private static final long serialVersionUID = 7138329143949025153L; 8.01/2.97 8.01/2.97 private final K key; 8.01/2.97 private final V value; 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Creates an entry representing a mapping from the specified 8.01/2.97 * key to the specified value. 8.01/2.97 * 8.01/2.97 * @param key the key represented by this entry 8.01/2.97 * @param value the value represented by this entry 8.01/2.97 */ 8.01/2.97 public SimpleImmutableEntry(K key, V value) { 8.01/2.97 this.key = key; 8.01/2.97 this.value = value; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Creates an entry representing the same mapping as the 8.01/2.97 * specified entry. 8.01/2.97 * 8.01/2.97 * @param entry the entry to copy 8.01/2.97 */ 8.01/2.97 public SimpleImmutableEntry(Entry entry) { 8.01/2.97 this.key = entry.getKey(); 8.01/2.97 this.value = entry.getValue(); 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns the key corresponding to this entry. 8.01/2.97 * 8.01/2.97 * @return the key corresponding to this entry 8.01/2.97 */ 8.01/2.97 public K getKey() { 8.01/2.97 return key; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns the value corresponding to this entry. 8.01/2.97 * 8.01/2.97 * @return the value corresponding to this entry 8.01/2.97 */ 8.01/2.97 public V getValue() { 8.01/2.97 return value; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Replaces the value corresponding to this entry with the specified 8.01/2.97 * value (optional operation). This implementation simply throws 8.01/2.97 * UnsupportedOperationException, as this class implements 8.01/2.97 * an immutable map entry. 8.01/2.97 * 8.01/2.97 * @param value new value to be stored in this entry 8.01/2.97 * @return (Does not return) 8.01/2.97 * @throws UnsupportedOperationException always 8.01/2.97 */ 8.01/2.97 public V setValue(V value) { 8.01/2.97 throw new UnsupportedOperationException(); 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Compares the specified object with this entry for equality. 8.01/2.97 * Returns {@code true} if the given object is also a map entry and 8.01/2.97 * the two entries represent the same mapping. More formally, two 8.01/2.97 * entries {@code e1} and {@code e2} represent the same mapping 8.01/2.97 * if
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.

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 the type of elements maintained by this set 8.01/2.97 * 8.01/2.97 * @author Josh Bloch 8.01/2.97 * @author Neal Gafter 8.01/2.97 * @see Collection 8.01/2.97 * @see AbstractCollection 8.01/2.97 * @see Set 8.01/2.97 * @since 1.2 8.01/2.97 */ 8.01/2.97 8.01/2.97 public abstract class AbstractSet extends AbstractCollection implements Set { 8.01/2.97 /** 8.01/2.97 * Sole constructor. (For invocation by subclass constructors, typically 8.01/2.97 * implicit.) 8.01/2.97 */ 8.01/2.97 protected AbstractSet() { 8.01/2.97 } 8.01/2.97 8.01/2.97 // Comparison and hashing 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Compares the specified object with this set for equality. Returns 8.01/2.97 * true if the given object is also a set, the two sets have 8.01/2.97 * the same size, and every member of the given set is contained in 8.01/2.97 * this set. This ensures that the equals method works 8.01/2.97 * properly across different implementations of the Set 8.01/2.97 * interface.

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 i = iterator(); 8.01/2.97 while (i.hasNext()) { 8.01/2.97 E obj = i.next(); 8.01/2.97 if (obj != null) 8.01/2.97 h += obj.hashCode(); 8.01/2.97 } 8.01/2.97 return h; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Removes from this set all of its elements that are contained in the 8.01/2.97 * specified collection (optional operation). If the specified 8.01/2.97 * collection is also a set, this operation effectively modifies this 8.01/2.97 * set so that its value is the asymmetric set difference of 8.01/2.97 * the two sets. 8.01/2.97 * 8.01/2.97 *

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.97 // Query Operations 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns the number of elements in this collection. If this collection 8.01/2.97 * contains more than Integer.MAX_VALUE elements, returns 8.01/2.97 * Integer.MAX_VALUE. 8.01/2.97 * 8.01/2.97 * @return the number of elements in this collection 8.01/2.97 */ 8.01/2.97 int size(); 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns true if this collection contains no elements. 8.01/2.97 * 8.01/2.97 * @return true if this collection contains no elements 8.01/2.97 */ 8.01/2.97 boolean isEmpty(); 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns true if this collection contains the specified element. 8.01/2.97 * More formally, 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)). 8.01/2.97 * 8.01/2.97 * @param o element whose presence in this collection is to be tested 8.01/2.97 * @return true if this collection contains the specified 8.01/2.97 * element 8.01/2.97 * @throws ClassCastException if the type of the specified element 8.01/2.97 * is incompatible with this collection (optional) 8.01/2.97 * @throws NullPointerException if the specified element is null and this 8.01/2.97 * collection does not permit null elements (optional) 8.01/2.97 */ 8.01/2.97 boolean contains(Object o); 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns an iterator over the elements in this collection. There are no 8.01/2.97 * guarantees concerning the order in which the elements are returned 8.01/2.97 * (unless this collection is an instance of some class that provides a 8.01/2.97 * guarantee). 8.01/2.97 * 8.01/2.97 * @return an Iterator over the elements in this collection 8.01/2.97 */ 8.01/2.97 Iterator iterator(); 8.01/2.97 8.01/2.97 // Modification Operations 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Ensures that this collection contains the specified element (optional 8.01/2.97 * operation). Returns true if this collection changed as a 8.01/2.97 * result of the call. (Returns false if this collection does 8.01/2.97 * not permit duplicates and already contains the specified element.)

8.01/2.97 * 8.01/2.97 * Collections that support this operation may place limitations on what 8.01/2.97 * elements may be added to this collection. In particular, some 8.01/2.97 * collections will refuse to add null elements, and others will 8.01/2.97 * impose restrictions on the type of elements that may be added. 8.01/2.97 * Collection classes should clearly specify in their documentation any 8.01/2.97 * restrictions on what elements may be added.

8.01/2.97 * 8.01/2.97 * If a collection refuses to add a particular element for any reason 8.01/2.97 * other than that it already contains the element, it must throw 8.01/2.97 * an exception (rather than returning false). This preserves 8.01/2.97 * the invariant that a collection always contains the specified element 8.01/2.97 * after this call returns. 8.01/2.97 * 8.01/2.97 * @param e element whose presence in this collection is to be ensured 8.01/2.97 * @return true if this collection changed as a result of the 8.01/2.97 * call 8.01/2.97 * @throws UnsupportedOperationException if the add operation 8.01/2.97 * is not supported by this collection 8.01/2.97 * @throws ClassCastException if the class of the specified element 8.01/2.97 * prevents it from being added to this collection 8.01/2.97 * @throws NullPointerException if the specified element is null and this 8.01/2.97 * collection does not permit null elements 8.01/2.97 * @throws IllegalArgumentException if some property of the element 8.01/2.97 * prevents it from being added to this collection 8.01/2.97 * @throws IllegalStateException if the element cannot be added at this 8.01/2.97 * time due to insertion restrictions 8.01/2.97 */ 8.01/2.97 boolean add(E e); 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Removes a single instance of the specified element from this 8.01/2.97 * collection, if it is present (optional operation). More formally, 8.01/2.97 * removes an element e such that 8.01/2.97 * (o==null ? e==null : o.equals(e)), if 8.01/2.97 * this collection contains one or more such elements. Returns 8.01/2.97 * true if this collection contained the specified element (or 8.01/2.97 * equivalently, if this collection changed as a result of the call). 8.01/2.97 * 8.01/2.97 * @param o element to be removed from this collection, if present 8.01/2.97 * @return true if an element was removed as a result of this call 8.01/2.97 * @throws ClassCastException if the type of the specified element 8.01/2.97 * is incompatible with this collection (optional) 8.01/2.97 * @throws NullPointerException if the specified element is null and this 8.01/2.97 * collection does not permit null elements (optional) 8.01/2.97 * @throws UnsupportedOperationException if the remove operation 8.01/2.97 * is not supported by this collection 8.01/2.97 */ 8.01/2.97 boolean remove(Object o); 8.01/2.97 8.01/2.97 8.01/2.97 // Bulk Operations 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns true if this collection contains all of the elements 8.01/2.97 * in the specified collection. 8.01/2.97 * 8.01/2.97 * @param c collection to be checked for containment in this collection 8.01/2.97 * @return true if this collection contains all of the elements 8.01/2.97 * in the specified collection 8.01/2.97 * @throws ClassCastException if the types of one or more elements 8.01/2.97 * in the specified collection are incompatible with this 8.01/2.97 * collection (optional) 8.01/2.97 * @throws NullPointerException if the specified collection contains one 8.01/2.97 * or more null elements and this collection does not permit null 8.01/2.97 * elements (optional), or if the specified collection is null 8.01/2.97 * @see #contains(Object) 8.01/2.97 */ 8.01/2.97 boolean containsAll(Collection c); 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Adds all of the elements in the specified collection to this collection 8.01/2.97 * (optional operation). The behavior of this operation is undefined if 8.01/2.97 * the specified collection is modified while the operation is in progress. 8.01/2.97 * (This implies that the behavior of this call is undefined if the 8.01/2.97 * specified collection is this collection, and this collection is 8.01/2.97 * nonempty.) 8.01/2.97 * 8.01/2.97 * @param c collection containing elements to be added to this collection 8.01/2.97 * @return true if this collection changed as a result of the call 8.01/2.97 * @throws UnsupportedOperationException if the addAll operation 8.01/2.97 * is not supported by this collection 8.01/2.97 * @throws ClassCastException if the class of an element of the specified 8.01/2.97 * collection prevents it from being added to this collection 8.01/2.97 * @throws NullPointerException if the specified collection contains a 8.01/2.97 * null element and this collection does not permit null elements, 8.01/2.97 * or if the specified collection is null 8.01/2.97 * @throws IllegalArgumentException if some property of an element of the 8.01/2.97 * specified collection prevents it from being added to this 8.01/2.97 * collection 8.01/2.97 * @throws IllegalStateException if not all the elements can be added at 8.01/2.97 * this time due to insertion restrictions 8.01/2.97 * @see #add(Object) 8.01/2.97 */ 8.01/2.97 boolean addAll(Collection c); 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Removes all of this collection's elements that are also contained in the 8.01/2.97 * specified collection (optional operation). After this call returns, 8.01/2.97 * this collection will contain no elements in common with the specified 8.01/2.97 * collection. 8.01/2.97 * 8.01/2.97 * @param c collection containing elements to be removed from this collection 8.01/2.97 * @return true if this collection changed as a result of the 8.01/2.97 * call 8.01/2.97 * @throws UnsupportedOperationException if the removeAll method 8.01/2.97 * is not supported by this collection 8.01/2.97 * @throws ClassCastException if the types of one or more elements 8.01/2.97 * in this collection are incompatible with the specified 8.01/2.97 * collection (optional) 8.01/2.97 * @throws NullPointerException if this collection contains one or more 8.01/2.97 * null elements and the specified collection does not support 8.01/2.97 * null elements (optional), 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 boolean removeAll(Collection c); 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Retains only the elements in this collection that are contained in the 8.01/2.97 * specified collection (optional operation). In other words, removes from 8.01/2.97 * this collection all of its elements that are not contained in the 8.01/2.97 * specified collection. 8.01/2.97 * 8.01/2.97 * @param c collection containing elements to be retained in this collection 8.01/2.97 * @return true if this collection changed as a result of the call 8.01/2.97 * @throws UnsupportedOperationException if the retainAll operation 8.01/2.97 * is not supported by this collection 8.01/2.97 * @throws ClassCastException if the types of one or more elements 8.01/2.97 * in this collection are incompatible with the specified 8.01/2.97 * collection (optional) 8.01/2.97 * @throws NullPointerException if this collection contains one or more 8.01/2.97 * null elements and the specified collection does not permit null 8.01/2.97 * elements (optional), 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 boolean retainAll(Collection c); 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Removes all of the elements from this collection (optional operation). 8.01/2.97 * The collection will be empty after this method returns. 8.01/2.97 * 8.01/2.97 * @throws UnsupportedOperationException if the clear operation 8.01/2.97 * is not supported by this collection 8.01/2.97 */ 8.01/2.97 void clear(); 8.01/2.97 8.01/2.97 8.01/2.97 // Comparison and hashing 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Compares the specified object with this collection for equality.

8.01/2.97 * 8.01/2.97 * While the Collection interface adds no stipulations to the 8.01/2.97 * general contract for the Object.equals, programmers who 8.01/2.97 * implement the Collection interface "directly" (in other words, 8.01/2.97 * create a class that is a Collection but is not a Set 8.01/2.97 * or a List) must exercise care if they choose to override the 8.01/2.97 * Object.equals. It is not necessary to do so, and the simplest 8.01/2.97 * course of action is to rely on Object's implementation, but 8.01/2.97 * the implementor may wish to implement a "value comparison" in place of 8.01/2.97 * the default "reference comparison." (The List and 8.01/2.97 * Set interfaces mandate such value comparisons.)

8.01/2.97 * 8.01/2.97 * The general contract for the Object.equals method states that 8.01/2.97 * equals must be symmetric (in other words, a.equals(b) if and 8.01/2.97 * only if b.equals(a)). The contracts for List.equals 8.01/2.97 * and Set.equals state that lists are only equal to other lists, 8.01/2.97 * and sets to other sets. Thus, a custom equals method for a 8.01/2.97 * collection class that implements neither the List nor 8.01/2.97 * Set interface must return false when this collection 8.01/2.97 * is compared to any list or set. (By the same logic, it is not possible 8.01/2.97 * to write a class that correctly implements both the Set and 8.01/2.97 * List interfaces.) 8.01/2.97 * 8.01/2.97 * @param o object to be compared for equality with this collection 8.01/2.97 * @return true if the specified object is equal to this 8.01/2.97 * collection 8.01/2.97 * 8.01/2.97 * @see Object#equals(Object) 8.01/2.97 * @see Set#equals(Object) 8.01/2.97 * @see List#equals(Object) 8.01/2.97 */ 8.01/2.97 boolean equals(Object o); 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns the hash code value for this collection. While the 8.01/2.97 * Collection interface adds no stipulations to the general 8.01/2.97 * contract for the Object.hashCode method, programmers should 8.01/2.97 * take note that any class that overrides the Object.equals 8.01/2.97 * method must also override the Object.hashCode method in order 8.01/2.97 * to satisfy the general contract for the Object.hashCodemethod. 8.01/2.97 * In particular, c1.equals(c2) implies that 8.01/2.97 * c1.hashCode()==c2.hashCode(). 8.01/2.97 * 8.01/2.97 * @return the hash code value for this collection 8.01/2.97 * 8.01/2.97 * @see Object#hashCode() 8.01/2.97 * @see Object#equals(Object) 8.01/2.97 */ 8.01/2.97 int hashCode(); 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 exception may be thrown by methods that have detected concurrent 8.01/2.97 * modification of an object when such modification is not permissible. 8.01/2.97 *

8.01/2.97 * For example, it is not generally permissible for one thread to modify a Collection 8.01/2.97 * while another thread is iterating over it. In general, the results of the 8.01/2.97 * iteration are undefined under these circumstances. Some Iterator 8.01/2.97 * implementations (including those of all the general purpose collection implementations 8.01/2.97 * provided by the JRE) may choose to throw this exception if this behavior is 8.01/2.97 * detected. Iterators that do this are known as fail-fast iterators, 8.01/2.97 * as they fail quickly and cleanly, rather that risking arbitrary, 8.01/2.97 * non-deterministic behavior at an undetermined time in the future. 8.01/2.97 *

8.01/2.97 * Note that this exception does not always indicate that an object has 8.01/2.97 * been concurrently modified by a different thread. If a single 8.01/2.97 * thread issues a sequence of method invocations that violates the 8.01/2.97 * contract of an object, the object may throw this exception. For 8.01/2.97 * example, if a thread modifies a collection directly while it is 8.01/2.97 * iterating over the collection with a fail-fast iterator, the iterator 8.01/2.97 * will throw this exception. 8.01/2.97 * 8.01/2.97 *

Note that fail-fast behavior cannot be guaranteed as it is, generally 8.01/2.97 * speaking, impossible to make any hard guarantees in the presence of 8.01/2.97 * unsynchronized concurrent modification. Fail-fast operations 8.01/2.97 * throw ConcurrentModificationException on a best-effort basis. 8.01/2.97 * Therefore, it would be wrong to write a program that depended on this 8.01/2.97 * exception for its correctness: ConcurrentModificationException 8.01/2.97 * should be used only to detect bugs. 8.01/2.97 * 8.01/2.97 * @author Josh Bloch 8.01/2.97 * @see Collection 8.01/2.97 * @see Iterator 8.01/2.97 * @see ListIterator 8.01/2.97 * @see Vector 8.01/2.97 * @see LinkedList 8.01/2.97 * @see HashSet 8.01/2.97 * @see Hashtable 8.01/2.97 * @see TreeMap 8.01/2.97 * @see AbstractList 8.01/2.97 * @since 1.2 8.01/2.97 */ 8.01/2.97 public class ConcurrentModificationException extends RuntimeException { 8.01/2.97 /** 8.01/2.97 * Constructs a ConcurrentModificationException with no 8.01/2.97 * detail message. 8.01/2.97 */ 8.01/2.97 public ConcurrentModificationException() { 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Constructs a ConcurrentModificationException with the 8.01/2.97 * specified detail message. 8.01/2.97 * 8.01/2.97 * @param message the detail message pertaining to this exception. 8.01/2.97 */ 8.01/2.97 public ConcurrentModificationException(String message) { 8.01/2.97 super(message); 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-2007 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 * Hash table based implementation of the Map interface. This 8.01/2.97 * implementation provides all of the optional map operations, and permits 8.01/2.97 * null values and the null key. (The HashMap 8.01/2.97 * class is roughly equivalent to Hashtable, except that it is 8.01/2.97 * unsynchronized and permits nulls.) This class makes no guarantees as to 8.01/2.97 * the order of the map; in particular, it does not guarantee that the order 8.01/2.97 * will remain constant over time. 8.01/2.97 * 8.01/2.97 *

This implementation provides constant-time performance for the basic 8.01/2.97 * operations (get and put), assuming the hash function 8.01/2.97 * disperses the elements properly among the buckets. Iteration over 8.01/2.97 * collection views requires time proportional to the "capacity" of the 8.01/2.97 * HashMap instance (the number of buckets) plus its size (the number 8.01/2.97 * of key-value mappings). Thus, it's very important not to set the initial 8.01/2.97 * capacity too high (or the load factor too low) if iteration performance is 8.01/2.97 * important. 8.01/2.97 * 8.01/2.97 *

An instance of HashMap has two parameters that affect its 8.01/2.97 * performance: initial capacity and load factor. The 8.01/2.97 * capacity is the number of buckets in the hash table, and the initial 8.01/2.97 * capacity is simply the capacity at the time the hash table is created. The 8.01/2.97 * load factor is a measure of how full the hash table is allowed to 8.01/2.97 * get before its capacity is automatically increased. When the number of 8.01/2.97 * entries in the hash table exceeds the product of the load factor and the 8.01/2.97 * current capacity, the hash table is rehashed (that is, internal data 8.01/2.97 * structures are rebuilt) so that the hash table has approximately twice the 8.01/2.97 * number of buckets. 8.01/2.97 * 8.01/2.97 *

As a general rule, the default load factor (.75) offers a good tradeoff 8.01/2.97 * between time and space costs. Higher values decrease the space overhead 8.01/2.97 * but increase the lookup cost (reflected in most of the operations of the 8.01/2.97 * HashMap class, including get and put). The 8.01/2.97 * expected number of entries in the map and its load factor should be taken 8.01/2.97 * into account when setting its initial capacity, so as to minimize the 8.01/2.97 * number of rehash operations. If the initial capacity is greater 8.01/2.97 * than the maximum number of entries divided by the load factor, no 8.01/2.97 * rehash operations will ever occur. 8.01/2.97 * 8.01/2.97 *

If many mappings are to be stored in a HashMap instance, 8.01/2.97 * creating it with a sufficiently large capacity will allow the mappings to 8.01/2.97 * be stored more efficiently than letting it perform automatic rehashing as 8.01/2.97 * needed to grow the table. 8.01/2.97 * 8.01/2.97 *

Note that this implementation is not synchronized. 8.01/2.97 * If multiple threads access a hash map concurrently, and at least one of 8.01/2.97 * the threads modifies the map structurally, it must be 8.01/2.97 * synchronized externally. (A structural modification is any operation 8.01/2.97 * that adds or deletes one or more mappings; merely changing the value 8.01/2.97 * associated with a key that an instance already contains is not a 8.01/2.97 * structural modification.) This is typically accomplished by 8.01/2.97 * synchronizing on some object that naturally encapsulates the map. 8.01/2.97 * 8.01/2.97 * If no such object exists, the map should be "wrapped" using the 8.01/2.97 * {@link Collections#synchronizedMap Collections.synchronizedMap} 8.01/2.97 * method. This is best done at creation time, to prevent accidental 8.01/2.97 * unsynchronized access to the map:

8.01/2.97	 *   Map m = Collections.synchronizedMap(new HashMap(...));
8.01/2.97 * 8.01/2.97 *

The iterators returned by all of this class's "collection view methods" 8.01/2.97 * are fail-fast: if the map is structurally modified at any time after 8.01/2.97 * the iterator is created, in any way except through the iterator's own 8.01/2.97 * remove method, the iterator will throw a 8.01/2.97 * {@link ConcurrentModificationException}. Thus, in the face of concurrent 8.01/2.97 * modification, the iterator fails quickly and cleanly, rather than risking 8.01/2.97 * arbitrary, non-deterministic behavior at an undetermined time in the 8.01/2.97 * future. 8.01/2.97 * 8.01/2.97 *

Note that the fail-fast behavior of an iterator cannot be guaranteed 8.01/2.97 * as it is, generally speaking, impossible to make any hard guarantees in the 8.01/2.97 * presence of unsynchronized concurrent modification. Fail-fast iterators 8.01/2.97 * throw ConcurrentModificationException on a best-effort basis. 8.01/2.97 * Therefore, it would be wrong to write a program that depended on this 8.01/2.97 * exception for its correctness: the fail-fast behavior of iterators 8.01/2.97 * should be used only to detect bugs. 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 the type of keys maintained by this map 8.01/2.97 * @param the type of mapped values 8.01/2.97 * 8.01/2.97 * @author Doug Lea 8.01/2.97 * @author Josh Bloch 8.01/2.97 * @author Arthur van Hoff 8.01/2.97 * @author Neal Gafter 8.01/2.97 * @see Object#hashCode() 8.01/2.97 * @see Collection 8.01/2.97 * @see Map 8.01/2.97 * @see TreeMap 8.01/2.97 * @see Hashtable 8.01/2.97 * @since 1.2 8.01/2.97 */ 8.01/2.97 8.01/2.97 public class HashMap 8.01/2.97 extends AbstractMap 8.01/2.97 implements Map, Cloneable 8.01/2.97 { 8.01/2.97 8.01/2.97 /** 8.01/2.97 * The default initial capacity - MUST be a power of two. 8.01/2.97 */ 8.01/2.97 static final int DEFAULT_INITIAL_CAPACITY = 16; 8.01/2.97 8.01/2.97 /** 8.01/2.97 * The maximum capacity, used if a higher value is implicitly specified 8.01/2.97 * by either of the constructors with arguments. 8.01/2.97 * MUST be a power of two <= 1<<30. 8.01/2.97 */ 8.01/2.97 static final int MAXIMUM_CAPACITY = 1 << 30; 8.01/2.97 8.01/2.97 /** 8.01/2.97 * The load factor used when none specified in constructor. 8.01/2.97 */ 8.01/2.97 static final float DEFAULT_LOAD_FACTOR = 0.75f; 8.01/2.97 8.01/2.97 /** 8.01/2.97 * The table, resized as necessary. Length MUST Always be a power of two. 8.01/2.97 */ 8.01/2.97 transient Entry[] table; 8.01/2.97 8.01/2.97 /** 8.01/2.97 * The number of key-value mappings contained in this map. 8.01/2.97 */ 8.01/2.97 transient int size; 8.01/2.97 8.01/2.97 /** 8.01/2.97 * The next size value at which to resize (capacity * load factor). 8.01/2.97 * @serial 8.01/2.97 */ 8.01/2.97 int threshold; 8.01/2.97 8.01/2.97 /** 8.01/2.97 * The load factor for the hash table. 8.01/2.97 * 8.01/2.97 * @serial 8.01/2.97 */ 8.01/2.97 final float loadFactor; 8.01/2.97 8.01/2.97 /** 8.01/2.97 * The number of times this HashMap has been structurally modified 8.01/2.97 * Structural modifications are those that change the number of mappings in 8.01/2.97 * the HashMap or otherwise modify its internal structure (e.g., 8.01/2.97 * rehash). This field is used to make iterators on Collection-views of 8.01/2.97 * the HashMap fail-fast. (See ConcurrentModificationException). 8.01/2.97 */ 8.01/2.97 transient volatile int modCount; 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Constructs an empty HashMap with the specified initial 8.01/2.97 * capacity and load factor. 8.01/2.97 * 8.01/2.97 * @param initialCapacity the initial capacity 8.01/2.97 * @param loadFactor the load factor 8.01/2.97 * @throws IllegalArgumentException if the initial capacity is negative 8.01/2.97 * or the load factor is nonpositive 8.01/2.97 */ 8.01/2.97 public HashMap(int initialCapacity, float loadFactor) { 8.01/2.97 if (initialCapacity < 0) 8.01/2.97 throw new IllegalArgumentException("Illegal initial capacity: " + 8.01/2.97 initialCapacity); 8.01/2.97 if (initialCapacity > MAXIMUM_CAPACITY) 8.01/2.97 initialCapacity = MAXIMUM_CAPACITY; 8.01/2.97 if (loadFactor <= 0 || Float.isNaN(loadFactor)) 8.01/2.97 throw new IllegalArgumentException("Illegal load factor: " + 8.01/2.97 loadFactor); 8.01/2.97 8.01/2.97 // Find a power of 2 >= initialCapacity 8.01/2.97 int capacity = 1; 8.01/2.97 while (capacity < initialCapacity) 8.01/2.97 capacity <<= 1; 8.01/2.97 8.01/2.97 this.loadFactor = loadFactor; 8.01/2.97 threshold = (int)(capacity * loadFactor); 8.01/2.97 table = new Entry[capacity]; 8.01/2.97 init(); 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Constructs an empty HashMap with the specified initial 8.01/2.97 * capacity and the default load factor (0.75). 8.01/2.97 * 8.01/2.97 * @param initialCapacity the initial capacity. 8.01/2.97 * @throws IllegalArgumentException if the initial capacity is negative. 8.01/2.97 */ 8.01/2.97 public HashMap(int initialCapacity) { 8.01/2.97 this(initialCapacity, DEFAULT_LOAD_FACTOR); 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Constructs an empty HashMap with the default initial capacity 8.01/2.97 * (16) and the default load factor (0.75). 8.01/2.97 */ 8.01/2.97 public HashMap() { 8.01/2.97 this.loadFactor = DEFAULT_LOAD_FACTOR; 8.01/2.97 threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR); 8.01/2.97 table = new Entry[DEFAULT_INITIAL_CAPACITY]; 8.01/2.97 init(); 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Constructs a new HashMap with the same mappings as the 8.01/2.97 * specified Map. The HashMap is created with 8.01/2.97 * default load factor (0.75) and an initial capacity sufficient to 8.01/2.97 * hold the mappings in the specified Map. 8.01/2.97 * 8.01/2.97 * @param m the map whose mappings are to be placed in this map 8.01/2.97 * @throws NullPointerException if the specified map is null 8.01/2.97 */ 8.01/2.97 public HashMap(Map m) { 8.01/2.97 this(Math.max((int) (m.size() / DEFAULT_LOAD_FACTOR) + 1, 8.01/2.97 DEFAULT_INITIAL_CAPACITY), DEFAULT_LOAD_FACTOR); 8.01/2.97 putAllForCreate(m); 8.01/2.97 } 8.01/2.97 8.01/2.97 // internal utilities 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Initialization hook for subclasses. This method is called 8.01/2.97 * in all constructors and pseudo-constructors (clone, readObject) 8.01/2.97 * after HashMap has been initialized but before any entries have 8.01/2.97 * been inserted. (In the absence of this method, readObject would 8.01/2.97 * require explicit knowledge of subclasses.) 8.01/2.97 */ 8.01/2.97 void init() { 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Applies a supplemental hash function to a given hashCode, which 8.01/2.97 * defends against poor quality hash functions. This is critical 8.01/2.97 * because HashMap uses power-of-two length hash tables, that 8.01/2.97 * otherwise encounter collisions for hashCodes that do not differ 8.01/2.97 * in lower bits. Note: Null keys always map to hash 0, thus index 0. 8.01/2.97 */ 8.01/2.97 static int hash(int h) { 8.01/2.97 // This function ensures that hashCodes that differ only by 8.01/2.97 // constant multiples at each bit position have a bounded 8.01/2.97 // number of collisions (approximately 8 at default load factor). 8.01/2.97 h ^= (h >>> 20) ^ (h >>> 12); 8.01/2.97 return h ^ (h >>> 7) ^ (h >>> 4); 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns index for hash code h. 8.01/2.97 */ 8.01/2.97 static int indexFor(int h, int length) { 8.01/2.97 return h & (length-1); 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns the number of key-value mappings in this map. 8.01/2.97 * 8.01/2.97 * @return the number of key-value mappings in this map 8.01/2.97 */ 8.01/2.97 public int size() { 8.01/2.97 return size; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns true if this map contains no key-value mappings. 8.01/2.97 * 8.01/2.97 * @return true if this map contains no key-value mappings 8.01/2.97 */ 8.01/2.97 public boolean isEmpty() { 8.01/2.97 return size == 0; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns the value to which the specified key is mapped, 8.01/2.97 * or {@code null} if this map contains no mapping for the key. 8.01/2.97 * 8.01/2.97 *

More formally, if this map contains a mapping from a key 8.01/2.97 * {@code k} to a value {@code v} such that {@code (key==null ? k==null : 8.01/2.97 * key.equals(k))}, then this method returns {@code v}; otherwise 8.01/2.97 * it returns {@code null}. (There can be at most one such mapping.) 8.01/2.97 * 8.01/2.97 *

A return value of {@code null} does not necessarily 8.01/2.97 * indicate that the map contains no mapping for the key; it's also 8.01/2.97 * possible that the map explicitly maps the key to {@code null}. 8.01/2.97 * The {@link #containsKey containsKey} operation may be used to 8.01/2.97 * distinguish these two cases. 8.01/2.97 * 8.01/2.97 * @see #put(Object, Object) 8.01/2.97 */ 8.01/2.97 public V get(Object key) { 8.01/2.97 if (key == null) 8.01/2.97 return getForNullKey(); 8.01/2.97 int hash = hash(key.hashCode()); 8.01/2.97 for (Entry e = table[indexFor(hash, table.length)]; 8.01/2.97 e != null; 8.01/2.97 e = e.next) { 8.01/2.97 Object k; 8.01/2.97 if (e.hash == hash && ((k = e.key) == key || key.equals(k))) 8.01/2.97 return e.value; 8.01/2.97 } 8.01/2.97 return null; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Offloaded version of get() to look up null keys. Null keys map 8.01/2.97 * to index 0. This null case is split out into separate methods 8.01/2.97 * for the sake of performance in the two most commonly used 8.01/2.97 * operations (get and put), but incorporated with conditionals in 8.01/2.97 * others. 8.01/2.97 */ 8.01/2.97 private V getForNullKey() { 8.01/2.97 for (Entry e = table[0]; e != null; e = e.next) { 8.01/2.97 if (e.key == null) 8.01/2.97 return e.value; 8.01/2.97 } 8.01/2.97 return null; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns true if this map contains a mapping for the 8.01/2.97 * specified key. 8.01/2.97 * 8.01/2.97 * @param key The key whose presence in this map is to be tested 8.01/2.97 * @return true if this map contains a mapping for the specified 8.01/2.97 * key. 8.01/2.97 */ 8.01/2.97 public boolean containsKey(Object key) { 8.01/2.97 return getEntry(key) != null; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns the entry associated with the specified key in the 8.01/2.97 * HashMap. Returns null if the HashMap contains no mapping 8.01/2.97 * for the key. 8.01/2.97 */ 8.01/2.97 final Entry getEntry(Object key) { 8.01/2.97 int hash = (key == null) ? 0 : hash(key.hashCode()); 8.01/2.97 for (Entry e = table[indexFor(hash, table.length)]; 8.01/2.97 e != null; 8.01/2.97 e = e.next) { 8.01/2.97 Object k; 8.01/2.97 if (e.hash == hash && 8.01/2.97 ((k = e.key) == key || (key != null && key.equals(k)))) 8.01/2.97 return e; 8.01/2.97 } 8.01/2.97 return null; 8.01/2.97 } 8.01/2.97 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Associates the specified value with the specified key in this map. 8.01/2.97 * If the map previously contained a mapping for the key, the old 8.01/2.97 * value is replaced. 8.01/2.97 * 8.01/2.97 * @param key key with which the specified value is to be associated 8.01/2.97 * @param value value to be associated with the specified key 8.01/2.97 * @return the previous value associated with key, or 8.01/2.97 * null if there was no mapping for key. 8.01/2.97 * (A null return can also indicate that the map 8.01/2.97 * previously associated null with key.) 8.01/2.97 */ 8.01/2.97 public V put(K key, V value) { 8.01/2.97 if (key == null) 8.01/2.97 return putForNullKey(value); 8.01/2.97 int hash = hash(key.hashCode()); 8.01/2.97 int i = indexFor(hash, table.length); 8.01/2.97 for (Entry e = table[i]; e != null; e = e.next) { 8.01/2.97 Object k; 8.01/2.97 if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { 8.01/2.97 V oldValue = e.value; 8.01/2.97 e.value = value; 8.01/2.97 e.recordAccess(this); 8.01/2.97 return oldValue; 8.01/2.97 } 8.01/2.97 } 8.01/2.97 8.01/2.97 modCount++; 8.01/2.97 addEntry(hash, key, value, i); 8.01/2.97 return null; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Offloaded version of put for null keys 8.01/2.97 */ 8.01/2.97 private V putForNullKey(V value) { 8.01/2.97 for (Entry e = table[0]; e != null; e = e.next) { 8.01/2.97 if (e.key == null) { 8.01/2.97 V oldValue = e.value; 8.01/2.97 e.value = value; 8.01/2.97 e.recordAccess(this); 8.01/2.97 return oldValue; 8.01/2.97 } 8.01/2.97 } 8.01/2.97 modCount++; 8.01/2.97 addEntry(0, null, value, 0); 8.01/2.97 return null; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * This method is used instead of put by constructors and 8.01/2.97 * pseudoconstructors (clone, readObject). It does not resize the table, 8.01/2.97 * check for comodification, etc. It calls createEntry rather than 8.01/2.97 * addEntry. 8.01/2.97 */ 8.01/2.97 private void putForCreate(K key, V value) { 8.01/2.97 int hash = (key == null) ? 0 : hash(key.hashCode()); 8.01/2.97 int i = indexFor(hash, table.length); 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Look for preexisting entry for key. This will never happen for 8.01/2.97 * clone or deserialize. It will only happen for construction if the 8.01/2.97 * input Map is a sorted map whose ordering is inconsistent w/ equals. 8.01/2.97 */ 8.01/2.97 for (Entry e = table[i]; e != null; e = e.next) { 8.01/2.97 Object k; 8.01/2.97 if (e.hash == hash && 8.01/2.97 ((k = e.key) == key || (key != null && key.equals(k)))) { 8.01/2.97 e.value = value; 8.01/2.97 return; 8.01/2.97 } 8.01/2.97 } 8.01/2.97 8.01/2.97 createEntry(hash, key, value, i); 8.01/2.97 } 8.01/2.97 8.01/2.97 private void putAllForCreate(Map m) { 8.01/2.97 for (Iterator> i = m.entrySet().iterator(); i.hasNext(); ) { 8.01/2.97 Map.Entry e = i.next(); 8.01/2.97 putForCreate(e.getKey(), e.getValue()); 8.01/2.97 } 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Rehashes the contents of this map into a new array with a 8.01/2.97 * larger capacity. This method is called automatically when the 8.01/2.97 * number of keys in this map reaches its threshold. 8.01/2.97 * 8.01/2.97 * If current capacity is MAXIMUM_CAPACITY, this method does not 8.01/2.97 * resize the map, but sets threshold to Integer.MAX_VALUE. 8.01/2.97 * This has the effect of preventing future calls. 8.01/2.97 * 8.01/2.97 * @param newCapacity the new capacity, MUST be a power of two; 8.01/2.97 * must be greater than current capacity unless current 8.01/2.97 * capacity is MAXIMUM_CAPACITY (in which case value 8.01/2.97 * is irrelevant). 8.01/2.97 */ 8.01/2.97 void resize(int newCapacity) { 8.01/2.97 Entry[] oldTable = table; 8.01/2.97 int oldCapacity = oldTable.length; 8.01/2.97 if (oldCapacity == MAXIMUM_CAPACITY) { 8.01/2.97 threshold = Integer.MAX_VALUE; 8.01/2.97 return; 8.01/2.97 } 8.01/2.97 8.01/2.97 Entry[] newTable = new Entry[newCapacity]; 8.01/2.97 transfer(newTable); 8.01/2.97 table = newTable; 8.01/2.97 threshold = (int)(newCapacity * loadFactor); 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Transfers all entries from current table to newTable. 8.01/2.97 */ 8.01/2.97 void transfer(Entry[] newTable) { 8.01/2.97 Entry[] src = table; 8.01/2.97 int newCapacity = newTable.length; 8.01/2.97 for (int j = 0; j < src.length; j++) { 8.01/2.97 Entry e = src[j]; 8.01/2.97 if (e != null) { 8.01/2.97 src[j] = null; 8.01/2.97 do { 8.01/2.97 Entry next = e.next; 8.01/2.97 int i = indexFor(e.hash, newCapacity); 8.01/2.97 e.next = newTable[i]; 8.01/2.97 newTable[i] = e; 8.01/2.97 e = next; 8.01/2.97 } while (e != null); 8.01/2.97 } 8.01/2.97 } 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Copies all of the mappings from the specified map to this map. 8.01/2.97 * These mappings will replace any mappings that this map had for 8.01/2.97 * any of the keys currently in the specified map. 8.01/2.97 * 8.01/2.97 * @param m mappings to be stored in this map 8.01/2.97 * @throws NullPointerException if the specified map is null 8.01/2.97 */ 8.01/2.97 public void putAll(Map m) { 8.01/2.97 int numKeysToBeAdded = m.size(); 8.01/2.97 if (numKeysToBeAdded == 0) 8.01/2.97 return; 8.01/2.97 8.01/2.97 /* 8.01/2.97 * Expand the map if the map if the number of mappings to be added 8.01/2.97 * is greater than or equal to threshold. This is conservative; the 8.01/2.97 * obvious condition is (m.size() + size) >= threshold, but this 8.01/2.97 * condition could result in a map with twice the appropriate capacity, 8.01/2.97 * if the keys to be added overlap with the keys already in this map. 8.01/2.97 * By using the conservative calculation, we subject ourself 8.01/2.97 * to at most one extra resize. 8.01/2.97 */ 8.01/2.97 if (numKeysToBeAdded > threshold) { 8.01/2.97 int targetCapacity = (int)(numKeysToBeAdded / loadFactor + 1); 8.01/2.97 if (targetCapacity > MAXIMUM_CAPACITY) 8.01/2.97 targetCapacity = MAXIMUM_CAPACITY; 8.01/2.97 int newCapacity = table.length; 8.01/2.97 while (newCapacity < targetCapacity) 8.01/2.97 newCapacity <<= 1; 8.01/2.97 if (newCapacity > table.length) 8.01/2.97 resize(newCapacity); 8.01/2.97 } 8.01/2.97 8.01/2.97 for (Iterator> i = m.entrySet().iterator(); i.hasNext(); ) { 8.01/2.97 Map.Entry e = i.next(); 8.01/2.97 put(e.getKey(), e.getValue()); 8.01/2.97 } 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Removes the mapping for the specified key from this map if present. 8.01/2.97 * 8.01/2.97 * @param key key whose mapping is to be removed from the map 8.01/2.97 * @return the previous value associated with key, or 8.01/2.97 * null if there was no mapping for key. 8.01/2.97 * (A null return can also indicate that the map 8.01/2.97 * previously associated null with key.) 8.01/2.97 */ 8.01/2.97 public V remove(Object key) { 8.01/2.97 Entry e = removeEntryForKey(key); 8.01/2.97 return (e == null ? null : e.value); 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Removes and returns the entry associated with the specified key 8.01/2.97 * in the HashMap. Returns null if the HashMap contains no mapping 8.01/2.97 * for this key. 8.01/2.97 */ 8.01/2.97 final Entry removeEntryForKey(Object key) { 8.01/2.97 int hash = (key == null) ? 0 : hash(key.hashCode()); 8.01/2.97 int i = indexFor(hash, table.length); 8.01/2.97 Entry prev = table[i]; 8.01/2.97 Entry e = prev; 8.01/2.97 8.01/2.97 while (e != null) { 8.01/2.97 Entry next = e.next; 8.01/2.97 Object k; 8.01/2.97 if (e.hash == hash && 8.01/2.97 ((k = e.key) == key || (key != null && key.equals(k)))) { 8.01/2.97 modCount++; 8.01/2.97 size--; 8.01/2.97 if (prev == e) 8.01/2.97 table[i] = next; 8.01/2.97 else 8.01/2.97 prev.next = next; 8.01/2.97 e.recordRemoval(this); 8.01/2.97 return e; 8.01/2.97 } 8.01/2.97 prev = e; 8.01/2.97 e = next; 8.01/2.97 } 8.01/2.97 8.01/2.97 return e; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Special version of remove for EntrySet. 8.01/2.97 */ 8.01/2.97 final Entry removeMapping(Object o) { 8.01/2.97 if (!(o instanceof Map.Entry)) 8.01/2.97 return null; 8.01/2.97 8.01/2.97 Map.Entry entry = (Map.Entry) o; 8.01/2.97 Object key = entry.getKey(); 8.01/2.97 int hash = (key == null) ? 0 : hash(key.hashCode()); 8.01/2.97 int i = indexFor(hash, table.length); 8.01/2.97 Entry prev = table[i]; 8.01/2.97 Entry e = prev; 8.01/2.97 8.01/2.97 while (e != null) { 8.01/2.97 Entry next = e.next; 8.01/2.97 if (e.hash == hash && e.equals(entry)) { 8.01/2.97 modCount++; 8.01/2.97 size--; 8.01/2.97 if (prev == e) 8.01/2.97 table[i] = next; 8.01/2.97 else 8.01/2.97 prev.next = next; 8.01/2.97 e.recordRemoval(this); 8.01/2.97 return e; 8.01/2.97 } 8.01/2.97 prev = e; 8.01/2.97 e = next; 8.01/2.97 } 8.01/2.97 8.01/2.97 return e; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Removes all of the mappings from this map. 8.01/2.97 * The map will be empty after this call returns. 8.01/2.97 */ 8.01/2.97 public void clear() { 8.01/2.97 modCount++; 8.01/2.97 Entry[] tab = table; 8.01/2.97 for (int i = 0; i < tab.length; i++) 8.01/2.97 tab[i] = null; 8.01/2.97 size = 0; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns true if this map maps one or more keys to the 8.01/2.97 * specified value. 8.01/2.97 * 8.01/2.97 * @param value value whose presence in this map is to be tested 8.01/2.97 * @return true if this map maps one or more keys to the 8.01/2.97 * specified value 8.01/2.97 */ 8.01/2.97 public boolean containsValue(Object value) { 8.01/2.97 if (value == null) 8.01/2.97 return containsNullValue(); 8.01/2.97 8.01/2.97 Entry[] tab = table; 8.01/2.97 for (int i = 0; i < tab.length ; i++) 8.01/2.97 for (Entry e = tab[i] ; e != null ; e = e.next) 8.01/2.97 if (value.equals(e.value)) 8.01/2.97 return true; 8.01/2.97 return false; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Special-case code for containsValue with null argument 8.01/2.97 */ 8.01/2.97 private boolean containsNullValue() { 8.01/2.97 Entry[] tab = table; 8.01/2.97 for (int i = 0; i < tab.length ; i++) 8.01/2.97 for (Entry e = tab[i] ; e != null ; e = e.next) 8.01/2.97 if (e.value == null) 8.01/2.97 return true; 8.01/2.97 return false; 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns a shallow copy of this HashMap instance: the keys and 8.01/2.97 * values themselves are not cloned. 8.01/2.97 * 8.01/2.97 * @return a shallow copy of this map 8.01/2.97 */ 8.01/2.97 public Object clone() { 8.01/2.97 HashMap result = null; 8.01/2.97 try { 8.01/2.97 result = (HashMap)super.clone(); 8.01/2.97 } catch (CloneNotSupportedException e) { 8.01/2.97 // assert false; 8.01/2.97 } 8.01/2.97 result.table = new Entry[table.length]; 8.01/2.97 result.entrySet = null; 8.01/2.97 result.modCount = 0; 8.01/2.97 result.size = 0; 8.01/2.97 result.init(); 8.01/2.97 result.putAllForCreate(this); 8.01/2.97 8.01/2.97 return result; 8.01/2.97 } 8.01/2.97 8.01/2.97 static class Entry implements Map.Entry { 8.01/2.97 final K key; 8.01/2.97 V value; 8.01/2.97 Entry next; 8.01/2.97 final int hash; 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Creates new entry. 8.01/2.97 */ 8.01/2.97 Entry(int h, K k, V v, Entry n) { 8.01/2.97 value = v; 8.01/2.97 next = n; 8.01/2.97 key = k; 8.01/2.97 hash = h; 8.01/2.97 } 8.01/2.97 8.01/2.97 public final K getKey() { 8.01/2.97 return key; 8.01/2.97 } 8.01/2.97 8.01/2.97 public final V getValue() { 8.01/2.97 return value; 8.01/2.97 } 8.01/2.97 8.01/2.97 public final V setValue(V newValue) { 8.01/2.97 V oldValue = value; 8.01/2.97 value = newValue; 8.01/2.97 return oldValue; 8.01/2.97 } 8.01/2.97 8.01/2.97 public final 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 Object k1 = getKey(); 8.01/2.97 Object k2 = e.getKey(); 8.01/2.97 if (k1 == k2 || (k1 != null && k1.equals(k2))) { 8.01/2.97 Object v1 = getValue(); 8.01/2.97 Object v2 = e.getValue(); 8.01/2.97 if (v1 == v2 || (v1 != null && v1.equals(v2))) 8.01/2.97 return true; 8.01/2.97 } 8.01/2.97 return false; 8.01/2.97 } 8.01/2.97 8.01/2.97 public final 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 public final String toString() { 8.01/2.97 return getKey() + "=" + getValue(); 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * This method is invoked whenever the value in an entry is 8.01/2.97 * overwritten by an invocation of put(k,v) for a key k that's already 8.01/2.97 * in the HashMap. 8.01/2.97 */ 8.01/2.97 void recordAccess(HashMap m) { 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * This method is invoked whenever the entry is 8.01/2.97 * removed from the table. 8.01/2.97 */ 8.01/2.97 void recordRemoval(HashMap m) { 8.01/2.97 } 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Adds a new entry with the specified key, value and hash code to 8.01/2.97 * the specified bucket. It is the responsibility of this 8.01/2.97 * method to resize the table if appropriate. 8.01/2.97 * 8.01/2.97 * Subclass overrides this to alter the behavior of put method. 8.01/2.97 */ 8.01/2.97 void addEntry(int hash, K key, V value, int bucketIndex) { 8.01/2.97 Entry e = table[bucketIndex]; 8.01/2.97 table[bucketIndex] = new Entry(hash, key, value, e); 8.01/2.97 if (size++ >= threshold) 8.01/2.97 resize(2 * table.length); 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Like addEntry except that this version is used when creating entries 8.01/2.97 * as part of Map construction or "pseudo-construction" (cloning, 8.01/2.97 * deserialization). This version needn't worry about resizing the table. 8.01/2.97 * 8.01/2.97 * Subclass overrides this to alter the behavior of HashMap(Map), 8.01/2.97 * clone, and readObject. 8.01/2.97 */ 8.01/2.97 void createEntry(int hash, K key, V value, int bucketIndex) { 8.01/2.97 Entry e = table[bucketIndex]; 8.01/2.97 table[bucketIndex] = new Entry(hash, key, value, e); 8.01/2.97 size++; 8.01/2.97 } 8.01/2.97 8.01/2.97 private abstract class HashIterator implements Iterator { 8.01/2.97 Entry next; // next entry to return 8.01/2.97 int expectedModCount; // For fast-fail 8.01/2.97 int index; // current slot 8.01/2.97 Entry current; // current entry 8.01/2.97 8.01/2.97 HashIterator() { 8.01/2.97 expectedModCount = modCount; 8.01/2.97 if (size > 0) { // advance to first entry 8.01/2.97 Entry[] t = table; 8.01/2.97 while (index < t.length && (next = t[index++]) == null) 8.01/2.97 ; 8.01/2.97 } 8.01/2.97 } 8.01/2.97 8.01/2.97 public final boolean hasNext() { 8.01/2.97 return next != null; 8.01/2.97 } 8.01/2.97 8.01/2.97 final Entry nextEntry() { 8.01/2.97 if (modCount != expectedModCount) 8.01/2.97 throw new ConcurrentModificationException(); 8.01/2.97 Entry e = next; 8.01/2.97 if (e == null) 8.01/2.97 throw new NoSuchElementException(); 8.01/2.97 8.01/2.97 if ((next = e.next) == null) { 8.01/2.97 Entry[] t = table; 8.01/2.97 while (index < t.length && (next = t[index++]) == null) 8.01/2.97 ; 8.01/2.97 } 8.01/2.97 current = e; 8.01/2.97 return e; 8.01/2.97 } 8.01/2.97 8.01/2.97 public void remove() { 8.01/2.97 if (current == null) 8.01/2.97 throw new IllegalStateException(); 8.01/2.97 if (modCount != expectedModCount) 8.01/2.97 throw new ConcurrentModificationException(); 8.01/2.97 Object k = current.key; 8.01/2.97 current = null; 8.01/2.97 HashMap.this.removeEntryForKey(k); 8.01/2.97 expectedModCount = modCount; 8.01/2.97 } 8.01/2.97 8.01/2.97 } 8.01/2.97 8.01/2.97 private final class ValueIterator extends HashIterator { 8.01/2.97 public V next() { 8.01/2.97 return nextEntry().value; 8.01/2.97 } 8.01/2.97 } 8.01/2.97 8.01/2.97 private final class KeyIterator extends HashIterator { 8.01/2.97 public K next() { 8.01/2.97 return nextEntry().getKey(); 8.01/2.97 } 8.01/2.97 } 8.01/2.97 8.01/2.97 private final class EntryIterator extends HashIterator> { 8.01/2.97 public Map.Entry next() { 8.01/2.97 return nextEntry(); 8.01/2.97 } 8.01/2.97 } 8.01/2.97 8.01/2.97 // Subclass overrides these to alter behavior of views' iterator() method 8.01/2.97 Iterator newKeyIterator() { 8.01/2.97 return new KeyIterator(); 8.01/2.97 } 8.01/2.97 Iterator newValueIterator() { 8.01/2.97 return new ValueIterator(); 8.01/2.97 } 8.01/2.97 Iterator> newEntryIterator() { 8.01/2.97 return new EntryIterator(); 8.01/2.97 } 8.01/2.97 8.01/2.97 8.01/2.97 // Views 8.01/2.97 8.01/2.97 private transient Set> entrySet = null; 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns a {@link Set} view of the keys contained in this map. 8.01/2.97 * The set is backed by the map, so changes to the map are 8.01/2.97 * reflected in the set, and vice-versa. If the map is modified 8.01/2.97 * while an iteration over the set is in progress (except through 8.01/2.97 * the iterator's own remove operation), the results of 8.01/2.97 * the iteration are undefined. The set supports element removal, 8.01/2.97 * which removes the corresponding mapping from the map, via the 8.01/2.97 * Iterator.remove, Set.remove, 8.01/2.97 * removeAll, retainAll, and clear 8.01/2.97 * operations. It does not support the add or addAll 8.01/2.97 * operations. 8.01/2.97 */ 8.01/2.97 public Set keySet() { 8.01/2.97 Set ks = keySet; 8.01/2.97 return (ks != null ? ks : (keySet = new KeySet())); 8.01/2.97 } 8.01/2.97 8.01/2.97 private final class KeySet extends AbstractSet { 8.01/2.97 public Iterator iterator() { 8.01/2.97 return newKeyIterator(); 8.01/2.97 } 8.01/2.97 public int size() { 8.01/2.97 return size; 8.01/2.97 } 8.01/2.97 public boolean contains(Object o) { 8.01/2.97 return containsKey(o); 8.01/2.97 } 8.01/2.97 public boolean remove(Object o) { 8.01/2.97 return HashMap.this.removeEntryForKey(o) != null; 8.01/2.97 } 8.01/2.97 public void clear() { 8.01/2.97 HashMap.this.clear(); 8.01/2.97 } 8.01/2.97 public Object[] toArray() { 8.01/2.97 Object[] res = new Object[size]; 8.01/2.97 Iterator it = iterator(); 8.01/2.97 int i = 0; 8.01/2.97 while (it.hasNext()) 8.01/2.97 res[i++] = it.next(); 8.01/2.97 return res; 8.01/2.97 } 8.01/2.97 public T[] toArray(T[] a) { 8.01/2.97 a = (T[])java.lang.reflect.Array.newInstance( 8.01/2.97 a.getClass().getComponentType(), size); 8.01/2.97 Object[] res = a; 8.01/2.97 Iterator it = iterator(); 8.01/2.97 int i = 0; 8.01/2.97 while (it.hasNext()) 8.01/2.97 res[i++] = it.next(); 8.01/2.97 return a; 8.01/2.97 } 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns a {@link Collection} view of the values contained in this map. 8.01/2.97 * The collection is backed by the map, so changes to the map are 8.01/2.97 * reflected in the collection, and vice-versa. If the map is 8.01/2.97 * modified while an iteration over the collection is in progress 8.01/2.97 * (except through the iterator's own remove operation), 8.01/2.97 * the results of the iteration are undefined. The collection 8.01/2.97 * supports element removal, which removes the corresponding 8.01/2.97 * mapping from the map, via the Iterator.remove, 8.01/2.97 * Collection.remove, removeAll, 8.01/2.97 * retainAll and clear operations. It does not 8.01/2.97 * support the add or addAll operations. 8.01/2.97 */ 8.01/2.97 public Collection values() { 8.01/2.97 Collection vs = values; 8.01/2.97 return (vs != null ? vs : (values = new Values())); 8.01/2.97 } 8.01/2.97 8.01/2.97 private final class Values extends AbstractCollection { 8.01/2.97 public Iterator iterator() { 8.01/2.97 return newValueIterator(); 8.01/2.97 } 8.01/2.97 public int size() { 8.01/2.97 return size; 8.01/2.97 } 8.01/2.97 public boolean contains(Object o) { 8.01/2.97 return containsValue(o); 8.01/2.97 } 8.01/2.97 public void clear() { 8.01/2.97 HashMap.this.clear(); 8.01/2.97 } 8.01/2.97 } 8.01/2.97 8.01/2.97 /** 8.01/2.97 * Returns a {@link Set} view of the mappings contained in this map. 8.01/2.97 * The set is backed by the map, so changes to the map are 8.01/2.97 * reflected in the set, and vice-versa. If the map is modified 8.01/2.97 * while an iteration over the set is in progress (except through 8.01/2.97 * the iterator's own remove operation, or through the 8.01/2.97 * setValue operation on a map entry returned by the 8.01/2.97 * iterator) the results of the iteration are undefined. The set 8.01/2.97 * supports element removal, which removes the corresponding 8.01/2.97 * mapping from the map, via the Iterator.remove, 8.01/2.97 * Set.remove, removeAll, retainAll and 8.01/2.97 * clear operations. It does not support the 8.01/2.97 * add or addAll operations. 8.01/2.97 * 8.01/2.97 * @return a set view of the mappings contained in this map 8.01/2.97 */ 8.01/2.97 public Set> entrySet() { 8.01/2.97 return entrySet0(); 8.01/2.97 } 8.01/2.97 8.01/2.97 private Set> entrySet0() { 8.01/2.97 Set> es = entrySet; 8.01/2.97 return es != null ? es : (entrySet = new EntrySet()); 8.01/2.97 } 8.01/2.97 8.01/2.97 private final class EntrySet extends AbstractSet> { 8.01/2.97 public Iterator> iterator() { 8.01/2.97 return newEntryIterator(); 8.01/2.97 } 8.01/2.97 public boolean contains(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 Entry candidate = getEntry(e.getKey()); 8.01/2.97 return candidate != null && candidate.equals(e); 8.01/2.97 } 8.01/2.97 public boolean remove(Object o) { 8.01/2.97 return removeMapping(o) != null; 8.01/2.97 } 8.01/2.97 public int size() { 8.01/2.97 return size; 8.01/2.97 } 8.01/2.97 public void clear() { 8.01/2.97 HashMap.this.clear(); 8.01/2.97 } 8.01/2.97 public Object[] toArray() { 8.01/2.97 Object[] res = new Object[size]; 8.01/2.97 Iterator> it = iterator(); 8.01/2.98 int i = 0; 8.01/2.98 while (it.hasNext()) 8.01/2.98 res[i++] = it.next(); 8.01/2.98 return res; 8.01/2.98 } 8.01/2.98 public T[] toArray(T[] a) { 8.01/2.98 a = (T[])java.lang.reflect.Array.newInstance( 8.01/2.98 a.getClass().getComponentType(), size); 8.01/2.98 Object[] res = a; 8.01/2.98 Iterator> it = iterator(); 8.01/2.98 int i = 0; 8.01/2.98 while (it.hasNext()) 8.01/2.98 res[i++] = it.next(); 8.01/2.98 return a; 8.01/2.98 } 8.01/2.98 } 8.01/2.98 8.01/2.98 private static final long serialVersionUID = 362498820763181265L; 8.01/2.98 } 8.01/2.98 8.01/2.98 8.01/2.98 /* 8.01/2.98 * Copyright 1994-2003 Sun Microsystems, Inc. All Rights Reserved. 8.01/2.98 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.01/2.98 * 8.01/2.98 * This code is free software; you can redistribute it and/or modify it 8.01/2.98 * under the terms of the GNU General Public License version 2 only, as 8.01/2.98 * published by the Free Software Foundation. Sun designates this 8.01/2.98 * particular file as subject to the "Classpath" exception as provided 8.01/2.98 * by Sun in the LICENSE file that accompanied this code. 8.01/2.98 * 8.01/2.98 * This code is distributed in the hope that it will be useful, but WITHOUT 8.01/2.98 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.01/2.98 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.01/2.98 * version 2 for more details (a copy is included in the LICENSE file that 8.01/2.98 * accompanied this code). 8.01/2.98 * 8.01/2.98 * You should have received a copy of the GNU General Public License version 8.01/2.98 * 2 along with this work; if not, write to the Free Software Foundation, 8.01/2.98 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.01/2.98 * 8.01/2.98 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 8.01/2.98 * CA 95054 USA or visit www.sun.com if you need additional information or 8.01/2.98 * have any questions. 8.01/2.98 */ 8.01/2.98 8.01/2.98 package javaUtilEx; 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Thrown to indicate that a method has been passed an illegal or 8.01/2.98 * inappropriate argument. 8.01/2.98 * 8.01/2.98 * @author unascribed 8.01/2.98 * @see java.lang.Thread#setPriority(int) 8.01/2.98 * @since JDK1.0 8.01/2.98 */ 8.01/2.98 public 8.01/2.98 class IllegalArgumentException extends RuntimeException { 8.01/2.98 /** 8.01/2.98 * Constructs an IllegalArgumentException with no 8.01/2.98 * detail message. 8.01/2.98 */ 8.01/2.98 public IllegalArgumentException() { 8.01/2.98 super(); 8.01/2.98 } 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Constructs an IllegalArgumentException with the 8.01/2.98 * specified detail message. 8.01/2.98 * 8.01/2.98 * @param s the detail message. 8.01/2.98 */ 8.01/2.98 public IllegalArgumentException(String s) { 8.01/2.98 super(s); 8.01/2.98 } 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Constructs a new exception with the specified detail message and 8.01/2.98 * cause. 8.01/2.98 * 8.01/2.98 *

Note that the detail message associated with cause is 8.01/2.98 * not automatically incorporated in this exception's detail 8.01/2.98 * message. 8.01/2.98 * 8.01/2.98 * @param message the detail message (which is saved for later retrieval 8.01/2.98 * by the {@link Throwable#getMessage()} method). 8.01/2.98 * @param cause the cause (which is saved for later retrieval by the 8.01/2.98 * {@link Throwable#getCause()} method). (A null value 8.01/2.98 * is permitted, and indicates that the cause is nonexistent or 8.01/2.98 * unknown.) 8.01/2.98 * @since 1.5 8.01/2.98 */ 8.01/2.98 public IllegalArgumentException(String message, Throwable cause) { 8.01/2.98 super(message, cause); 8.01/2.98 } 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Constructs a new exception with the specified cause and a detail 8.01/2.98 * message of (cause==null ? null : cause.toString()) (which 8.01/2.98 * typically contains the class and detail message of cause). 8.01/2.98 * This constructor is useful for exceptions that are little more than 8.01/2.98 * wrappers for other throwables (for example, {@link 8.01/2.98 * java.security.PrivilegedActionException}). 8.01/2.98 * 8.01/2.98 * @param cause the cause (which is saved for later retrieval by the 8.01/2.98 * {@link Throwable#getCause()} method). (A null value is 8.01/2.98 * permitted, and indicates that the cause is nonexistent or 8.01/2.98 * unknown.) 8.01/2.98 * @since 1.5 8.01/2.98 */ 8.01/2.98 public IllegalArgumentException(Throwable cause) { 8.01/2.98 super(cause); 8.01/2.98 } 8.01/2.98 8.01/2.98 private static final long serialVersionUID = -5365630128856068164L; 8.01/2.98 } 8.01/2.98 8.01/2.98 8.01/2.98 /* 8.01/2.98 * Copyright 1996-2003 Sun Microsystems, Inc. All Rights Reserved. 8.01/2.98 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.01/2.98 * 8.01/2.98 * This code is free software; you can redistribute it and/or modify it 8.01/2.98 * under the terms of the GNU General Public License version 2 only, as 8.01/2.98 * published by the Free Software Foundation. Sun designates this 8.01/2.98 * particular file as subject to the "Classpath" exception as provided 8.01/2.98 * by Sun in the LICENSE file that accompanied this code. 8.01/2.98 * 8.01/2.98 * This code is distributed in the hope that it will be useful, but WITHOUT 8.01/2.98 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.01/2.98 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.01/2.98 * version 2 for more details (a copy is included in the LICENSE file that 8.01/2.98 * accompanied this code). 8.01/2.98 * 8.01/2.98 * You should have received a copy of the GNU General Public License version 8.01/2.98 * 2 along with this work; if not, write to the Free Software Foundation, 8.01/2.98 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.01/2.98 * 8.01/2.98 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 8.01/2.98 * CA 95054 USA or visit www.sun.com if you need additional information or 8.01/2.98 * have any questions. 8.01/2.98 */ 8.01/2.98 8.01/2.98 package javaUtilEx; 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Signals that a method has been invoked at an illegal or 8.01/2.98 * inappropriate time. In other words, the Java environment or 8.01/2.98 * Java application is not in an appropriate state for the requested 8.01/2.98 * operation. 8.01/2.98 * 8.01/2.98 * @author Jonni Kanerva 8.01/2.98 * @since JDK1.1 8.01/2.98 */ 8.01/2.98 public 8.01/2.98 class IllegalStateException extends RuntimeException { 8.01/2.98 /** 8.01/2.98 * Constructs an IllegalStateException with no detail message. 8.01/2.98 * A detail message is a String that describes this particular exception. 8.01/2.98 */ 8.01/2.98 public IllegalStateException() { 8.01/2.98 super(); 8.01/2.98 } 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Constructs an IllegalStateException with the specified detail 8.01/2.98 * message. A detail message is a String that describes this particular 8.01/2.98 * exception. 8.01/2.98 * 8.01/2.98 * @param s the String that contains a detailed message 8.01/2.98 */ 8.01/2.98 public IllegalStateException(String s) { 8.01/2.98 super(s); 8.01/2.98 } 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Constructs a new exception with the specified detail message and 8.01/2.98 * cause. 8.01/2.98 * 8.01/2.98 *

Note that the detail message associated with cause is 8.01/2.98 * not automatically incorporated in this exception's detail 8.01/2.98 * message. 8.01/2.98 * 8.01/2.98 * @param message the detail message (which is saved for later retrieval 8.01/2.98 * by the {@link Throwable#getMessage()} method). 8.01/2.98 * @param cause the cause (which is saved for later retrieval by the 8.01/2.98 * {@link Throwable#getCause()} method). (A null value 8.01/2.98 * is permitted, and indicates that the cause is nonexistent or 8.01/2.98 * unknown.) 8.01/2.98 * @since 1.5 8.01/2.98 */ 8.01/2.98 public IllegalStateException(String message, Throwable cause) { 8.01/2.98 super(message, cause); 8.01/2.98 } 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Constructs a new exception with the specified cause and a detail 8.01/2.98 * message of (cause==null ? null : cause.toString()) (which 8.01/2.98 * typically contains the class and detail message of cause). 8.01/2.98 * This constructor is useful for exceptions that are little more than 8.01/2.98 * wrappers for other throwables (for example, {@link 8.01/2.98 * java.security.PrivilegedActionException}). 8.01/2.98 * 8.01/2.98 * @param cause the cause (which is saved for later retrieval by the 8.01/2.98 * {@link Throwable#getCause()} method). (A null value is 8.01/2.98 * permitted, and indicates that the cause is nonexistent or 8.01/2.98 * unknown.) 8.01/2.98 * @since 1.5 8.01/2.98 */ 8.01/2.98 public IllegalStateException(Throwable cause) { 8.01/2.98 super(cause); 8.01/2.98 } 8.01/2.98 8.01/2.98 static final long serialVersionUID = -1848914673093119416L; 8.01/2.98 } 8.01/2.98 8.01/2.98 8.01/2.98 /* 8.01/2.98 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 8.01/2.98 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.01/2.98 * 8.01/2.98 * This code is free software; you can redistribute it and/or modify it 8.01/2.98 * under the terms of the GNU General Public License version 2 only, as 8.01/2.98 * published by the Free Software Foundation. Sun designates this 8.01/2.98 * particular file as subject to the "Classpath" exception as provided 8.01/2.98 * by Sun in the LICENSE file that accompanied this code. 8.01/2.98 * 8.01/2.98 * This code is distributed in the hope that it will be useful, but WITHOUT 8.01/2.98 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.01/2.98 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.01/2.98 * version 2 for more details (a copy is included in the LICENSE file that 8.01/2.98 * accompanied this code). 8.01/2.98 * 8.01/2.98 * You should have received a copy of the GNU General Public License version 8.01/2.98 * 2 along with this work; if not, write to the Free Software Foundation, 8.01/2.98 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.01/2.98 * 8.01/2.98 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 8.01/2.98 * CA 95054 USA or visit www.sun.com if you need additional information or 8.01/2.98 * have any questions. 8.01/2.98 */ 8.01/2.98 8.01/2.98 package javaUtilEx; 8.01/2.98 8.01/2.98 /** 8.01/2.98 * An iterator over a collection. {@code Iterator} takes the place of 8.01/2.98 * {@link Enumeration} in the Java Collections Framework. Iterators 8.01/2.98 * differ from enumerations in two ways: 8.01/2.98 * 8.01/2.98 *

    8.01/2.98 *
  • Iterators allow the caller to remove elements from the 8.01/2.98 * underlying collection during the iteration with well-defined 8.01/2.98 * semantics. 8.01/2.98 *
  • Method names have been improved. 8.01/2.98 *
8.01/2.98 * 8.01/2.98 *

This interface is a member of the 8.01/2.98 * 8.01/2.98 * Java Collections Framework. 8.01/2.98 * 8.01/2.98 * @author Josh Bloch 8.01/2.98 * @see Collection 8.01/2.98 * @see ListIterator 8.01/2.98 * @see Iterable 8.01/2.98 * @since 1.2 8.01/2.98 */ 8.01/2.98 public interface Iterator { 8.01/2.98 /** 8.01/2.98 * Returns {@code true} if the iteration has more elements. 8.01/2.98 * (In other words, returns {@code true} if {@link #next} would 8.01/2.98 * return an element rather than throwing an exception.) 8.01/2.98 * 8.01/2.98 * @return {@code true} if the iteration has more elements 8.01/2.98 */ 8.01/2.98 boolean hasNext(); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns the next element in the iteration. 8.01/2.98 * 8.01/2.98 * @return the next element in the iteration 8.01/2.98 * @throws NoSuchElementException if the iteration has no more elements 8.01/2.98 */ 8.01/2.98 E next(); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Removes from the underlying collection the last element returned 8.01/2.98 * by this iterator (optional operation). This method can be called 8.01/2.98 * only once per call to {@link #next}. The behavior of an iterator 8.01/2.98 * is unspecified if the underlying collection is modified while the 8.01/2.98 * iteration is in progress in any way other than by calling this 8.01/2.98 * method. 8.01/2.98 * 8.01/2.98 * @throws UnsupportedOperationException if the {@code remove} 8.01/2.98 * operation is not supported by this iterator 8.01/2.98 * 8.01/2.98 * @throws IllegalStateException if the {@code next} method has not 8.01/2.98 * yet been called, or the {@code remove} method has already 8.01/2.98 * been called after the last call to the {@code next} 8.01/2.98 * method 8.01/2.98 */ 8.01/2.98 void remove(); 8.01/2.98 } 8.01/2.98 8.01/2.98 8.01/2.98 package javaUtilEx; 8.01/2.98 8.01/2.98 public class juHashMapCreatePutAll { 8.01/2.98 public static void main(String[] args) { 8.01/2.98 Random.args = args; 8.01/2.98 8.01/2.98 HashMap m1 = createMap(Random.random()); 8.01/2.98 HashMap m2 = createMap(Random.random()); 8.01/2.98 m1.putAll(m2); 8.01/2.98 } 8.01/2.98 8.01/2.98 public static HashMap createMap(int n) { 8.01/2.98 HashMap m = new HashMap(); 8.01/2.98 while (n > 0) { 8.01/2.98 Content key = new Content(Random.random()); 8.01/2.98 Content val = new Content(Random.random()); 8.01/2.98 m.put(key, val); 8.01/2.98 n--; 8.01/2.98 } 8.01/2.98 return m; 8.01/2.98 } 8.01/2.98 } 8.01/2.98 8.01/2.98 final class Content { 8.01/2.98 int val; 8.01/2.98 8.01/2.98 public Content(int v) { 8.01/2.98 this.val = v; 8.01/2.98 } 8.01/2.98 8.01/2.98 public int hashCode() { 8.01/2.98 return val^31; 8.01/2.98 } 8.01/2.98 8.01/2.98 public boolean equals(Object o) { 8.01/2.98 if (o instanceof Content) { 8.01/2.98 return this.val == ((Content) o).val; 8.01/2.98 } 8.01/2.98 return false; 8.01/2.98 } 8.01/2.98 } 8.01/2.98 8.01/2.98 8.01/2.98 /* 8.01/2.98 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 8.01/2.98 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.01/2.98 * 8.01/2.98 * This code is free software; you can redistribute it and/or modify it 8.01/2.98 * under the terms of the GNU General Public License version 2 only, as 8.01/2.98 * published by the Free Software Foundation. Sun designates this 8.01/2.98 * particular file as subject to the "Classpath" exception as provided 8.01/2.98 * by Sun in the LICENSE file that accompanied this code. 8.01/2.98 * 8.01/2.98 * This code is distributed in the hope that it will be useful, but WITHOUT 8.01/2.98 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.01/2.98 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.01/2.98 * version 2 for more details (a copy is included in the LICENSE file that 8.01/2.98 * accompanied this code). 8.01/2.98 * 8.01/2.98 * You should have received a copy of the GNU General Public License version 8.01/2.98 * 2 along with this work; if not, write to the Free Software Foundation, 8.01/2.98 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.01/2.98 * 8.01/2.98 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 8.01/2.98 * CA 95054 USA or visit www.sun.com if you need additional information or 8.01/2.98 * have any questions. 8.01/2.98 */ 8.01/2.98 8.01/2.98 package javaUtilEx; 8.01/2.98 8.01/2.98 /** 8.01/2.98 * An object that maps keys to values. A map cannot contain duplicate keys; 8.01/2.98 * each key can map to at most one value. 8.01/2.98 * 8.01/2.98 *

This interface takes the place of the Dictionary class, which 8.01/2.98 * was a totally abstract class rather than an interface. 8.01/2.98 * 8.01/2.98 *

The Map interface provides three collection views, which 8.01/2.98 * allow a map's contents to be viewed as a set of keys, collection of values, 8.01/2.98 * or set of key-value mappings. The order of a map is defined as 8.01/2.98 * the order in which the iterators on the map's collection views return their 8.01/2.98 * elements. Some map implementations, like the TreeMap class, make 8.01/2.98 * specific guarantees as to their order; others, like the HashMap 8.01/2.98 * class, do not. 8.01/2.98 * 8.01/2.98 *

Note: great care must be exercised if mutable objects are used as map 8.01/2.98 * keys. The behavior of a map is not specified if the value of an object is 8.01/2.98 * changed in a manner that affects equals comparisons while the 8.01/2.98 * object is a key in the map. A special case of this prohibition is that it 8.01/2.98 * is not permissible for a map to contain itself as a key. While it is 8.01/2.98 * permissible for a map to contain itself as a value, extreme caution is 8.01/2.98 * advised: the equals and hashCode methods are no longer 8.01/2.98 * well defined on such a map. 8.01/2.98 * 8.01/2.98 *

All general-purpose map implementation classes should provide two 8.01/2.98 * "standard" constructors: a void (no arguments) constructor which creates an 8.01/2.98 * empty map, and a constructor with a single argument of type Map, 8.01/2.98 * which creates a new map with the same key-value mappings as its argument. 8.01/2.98 * In effect, the latter constructor allows the user to copy any map, 8.01/2.98 * producing an equivalent map of the desired class. There is no way to 8.01/2.98 * enforce this recommendation (as interfaces cannot contain constructors) but 8.01/2.98 * all of the general-purpose map implementations in the JDK comply. 8.01/2.98 * 8.01/2.98 *

The "destructive" methods contained in this interface, that is, the 8.01/2.98 * methods that modify the map on which they operate, are specified to throw 8.01/2.98 * UnsupportedOperationException if this map does not support the 8.01/2.98 * operation. If this is the case, these methods may, but are not required 8.01/2.98 * to, throw an UnsupportedOperationException if the invocation would 8.01/2.98 * have no effect on the map. For example, invoking the {@link #putAll(Map)} 8.01/2.98 * method on an unmodifiable map may, but is not required to, throw the 8.01/2.98 * exception if the map whose mappings are to be "superimposed" is empty. 8.01/2.98 * 8.01/2.98 *

Some map implementations have restrictions on the keys and values they 8.01/2.98 * may contain. For example, some implementations prohibit null keys and 8.01/2.98 * values, and some have restrictions on the types of their keys. Attempting 8.01/2.98 * to insert an ineligible key or value throws an unchecked exception, 8.01/2.98 * typically NullPointerException or ClassCastException. 8.01/2.98 * Attempting to query the presence of an ineligible key or value may throw an 8.01/2.98 * exception, or it may simply return false; some implementations will exhibit 8.01/2.98 * the former behavior and some will exhibit the latter. More generally, 8.01/2.98 * attempting an operation on an ineligible key or value whose completion 8.01/2.98 * would not result in the insertion of an ineligible element into the map may 8.01/2.98 * throw an exception or it may succeed, at the option of the implementation. 8.01/2.98 * Such exceptions are marked as "optional" in the specification for this 8.01/2.98 * interface. 8.01/2.98 * 8.01/2.98 *

This interface is a member of the 8.01/2.98 * 8.01/2.98 * Java Collections Framework. 8.01/2.98 * 8.01/2.98 *

Many methods in Collections Framework interfaces are defined 8.01/2.98 * in terms of the {@link Object#equals(Object) equals} method. For 8.01/2.98 * example, the specification for the {@link #containsKey(Object) 8.01/2.98 * containsKey(Object key)} method says: "returns true if and 8.01/2.98 * only if this map contains a mapping for a key k such that 8.01/2.98 * (key==null ? k==null : key.equals(k))." This specification should 8.01/2.98 * not be construed to imply that invoking Map.containsKey 8.01/2.98 * with a non-null argument key will cause key.equals(k) to 8.01/2.98 * be invoked for any key k. Implementations are free to 8.01/2.98 * implement optimizations whereby the equals invocation is avoided, 8.01/2.98 * for example, by first comparing the hash codes of the two keys. (The 8.01/2.98 * {@link Object#hashCode()} specification guarantees that two objects with 8.01/2.98 * unequal hash codes cannot be equal.) More generally, implementations of 8.01/2.98 * the various Collections Framework interfaces are free to take advantage of 8.01/2.98 * the specified behavior of underlying {@link Object} methods wherever the 8.01/2.98 * implementor deems it appropriate. 8.01/2.98 * 8.01/2.98 * @param the type of keys maintained by this map 8.01/2.98 * @param the type of mapped values 8.01/2.98 * 8.01/2.98 * @author Josh Bloch 8.01/2.98 * @see HashMap 8.01/2.98 * @see TreeMap 8.01/2.98 * @see Hashtable 8.01/2.98 * @see SortedMap 8.01/2.98 * @see Collection 8.01/2.98 * @see Set 8.01/2.98 * @since 1.2 8.01/2.98 */ 8.01/2.98 public interface Map { 8.01/2.98 // Query Operations 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns the number of key-value mappings in this map. If the 8.01/2.98 * map contains more than Integer.MAX_VALUE elements, returns 8.01/2.98 * Integer.MAX_VALUE. 8.01/2.98 * 8.01/2.98 * @return the number of key-value mappings in this map 8.01/2.98 */ 8.01/2.98 int size(); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns true if this map contains no key-value mappings. 8.01/2.98 * 8.01/2.98 * @return true if this map contains no key-value mappings 8.01/2.98 */ 8.01/2.98 boolean isEmpty(); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns true if this map contains a mapping for the specified 8.01/2.98 * key. More formally, returns true if and only if 8.01/2.98 * this map contains a mapping for a key k such that 8.01/2.98 * (key==null ? k==null : key.equals(k)). (There can be 8.01/2.98 * at most one such mapping.) 8.01/2.98 * 8.01/2.98 * @param key key whose presence in this map is to be tested 8.01/2.98 * @return true if this map contains a mapping for the specified 8.01/2.98 * key 8.01/2.98 * @throws ClassCastException if the key is of an inappropriate type for 8.01/2.98 * this map (optional) 8.01/2.98 * @throws NullPointerException if the specified key is null and this map 8.01/2.98 * does not permit null keys (optional) 8.01/2.98 */ 8.01/2.98 boolean containsKey(Object key); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns true if this map maps one or more keys to the 8.01/2.98 * specified value. More formally, returns true if and only if 8.01/2.98 * this map contains at least one mapping to a value v such that 8.01/2.98 * (value==null ? v==null : value.equals(v)). This operation 8.01/2.98 * will probably require time linear in the map size for most 8.01/2.98 * implementations of the Map interface. 8.01/2.98 * 8.01/2.98 * @param value value whose presence in this map is to be tested 8.01/2.98 * @return true if this map maps one or more keys to the 8.01/2.98 * specified value 8.01/2.98 * @throws ClassCastException if the value is of an inappropriate type for 8.01/2.98 * this map (optional) 8.01/2.98 * @throws NullPointerException if the specified value is null and this 8.01/2.98 * map does not permit null values (optional) 8.01/2.98 */ 8.01/2.98 boolean containsValue(Object value); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns the value to which the specified key is mapped, 8.01/2.98 * or {@code null} if this map contains no mapping for the key. 8.01/2.98 * 8.01/2.98 *

More formally, if this map contains a mapping from a key 8.01/2.98 * {@code k} to a value {@code v} such that {@code (key==null ? k==null : 8.01/2.98 * key.equals(k))}, then this method returns {@code v}; otherwise 8.01/2.98 * it returns {@code null}. (There can be at most one such mapping.) 8.01/2.98 * 8.01/2.98 *

If this map permits null values, then a return value of 8.01/2.98 * {@code null} does not necessarily indicate that the map 8.01/2.98 * contains no mapping for the key; it's also possible that the map 8.01/2.98 * explicitly maps the key to {@code null}. The {@link #containsKey 8.01/2.98 * containsKey} operation may be used to distinguish these two cases. 8.01/2.98 * 8.01/2.98 * @param key the key whose associated value is to be returned 8.01/2.98 * @return the value to which the specified key is mapped, or 8.01/2.98 * {@code null} if this map contains no mapping for the key 8.01/2.98 * @throws ClassCastException if the key is of an inappropriate type for 8.01/2.98 * this map (optional) 8.01/2.98 * @throws NullPointerException if the specified key is null and this map 8.01/2.98 * does not permit null keys (optional) 8.01/2.98 */ 8.01/2.98 V get(Object key); 8.01/2.98 8.01/2.98 // Modification Operations 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Associates the specified value with the specified key in this map 8.01/2.98 * (optional operation). If the map previously contained a mapping for 8.01/2.98 * the key, the old value is replaced by the specified value. (A map 8.01/2.98 * m is said to contain a mapping for a key k if and only 8.01/2.98 * if {@link #containsKey(Object) m.containsKey(k)} would return 8.01/2.98 * true.) 8.01/2.98 * 8.01/2.98 * @param key key with which the specified value is to be associated 8.01/2.98 * @param value value to be associated with the specified key 8.01/2.98 * @return the previous value associated with key, or 8.01/2.98 * null if there was no mapping for key. 8.01/2.98 * (A null return can also indicate that the map 8.01/2.98 * previously associated null with key, 8.01/2.98 * if the implementation supports null values.) 8.01/2.98 * @throws UnsupportedOperationException if the put operation 8.01/2.98 * is not supported by this map 8.01/2.98 * @throws ClassCastException if the class of the specified key or value 8.01/2.98 * prevents it from being stored in this map 8.01/2.98 * @throws NullPointerException if the specified key or value is null 8.01/2.98 * and this map does not permit null keys or values 8.01/2.98 * @throws IllegalArgumentException if some property of the specified key 8.01/2.98 * or value prevents it from being stored in this map 8.01/2.98 */ 8.01/2.98 V put(K key, V value); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Removes the mapping for a key from this map if it is present 8.01/2.98 * (optional operation). More formally, if this map contains a mapping 8.01/2.98 * from key k to value v such that 8.01/2.98 * (key==null ? k==null : key.equals(k)), that mapping 8.01/2.98 * is removed. (The map can contain at most one such mapping.) 8.01/2.98 * 8.01/2.98 *

Returns the value to which this map previously associated the key, 8.01/2.98 * or null if the map contained no mapping for the key. 8.01/2.98 * 8.01/2.98 *

If this map permits null values, then a return value of 8.01/2.98 * null does not necessarily indicate that the map 8.01/2.98 * contained no mapping for the key; it's also possible that the map 8.01/2.98 * explicitly mapped the key to null. 8.01/2.98 * 8.01/2.98 *

The map will not contain a mapping for the specified key once the 8.01/2.98 * call returns. 8.01/2.98 * 8.01/2.98 * @param key key whose mapping is to be removed from the map 8.01/2.98 * @return the previous value associated with key, or 8.01/2.98 * null if there was no mapping for key. 8.01/2.98 * @throws UnsupportedOperationException if the remove operation 8.01/2.98 * is not supported by this map 8.01/2.98 * @throws ClassCastException if the key is of an inappropriate type for 8.01/2.98 * this map (optional) 8.01/2.98 * @throws NullPointerException if the specified key is null and this 8.01/2.98 * map does not permit null keys (optional) 8.01/2.98 */ 8.01/2.98 V remove(Object key); 8.01/2.98 8.01/2.98 8.01/2.98 // Bulk Operations 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Copies all of the mappings from the specified map to this map 8.01/2.98 * (optional operation). The effect of this call is equivalent to that 8.01/2.98 * of calling {@link #put(Object,Object) put(k, v)} on this map once 8.01/2.98 * for each mapping from key k to value v in the 8.01/2.98 * specified map. The behavior of this operation is undefined if the 8.01/2.98 * specified map is modified while the operation is in progress. 8.01/2.98 * 8.01/2.98 * @param m mappings to be stored in this map 8.01/2.98 * @throws UnsupportedOperationException if the putAll operation 8.01/2.98 * is not supported by this map 8.01/2.98 * @throws ClassCastException if the class of a key or value in the 8.01/2.98 * specified map prevents it from being stored in this map 8.01/2.98 * @throws NullPointerException if the specified map is null, or if 8.01/2.98 * this map does not permit null keys or values, and the 8.01/2.98 * specified map contains null keys or values 8.01/2.98 * @throws IllegalArgumentException if some property of a key or value in 8.01/2.98 * the specified map prevents it from being stored in this map 8.01/2.98 */ 8.01/2.98 void putAll(Map m); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Removes all of the mappings from this map (optional operation). 8.01/2.98 * The map will be empty after this call returns. 8.01/2.98 * 8.01/2.98 * @throws UnsupportedOperationException if the clear operation 8.01/2.98 * is not supported by this map 8.01/2.98 */ 8.01/2.98 void clear(); 8.01/2.98 8.01/2.98 8.01/2.98 // Views 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns a {@link Set} view of the keys contained in this map. 8.01/2.98 * The set is backed by the map, so changes to the map are 8.01/2.98 * reflected in the set, and vice-versa. If the map is modified 8.01/2.98 * while an iteration over the set is in progress (except through 8.01/2.98 * the iterator's own remove operation), the results of 8.01/2.98 * the iteration are undefined. The set supports element removal, 8.01/2.98 * which removes the corresponding mapping from the map, via the 8.01/2.98 * Iterator.remove, Set.remove, 8.01/2.98 * removeAll, retainAll, and clear 8.01/2.98 * operations. It does not support the add or addAll 8.01/2.98 * operations. 8.01/2.98 * 8.01/2.98 * @return a set view of the keys contained in this map 8.01/2.98 */ 8.01/2.98 Set keySet(); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns a {@link Collection} view of the values contained in this map. 8.01/2.98 * The collection is backed by the map, so changes to the map are 8.01/2.98 * reflected in the collection, and vice-versa. If the map is 8.01/2.98 * modified while an iteration over the collection is in progress 8.01/2.98 * (except through the iterator's own remove operation), 8.01/2.98 * the results of the iteration are undefined. The collection 8.01/2.98 * supports element removal, which removes the corresponding 8.01/2.98 * mapping from the map, via the Iterator.remove, 8.01/2.98 * Collection.remove, removeAll, 8.01/2.98 * retainAll and clear operations. It does not 8.01/2.98 * support the add or addAll operations. 8.01/2.98 * 8.01/2.98 * @return a collection view of the values contained in this map 8.01/2.98 */ 8.01/2.98 Collection values(); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns a {@link Set} view of the mappings contained in this map. 8.01/2.98 * The set is backed by the map, so changes to the map are 8.01/2.98 * reflected in the set, and vice-versa. If the map is modified 8.01/2.98 * while an iteration over the set is in progress (except through 8.01/2.98 * the iterator's own remove operation, or through the 8.01/2.98 * setValue operation on a map entry returned by the 8.01/2.98 * iterator) the results of the iteration are undefined. The set 8.01/2.98 * supports element removal, which removes the corresponding 8.01/2.98 * mapping from the map, via the Iterator.remove, 8.01/2.98 * Set.remove, removeAll, retainAll and 8.01/2.98 * clear operations. It does not support the 8.01/2.98 * add or addAll operations. 8.01/2.98 * 8.01/2.98 * @return a set view of the mappings contained in this map 8.01/2.98 */ 8.01/2.98 Set> entrySet(); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * A map entry (key-value pair). The Map.entrySet method returns 8.01/2.98 * a collection-view of the map, whose elements are of this class. The 8.01/2.98 * only way to obtain a reference to a map entry is from the 8.01/2.98 * iterator of this collection-view. These Map.Entry objects are 8.01/2.98 * valid only for the duration of the iteration; more formally, 8.01/2.98 * the behavior of a map entry is undefined if the backing map has been 8.01/2.98 * modified after the entry was returned by the iterator, except through 8.01/2.98 * the setValue operation on the map entry. 8.01/2.98 * 8.01/2.98 * @see Map#entrySet() 8.01/2.98 * @since 1.2 8.01/2.98 */ 8.01/2.98 interface Entry { 8.01/2.98 /** 8.01/2.98 * Returns the key corresponding to this entry. 8.01/2.98 * 8.01/2.98 * @return the key corresponding to this entry 8.01/2.98 * @throws IllegalStateException implementations may, but are not 8.01/2.98 * required to, throw this exception if the entry has been 8.01/2.98 * removed from the backing map. 8.01/2.98 */ 8.01/2.98 K getKey(); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns the value corresponding to this entry. If the mapping 8.01/2.98 * has been removed from the backing map (by the iterator's 8.01/2.98 * remove operation), the results of this call are undefined. 8.01/2.98 * 8.01/2.98 * @return the value corresponding to this entry 8.01/2.98 * @throws IllegalStateException implementations may, but are not 8.01/2.98 * required to, throw this exception if the entry has been 8.01/2.98 * removed from the backing map. 8.01/2.98 */ 8.01/2.98 V getValue(); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Replaces the value corresponding to this entry with the specified 8.01/2.98 * value (optional operation). (Writes through to the map.) The 8.01/2.98 * behavior of this call is undefined if the mapping has already been 8.01/2.98 * removed from the map (by the iterator's remove operation). 8.01/2.98 * 8.01/2.98 * @param value new value to be stored in this entry 8.01/2.98 * @return old value corresponding to the entry 8.01/2.98 * @throws UnsupportedOperationException if the put operation 8.01/2.98 * is not supported by the backing map 8.01/2.98 * @throws ClassCastException if the class of the specified value 8.01/2.98 * prevents it from being stored in the backing map 8.01/2.98 * @throws NullPointerException if the backing map does not permit 8.01/2.98 * null values, and the specified value is null 8.01/2.98 * @throws IllegalArgumentException if some property of this value 8.01/2.98 * prevents it from being stored in the backing map 8.01/2.98 * @throws IllegalStateException implementations may, but are not 8.01/2.98 * required to, throw this exception if the entry has been 8.01/2.98 * removed from the backing map. 8.01/2.98 */ 8.01/2.98 V setValue(V value); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Compares the specified object with this entry for equality. 8.01/2.98 * Returns true if the given object is also a map entry and 8.01/2.98 * the two entries represent the same mapping. More formally, two 8.01/2.98 * entries e1 and e2 represent the same mapping 8.01/2.98 * if

8.01/2.98	         *     (e1.getKey()==null ?
8.01/2.98	         *      e2.getKey()==null : e1.getKey().equals(e2.getKey()))  &&
8.01/2.98	         *     (e1.getValue()==null ?
8.01/2.98	         *      e2.getValue()==null : e1.getValue().equals(e2.getValue()))
8.01/2.98	         * 
8.01/2.98 * This ensures that the equals method works properly across 8.01/2.98 * different implementations of the Map.Entry interface. 8.01/2.98 * 8.01/2.98 * @param o object to be compared for equality with this map entry 8.01/2.98 * @return true if the specified object is equal to this map 8.01/2.98 * entry 8.01/2.98 */ 8.01/2.98 boolean equals(Object o); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns the hash code value for this map entry. The hash code 8.01/2.98 * of a map entry e is defined to be:
8.01/2.98	         *     (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
8.01/2.98	         *     (e.getValue()==null ? 0 : e.getValue().hashCode())
8.01/2.98	         * 
8.01/2.98 * This ensures that e1.equals(e2) implies that 8.01/2.98 * e1.hashCode()==e2.hashCode() for any two Entries 8.01/2.98 * e1 and e2, as required by the general 8.01/2.98 * contract of Object.hashCode. 8.01/2.98 * 8.01/2.98 * @return the hash code value for this map entry 8.01/2.98 * @see Object#hashCode() 8.01/2.98 * @see Object#equals(Object) 8.01/2.98 * @see #equals(Object) 8.01/2.98 */ 8.01/2.98 int hashCode(); 8.01/2.98 } 8.01/2.98 8.01/2.98 // Comparison and hashing 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Compares the specified object with this map for equality. Returns 8.01/2.98 * true if the given object is also a map and the two maps 8.01/2.98 * represent the same mappings. More formally, two maps m1 and 8.01/2.98 * m2 represent the same mappings if 8.01/2.98 * m1.entrySet().equals(m2.entrySet()). This ensures that the 8.01/2.98 * equals method works properly across different implementations 8.01/2.98 * of the Map interface. 8.01/2.98 * 8.01/2.98 * @param o object to be compared for equality with this map 8.01/2.98 * @return true if the specified object is equal to this map 8.01/2.98 */ 8.01/2.98 boolean equals(Object o); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns the hash code value for this map. The hash code of a map is 8.01/2.98 * defined to be the sum of the hash codes of each entry in the map's 8.01/2.98 * entrySet() view. This ensures that m1.equals(m2) 8.01/2.98 * implies that m1.hashCode()==m2.hashCode() for any two maps 8.01/2.98 * m1 and m2, as required by the general contract of 8.01/2.98 * {@link Object#hashCode}. 8.01/2.98 * 8.01/2.98 * @return the hash code value for this map 8.01/2.98 * @see Map.Entry#hashCode() 8.01/2.98 * @see Object#equals(Object) 8.01/2.98 * @see #equals(Object) 8.01/2.98 */ 8.01/2.98 int hashCode(); 8.01/2.98 } 8.01/2.98 8.01/2.98 8.01/2.98 /* 8.01/2.98 * Copyright 1994-1998 Sun Microsystems, Inc. All Rights Reserved. 8.01/2.98 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.01/2.98 * 8.01/2.98 * This code is free software; you can redistribute it and/or modify it 8.01/2.98 * under the terms of the GNU General Public License version 2 only, as 8.01/2.98 * published by the Free Software Foundation. Sun designates this 8.01/2.98 * particular file as subject to the "Classpath" exception as provided 8.01/2.98 * by Sun in the LICENSE file that accompanied this code. 8.01/2.98 * 8.01/2.98 * This code is distributed in the hope that it will be useful, but WITHOUT 8.01/2.98 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.01/2.98 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.01/2.98 * version 2 for more details (a copy is included in the LICENSE file that 8.01/2.98 * accompanied this code). 8.01/2.98 * 8.01/2.98 * You should have received a copy of the GNU General Public License version 8.01/2.98 * 2 along with this work; if not, write to the Free Software Foundation, 8.01/2.98 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.01/2.98 * 8.01/2.98 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 8.01/2.98 * CA 95054 USA or visit www.sun.com if you need additional information or 8.01/2.98 * have any questions. 8.01/2.98 */ 8.01/2.98 8.01/2.98 package javaUtilEx; 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Thrown by the nextElement method of an 8.01/2.98 * Enumeration to indicate that there are no more 8.01/2.98 * elements in the enumeration. 8.01/2.98 * 8.01/2.98 * @author unascribed 8.01/2.98 * @see java.util.Enumeration 8.01/2.98 * @see java.util.Enumeration#nextElement() 8.01/2.98 * @since JDK1.0 8.01/2.98 */ 8.01/2.98 public 8.01/2.98 class NoSuchElementException extends RuntimeException { 8.01/2.98 /** 8.01/2.98 * Constructs a NoSuchElementException with null 8.01/2.98 * as its error message string. 8.01/2.98 */ 8.01/2.98 public NoSuchElementException() { 8.01/2.98 super(); 8.01/2.98 } 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Constructs a NoSuchElementException, saving a reference 8.01/2.98 * to the error message string s for later retrieval by the 8.01/2.98 * getMessage method. 8.01/2.98 * 8.01/2.98 * @param s the detail message. 8.01/2.98 */ 8.01/2.98 public NoSuchElementException(String s) { 8.01/2.98 super(s); 8.01/2.98 } 8.01/2.98 } 8.01/2.98 8.01/2.98 8.01/2.98 package javaUtilEx; 8.01/2.98 8.01/2.98 public class Random { 8.01/2.98 static String[] args; 8.01/2.98 static int index = 0; 8.01/2.98 8.01/2.98 public static int random() { 8.01/2.98 String string = args[index]; 8.01/2.98 index++; 8.01/2.98 return string.length(); 8.01/2.98 } 8.01/2.98 } 8.01/2.98 8.01/2.98 8.01/2.98 /* 8.01/2.98 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 8.01/2.98 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.01/2.98 * 8.01/2.98 * This code is free software; you can redistribute it and/or modify it 8.01/2.98 * under the terms of the GNU General Public License version 2 only, as 8.01/2.98 * published by the Free Software Foundation. Sun designates this 8.01/2.98 * particular file as subject to the "Classpath" exception as provided 8.01/2.98 * by Sun in the LICENSE file that accompanied this code. 8.01/2.98 * 8.01/2.98 * This code is distributed in the hope that it will be useful, but WITHOUT 8.01/2.98 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.01/2.98 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.01/2.98 * version 2 for more details (a copy is included in the LICENSE file that 8.01/2.98 * accompanied this code). 8.01/2.98 * 8.01/2.98 * You should have received a copy of the GNU General Public License version 8.01/2.98 * 2 along with this work; if not, write to the Free Software Foundation, 8.01/2.98 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.01/2.98 * 8.01/2.98 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 8.01/2.98 * CA 95054 USA or visit www.sun.com if you need additional information or 8.01/2.98 * have any questions. 8.01/2.98 */ 8.01/2.98 8.01/2.98 package javaUtilEx; 8.01/2.98 8.01/2.98 /** 8.01/2.98 * A collection that contains no duplicate elements. More formally, sets 8.01/2.98 * contain no pair of elements e1 and e2 such that 8.01/2.98 * e1.equals(e2), and at most one null element. As implied by 8.01/2.98 * its name, this interface models the mathematical set abstraction. 8.01/2.98 * 8.01/2.98 *

The Set interface places additional stipulations, beyond those 8.01/2.98 * inherited from the Collection interface, on the contracts of all 8.01/2.98 * constructors and on the contracts of the add, equals and 8.01/2.98 * hashCode methods. Declarations for other inherited methods are 8.01/2.98 * also included here for convenience. (The specifications accompanying these 8.01/2.98 * declarations have been tailored to the Set interface, but they do 8.01/2.98 * not contain any additional stipulations.) 8.01/2.98 * 8.01/2.98 *

The additional stipulation on constructors is, not surprisingly, 8.01/2.98 * that all constructors must create a set that contains no duplicate elements 8.01/2.98 * (as defined above). 8.01/2.98 * 8.01/2.98 *

Note: Great care must be exercised if mutable objects are used as set 8.01/2.98 * elements. The behavior of a set is not specified if the value of an object 8.01/2.98 * is changed in a manner that affects equals comparisons while the 8.01/2.98 * object is an element in the set. A special case of this prohibition is 8.01/2.98 * that it is not permissible for a set to contain itself as an element. 8.01/2.98 * 8.01/2.98 *

Some set implementations have restrictions on the elements that 8.01/2.98 * they may contain. For example, some implementations prohibit null elements, 8.01/2.98 * and some have restrictions on the types of their elements. Attempting to 8.01/2.98 * add an ineligible element throws an unchecked exception, typically 8.01/2.98 * NullPointerException or ClassCastException. Attempting 8.01/2.98 * to query the presence of an ineligible element may throw an exception, 8.01/2.98 * or it may simply return false; some implementations will exhibit the former 8.01/2.98 * behavior and some will exhibit the latter. More generally, attempting an 8.01/2.98 * operation on an ineligible element whose completion would not result in 8.01/2.98 * the insertion of an ineligible element into the set may throw an 8.01/2.98 * exception or it may succeed, at the option of the implementation. 8.01/2.98 * Such exceptions are marked as "optional" in the specification for this 8.01/2.98 * interface. 8.01/2.98 * 8.01/2.98 *

This interface is a member of the 8.01/2.98 * 8.01/2.98 * Java Collections Framework. 8.01/2.98 * 8.01/2.98 * @param the type of elements maintained by this set 8.01/2.98 * 8.01/2.98 * @author Josh Bloch 8.01/2.98 * @author Neal Gafter 8.01/2.98 * @see Collection 8.01/2.98 * @see List 8.01/2.98 * @see SortedSet 8.01/2.98 * @see HashSet 8.01/2.98 * @see TreeSet 8.01/2.98 * @see AbstractSet 8.01/2.98 * @see Collections#singleton(java.lang.Object) 8.01/2.98 * @see Collections#EMPTY_SET 8.01/2.98 * @since 1.2 8.01/2.98 */ 8.01/2.98 8.01/2.98 public interface Set extends Collection { 8.01/2.98 // Query Operations 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns the number of elements in this set (its cardinality). If this 8.01/2.98 * set contains more than Integer.MAX_VALUE elements, returns 8.01/2.98 * Integer.MAX_VALUE. 8.01/2.98 * 8.01/2.98 * @return the number of elements in this set (its cardinality) 8.01/2.98 */ 8.01/2.98 int size(); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns true if this set contains no elements. 8.01/2.98 * 8.01/2.98 * @return true if this set contains no elements 8.01/2.98 */ 8.01/2.98 boolean isEmpty(); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns true if this set contains the specified element. 8.01/2.98 * More formally, returns true if and only if this set 8.01/2.98 * contains an element e such that 8.01/2.98 * (o==null ? e==null : o.equals(e)). 8.01/2.98 * 8.01/2.98 * @param o element whose presence in this set is to be tested 8.01/2.98 * @return true if this set contains the specified element 8.01/2.98 * @throws ClassCastException if the type of the specified element 8.01/2.98 * is incompatible with this set (optional) 8.01/2.98 * @throws NullPointerException if the specified element is null and this 8.01/2.98 * set does not permit null elements (optional) 8.01/2.98 */ 8.01/2.98 boolean contains(Object o); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns an iterator over the elements in this set. The elements are 8.01/2.98 * returned in no particular order (unless this set is an instance of some 8.01/2.98 * class that provides a guarantee). 8.01/2.98 * 8.01/2.98 * @return an iterator over the elements in this set 8.01/2.98 */ 8.01/2.98 Iterator iterator(); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns an array containing all of the elements in this set. 8.01/2.98 * If this set makes any guarantees as to what order its elements 8.01/2.98 * are returned by its iterator, this method must return the 8.01/2.98 * elements in the same order. 8.01/2.98 * 8.01/2.98 *

The returned array will be "safe" in that no references to it 8.01/2.98 * are maintained by this set. (In other words, this method must 8.01/2.98 * allocate a new array even if this set is backed by an array). 8.01/2.98 * The caller is thus free to modify the returned array. 8.01/2.98 * 8.01/2.98 *

This method acts as bridge between array-based and collection-based 8.01/2.98 * APIs. 8.01/2.98 * 8.01/2.98 * @return an array containing all the elements in this set 8.01/2.98 */ 8.01/2.98 Object[] toArray(); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns an array containing all of the elements in this set; the 8.01/2.98 * runtime type of the returned array is that of the specified array. 8.01/2.98 * If the set fits in the specified array, it is returned therein. 8.01/2.98 * Otherwise, a new array is allocated with the runtime type of the 8.01/2.98 * specified array and the size of this set. 8.01/2.98 * 8.01/2.98 *

If this set fits in the specified array with room to spare 8.01/2.98 * (i.e., the array has more elements than this set), the element in 8.01/2.98 * the array immediately following the end of the set is set to 8.01/2.98 * null. (This is useful in determining the length of this 8.01/2.98 * set only if the caller knows that this set does not contain 8.01/2.98 * any null elements.) 8.01/2.98 * 8.01/2.98 *

If this set makes any guarantees as to what order its elements 8.01/2.98 * are returned by its iterator, this method must return the elements 8.01/2.98 * in the same order. 8.01/2.98 * 8.01/2.98 *

Like the {@link #toArray()} method, this method acts as bridge between 8.01/2.98 * array-based and collection-based APIs. Further, this method allows 8.01/2.98 * precise control over the runtime type of the output array, and may, 8.01/2.98 * under certain circumstances, be used to save allocation costs. 8.01/2.98 * 8.01/2.98 *

Suppose x is a set known to contain only strings. 8.01/2.98 * The following code can be used to dump the set into a newly allocated 8.01/2.98 * array of String: 8.01/2.98 * 8.01/2.98 *

8.01/2.98	     *     String[] y = x.toArray(new String[0]);
8.01/2.98 * 8.01/2.98 * Note that toArray(new Object[0]) is identical in function to 8.01/2.98 * toArray(). 8.01/2.98 * 8.01/2.98 * @param a the array into which the elements of this set are to be 8.01/2.98 * stored, if it is big enough; otherwise, a new array of the same 8.01/2.98 * runtime type is allocated for this purpose. 8.01/2.98 * @return an array containing all the elements in this set 8.01/2.98 * @throws ArrayStoreException if the runtime type of the specified array 8.01/2.98 * is not a supertype of the runtime type of every element in this 8.01/2.98 * set 8.01/2.98 * @throws NullPointerException if the specified array is null 8.01/2.98 */ 8.01/2.98 T[] toArray(T[] a); 8.01/2.98 8.01/2.98 8.01/2.98 // Modification Operations 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Adds the specified element to this set if it is not already present 8.01/2.98 * (optional operation). More formally, adds the specified element 8.01/2.98 * e to this set if the set contains no element e2 8.01/2.98 * such that 8.01/2.98 * (e==null ? e2==null : e.equals(e2)). 8.01/2.98 * If this set already contains the element, the call leaves the set 8.01/2.98 * unchanged and returns false. In combination with the 8.01/2.98 * restriction on constructors, this ensures that sets never contain 8.01/2.98 * duplicate elements. 8.01/2.98 * 8.01/2.98 *

The stipulation above does not imply that sets must accept all 8.01/2.98 * elements; sets may refuse to add any particular element, including 8.01/2.98 * null, and throw an exception, as described in the 8.01/2.98 * specification for {@link Collection#add Collection.add}. 8.01/2.98 * Individual set implementations should clearly document any 8.01/2.98 * restrictions on the elements that they may contain. 8.01/2.98 * 8.01/2.98 * @param e element to be added to this set 8.01/2.98 * @return true if this set did not already contain the specified 8.01/2.98 * element 8.01/2.98 * @throws UnsupportedOperationException if the add operation 8.01/2.98 * is not supported by this set 8.01/2.98 * @throws ClassCastException if the class of the specified element 8.01/2.98 * prevents it from being added to this set 8.01/2.98 * @throws NullPointerException if the specified element is null and this 8.01/2.98 * set does not permit null elements 8.01/2.98 * @throws IllegalArgumentException if some property of the specified element 8.01/2.98 * prevents it from being added to this set 8.01/2.98 */ 8.01/2.98 boolean add(E e); 8.01/2.98 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Removes the specified element from this set if it is present 8.01/2.98 * (optional operation). More formally, removes an element e 8.01/2.98 * such that 8.01/2.98 * (o==null ? e==null : o.equals(e)), if 8.01/2.98 * this set contains such an element. Returns true if this set 8.01/2.98 * contained the element (or equivalently, if this set changed as a 8.01/2.98 * result of the call). (This set will not contain the element once the 8.01/2.98 * call returns.) 8.01/2.98 * 8.01/2.98 * @param o object to be removed from this set, if present 8.01/2.98 * @return true if this set contained the specified element 8.01/2.98 * @throws ClassCastException if the type of the specified element 8.01/2.98 * is incompatible with this set (optional) 8.01/2.98 * @throws NullPointerException if the specified element is null and this 8.01/2.98 * set does not permit null elements (optional) 8.01/2.98 * @throws UnsupportedOperationException if the remove operation 8.01/2.98 * is not supported by this set 8.01/2.98 */ 8.01/2.98 boolean remove(Object o); 8.01/2.98 8.01/2.98 8.01/2.98 // Bulk Operations 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns true if this set contains all of the elements of the 8.01/2.98 * specified collection. If the specified collection is also a set, this 8.01/2.98 * method returns true if it is a subset of this set. 8.01/2.98 * 8.01/2.98 * @param c collection to be checked for containment in this set 8.01/2.98 * @return true if this set contains all of the elements of the 8.01/2.98 * specified collection 8.01/2.98 * @throws ClassCastException if the types of one or more elements 8.01/2.98 * in the specified collection are incompatible with this 8.01/2.98 * set (optional) 8.01/2.98 * @throws NullPointerException if the specified collection contains one 8.01/2.98 * or more null elements and this set does not permit null 8.01/2.98 * elements (optional), or if the specified collection is null 8.01/2.98 * @see #contains(Object) 8.01/2.98 */ 8.01/2.98 boolean containsAll(Collection c); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Adds all of the elements in the specified collection to this set if 8.01/2.98 * they're not already present (optional operation). If the specified 8.01/2.98 * collection is also a set, the addAll operation effectively 8.01/2.98 * modifies this set so that its value is the union of the two 8.01/2.98 * sets. The behavior of this operation is undefined if the specified 8.01/2.98 * collection is modified while the operation is in progress. 8.01/2.98 * 8.01/2.98 * @param c collection containing elements to be added to this set 8.01/2.98 * @return true if this set changed as a result of the call 8.01/2.98 * 8.01/2.98 * @throws UnsupportedOperationException if the addAll operation 8.01/2.98 * is not supported by this set 8.01/2.98 * @throws ClassCastException if the class of an element of the 8.01/2.98 * specified collection prevents it from being added to this set 8.01/2.98 * @throws NullPointerException if the specified collection contains one 8.01/2.98 * or more null elements and this set does not permit null 8.01/2.98 * elements, or if the specified collection is null 8.01/2.98 * @throws IllegalArgumentException if some property of an element of the 8.01/2.98 * specified collection prevents it from being added to this set 8.01/2.98 * @see #add(Object) 8.01/2.98 */ 8.01/2.98 boolean addAll(Collection c); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Retains only the elements in this set that are contained in the 8.01/2.98 * specified collection (optional operation). In other words, removes 8.01/2.98 * from this set all of its elements that are not contained in the 8.01/2.98 * specified collection. If the specified collection is also a set, this 8.01/2.98 * operation effectively modifies this set so that its value is the 8.01/2.98 * intersection of the two sets. 8.01/2.98 * 8.01/2.98 * @param c collection containing elements to be retained in this set 8.01/2.98 * @return true if this set changed as a result of the call 8.01/2.98 * @throws UnsupportedOperationException if the retainAll operation 8.01/2.98 * is not supported by this set 8.01/2.98 * @throws ClassCastException if the class of an element of this set 8.01/2.98 * is incompatible with the specified collection (optional) 8.01/2.98 * @throws NullPointerException if this set contains a null element and the 8.01/2.98 * specified collection does not permit null elements (optional), 8.01/2.98 * or if the specified collection is null 8.01/2.98 * @see #remove(Object) 8.01/2.98 */ 8.01/2.98 boolean retainAll(Collection c); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Removes from this set all of its elements that are contained in the 8.01/2.98 * specified collection (optional operation). If the specified 8.01/2.98 * collection is also a set, this operation effectively modifies this 8.01/2.98 * set so that its value is the asymmetric set difference of 8.01/2.98 * the two sets. 8.01/2.98 * 8.01/2.98 * @param c collection containing elements to be removed from this set 8.01/2.98 * @return true if this set changed as a result of the call 8.01/2.98 * @throws UnsupportedOperationException if the removeAll operation 8.01/2.98 * is not supported by this set 8.01/2.98 * @throws ClassCastException if the class of an element of this set 8.01/2.98 * is incompatible with the specified collection (optional) 8.01/2.98 * @throws NullPointerException if this set contains a null element and the 8.01/2.98 * specified collection does not permit null elements (optional), 8.01/2.98 * or if the specified collection is null 8.01/2.98 * @see #remove(Object) 8.01/2.98 * @see #contains(Object) 8.01/2.98 */ 8.01/2.98 boolean removeAll(Collection c); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Removes all of the elements from this set (optional operation). 8.01/2.98 * The set will be empty after this call returns. 8.01/2.98 * 8.01/2.98 * @throws UnsupportedOperationException if the clear method 8.01/2.98 * is not supported by this set 8.01/2.98 */ 8.01/2.98 void clear(); 8.01/2.98 8.01/2.98 8.01/2.98 // Comparison and hashing 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Compares the specified object with this set for equality. Returns 8.01/2.98 * true if the specified object is also a set, the two sets 8.01/2.98 * have the same size, and every member of the specified set is 8.01/2.98 * contained in this set (or equivalently, every member of this set is 8.01/2.98 * contained in the specified set). This definition ensures that the 8.01/2.98 * equals method works properly across different implementations of the 8.01/2.98 * set interface. 8.01/2.98 * 8.01/2.98 * @param o object to be compared for equality with this set 8.01/2.98 * @return true if the specified object is equal to this set 8.01/2.98 */ 8.01/2.98 boolean equals(Object o); 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Returns the hash code value for this set. The hash code of a set is 8.01/2.98 * defined to be the sum of the hash codes of the elements in the set, 8.01/2.98 * where the hash code of a null element is defined to be zero. 8.01/2.98 * This ensures that s1.equals(s2) implies that 8.01/2.98 * s1.hashCode()==s2.hashCode() for any two sets s1 8.01/2.98 * and s2, as required by the general contract of 8.01/2.98 * {@link Object#hashCode}. 8.01/2.98 * 8.01/2.98 * @return the hash code value for this set 8.01/2.98 * @see Object#equals(Object) 8.01/2.98 * @see Set#equals(Object) 8.01/2.98 */ 8.01/2.98 int hashCode(); 8.01/2.98 } 8.01/2.98 8.01/2.98 8.01/2.98 /* 8.01/2.98 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 8.01/2.98 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.01/2.98 * 8.01/2.98 * This code is free software; you can redistribute it and/or modify it 8.01/2.98 * under the terms of the GNU General Public License version 2 only, as 8.01/2.98 * published by the Free Software Foundation. Sun designates this 8.01/2.98 * particular file as subject to the "Classpath" exception as provided 8.01/2.98 * by Sun in the LICENSE file that accompanied this code. 8.01/2.98 * 8.01/2.98 * This code is distributed in the hope that it will be useful, but WITHOUT 8.01/2.98 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.01/2.98 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.01/2.98 * version 2 for more details (a copy is included in the LICENSE file that 8.01/2.98 * accompanied this code). 8.01/2.98 * 8.01/2.98 * You should have received a copy of the GNU General Public License version 8.01/2.98 * 2 along with this work; if not, write to the Free Software Foundation, 8.01/2.98 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.01/2.98 * 8.01/2.98 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 8.01/2.98 * CA 95054 USA or visit www.sun.com if you need additional information or 8.01/2.98 * have any questions. 8.01/2.98 */ 8.01/2.98 8.01/2.98 package javaUtilEx; 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Thrown to indicate that the requested operation is not supported.

8.01/2.98 * 8.01/2.98 * This class is a member of the 8.01/2.98 * 8.01/2.98 * Java Collections Framework. 8.01/2.98 * 8.01/2.98 * @author Josh Bloch 8.01/2.98 * @since 1.2 8.01/2.98 */ 8.01/2.98 public class UnsupportedOperationException extends RuntimeException { 8.01/2.98 /** 8.01/2.98 * Constructs an UnsupportedOperationException with no detail message. 8.01/2.98 */ 8.01/2.98 public UnsupportedOperationException() { 8.01/2.98 } 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Constructs an UnsupportedOperationException with the specified 8.01/2.98 * detail message. 8.01/2.98 * 8.01/2.98 * @param message the detail message 8.01/2.98 */ 8.01/2.98 public UnsupportedOperationException(String message) { 8.01/2.98 super(message); 8.01/2.98 } 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Constructs a new exception with the specified detail message and 8.01/2.98 * cause. 8.01/2.98 * 8.01/2.98 *

Note that the detail message associated with cause is 8.01/2.98 * not automatically incorporated in this exception's detail 8.01/2.98 * message. 8.01/2.98 * 8.01/2.98 * @param message the detail message (which is saved for later retrieval 8.01/2.98 * by the {@link Throwable#getMessage()} method). 8.01/2.98 * @param cause the cause (which is saved for later retrieval by the 8.01/2.98 * {@link Throwable#getCause()} method). (A null value 8.01/2.98 * is permitted, and indicates that the cause is nonexistent or 8.01/2.98 * unknown.) 8.01/2.98 * @since 1.5 8.01/2.98 */ 8.01/2.98 public UnsupportedOperationException(String message, Throwable cause) { 8.01/2.98 super(message, cause); 8.01/2.98 } 8.01/2.98 8.01/2.98 /** 8.01/2.98 * Constructs a new exception with the specified cause and a detail 8.01/2.98 * message of (cause==null ? null : cause.toString()) (which 8.01/2.98 * typically contains the class and detail message of cause). 8.01/2.98 * This constructor is useful for exceptions that are little more than 8.01/2.98 * wrappers for other throwables (for example, {@link 8.01/2.98 * java.security.PrivilegedActionException}). 8.01/2.98 * 8.01/2.98 * @param cause the cause (which is saved for later retrieval by the 8.01/2.98 * {@link Throwable#getCause()} method). (A null value is 8.01/2.98 * permitted, and indicates that the cause is nonexistent or 8.01/2.98 * unknown.) 8.01/2.98 * @since 1.5 8.01/2.98 */ 8.01/2.98 public UnsupportedOperationException(Throwable cause) { 8.01/2.98 super(cause); 8.01/2.98 } 8.01/2.98 8.01/2.98 static final long serialVersionUID = -1242599979055084673L; 8.01/2.98 } 8.01/2.98 8.01/2.98 8.17/3.05 EOF