7.31/2.78 MAYBE 7.65/2.80 proof of /export/starexec/sandbox/benchmark/theBenchmark.jar 7.65/2.80 # AProVE Commit ID: 48fb2092695e11cc9f56e44b17a92a5f88ffb256 marcel 20180622 unpublished dirty 7.65/2.80 7.65/2.80 7.65/2.80 termination of the given Bare JBC problem could not be shown: 7.65/2.80 7.65/2.80 (0) Bare JBC problem 7.65/2.80 (1) BareJBCToJBCProof [EQUIVALENT, 94 ms] 7.65/2.80 (2) JBC problem 7.65/2.80 7.65/2.80 7.65/2.80 ---------------------------------------- 7.65/2.80 7.65/2.80 (0) 7.65/2.80 Obligation: 7.65/2.80 need to prove termination of the following program: 7.65/2.80 /* 7.65/2.80 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 7.65/2.80 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.65/2.80 * 7.65/2.80 * This code is free software; you can redistribute it and/or modify it 7.65/2.80 * under the terms of the GNU General Public License version 2 only, as 7.65/2.80 * published by the Free Software Foundation. Sun designates this 7.65/2.80 * particular file as subject to the "Classpath" exception as provided 7.65/2.80 * by Sun in the LICENSE file that accompanied this code. 7.65/2.80 * 7.65/2.80 * This code is distributed in the hope that it will be useful, but WITHOUT 7.65/2.80 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.65/2.80 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.65/2.80 * version 2 for more details (a copy is included in the LICENSE file that 7.65/2.80 * accompanied this code). 7.65/2.80 * 7.65/2.80 * You should have received a copy of the GNU General Public License version 7.65/2.80 * 2 along with this work; if not, write to the Free Software Foundation, 7.65/2.80 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.65/2.80 * 7.65/2.80 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 7.65/2.80 * CA 95054 USA or visit www.sun.com if you need additional information or 7.65/2.80 * have any questions. 7.65/2.80 */ 7.65/2.80 7.65/2.80 package javaUtilEx; 7.65/2.80 7.65/2.80 /** 7.65/2.80 * This class provides a skeletal implementation of the Collection 7.65/2.80 * interface, to minimize the effort required to implement this interface.

7.65/2.80 * 7.65/2.80 * To implement an unmodifiable collection, the programmer needs only to 7.65/2.80 * extend this class and provide implementations for the iterator and 7.65/2.80 * size methods. (The iterator returned by the iterator 7.65/2.80 * method must implement hasNext and next.)

7.65/2.80 * 7.65/2.80 * To implement a modifiable collection, the programmer must additionally 7.65/2.80 * override this class's add method (which otherwise throws an 7.65/2.80 * UnsupportedOperationException), and the iterator returned by the 7.65/2.80 * iterator method must additionally implement its remove 7.65/2.80 * method.

7.65/2.80 * 7.65/2.80 * The programmer should generally provide a void (no argument) and 7.65/2.80 * Collection constructor, as per the recommendation in the 7.65/2.80 * Collection interface specification.

7.65/2.80 * 7.65/2.80 * The documentation for each non-abstract method in this class describes its 7.65/2.80 * implementation in detail. Each of these methods may be overridden if 7.65/2.80 * the collection being implemented admits a more efficient implementation.

7.65/2.80 * 7.65/2.80 * This class is a member of the 7.65/2.80 * 7.65/2.80 * Java Collections Framework. 7.65/2.80 * 7.65/2.80 * @author Josh Bloch 7.65/2.80 * @author Neal Gafter 7.65/2.80 * @see Collection 7.65/2.80 * @since 1.2 7.65/2.80 */ 7.65/2.80 7.65/2.80 public abstract class AbstractCollection implements Collection { 7.65/2.80 /** 7.65/2.80 * Sole constructor. (For invocation by subclass constructors, typically 7.65/2.80 * implicit.) 7.65/2.80 */ 7.65/2.80 protected AbstractCollection() { 7.65/2.80 } 7.65/2.80 7.65/2.80 // Query Operations 7.65/2.80 7.65/2.80 /** 7.65/2.80 * Returns an iterator over the elements contained in this collection. 7.65/2.80 * 7.65/2.80 * @return an iterator over the elements contained in this collection 7.65/2.80 */ 7.65/2.80 public abstract Iterator iterator(); 7.65/2.80 7.65/2.80 public abstract int size(); 7.65/2.80 7.65/2.80 /** 7.65/2.80 * {@inheritDoc} 7.65/2.80 * 7.65/2.80 *

This implementation returns size() == 0. 7.65/2.80 */ 7.65/2.80 public boolean isEmpty() { 7.65/2.80 return size() == 0; 7.65/2.80 } 7.65/2.80 7.65/2.80 /** 7.65/2.80 * {@inheritDoc} 7.65/2.80 * 7.65/2.80 *

This implementation iterates over the elements in the collection, 7.65/2.80 * checking each element in turn for equality with the specified element. 7.65/2.80 * 7.65/2.80 * @throws ClassCastException {@inheritDoc} 7.65/2.80 * @throws NullPointerException {@inheritDoc} 7.65/2.80 */ 7.65/2.80 public boolean contains(Object o) { 7.65/2.80 Iterator e = iterator(); 7.65/2.80 if (o==null) { 7.65/2.80 while (e.hasNext()) 7.65/2.80 if (e.next()==null) 7.65/2.80 return true; 7.65/2.80 } else { 7.65/2.80 while (e.hasNext()) 7.65/2.80 if (o.equals(e.next())) 7.65/2.80 return true; 7.65/2.80 } 7.65/2.80 return false; 7.65/2.80 } 7.65/2.80 7.65/2.80 // Modification Operations 7.65/2.80 7.65/2.80 /** 7.65/2.80 * {@inheritDoc} 7.65/2.80 * 7.65/2.80 *

This implementation always throws an 7.65/2.80 * UnsupportedOperationException. 7.65/2.80 * 7.65/2.80 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.80 * @throws ClassCastException {@inheritDoc} 7.65/2.80 * @throws NullPointerException {@inheritDoc} 7.65/2.80 * @throws IllegalArgumentException {@inheritDoc} 7.65/2.80 * @throws IllegalStateException {@inheritDoc} 7.65/2.80 */ 7.65/2.80 public boolean add(E e) { 7.65/2.80 throw new UnsupportedOperationException(); 7.65/2.80 } 7.65/2.80 7.65/2.80 /** 7.65/2.80 * {@inheritDoc} 7.65/2.80 * 7.65/2.80 *

This implementation iterates over the collection looking for the 7.65/2.80 * specified element. If it finds the element, it removes the element 7.65/2.80 * from the collection using the iterator's remove method. 7.65/2.80 * 7.65/2.80 *

Note that this implementation throws an 7.65/2.80 * UnsupportedOperationException if the iterator returned by this 7.65/2.80 * collection's iterator method does not implement the remove 7.65/2.80 * method and this collection contains the specified object. 7.65/2.80 * 7.65/2.80 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.80 * @throws ClassCastException {@inheritDoc} 7.65/2.80 * @throws NullPointerException {@inheritDoc} 7.65/2.80 */ 7.65/2.80 public boolean remove(Object o) { 7.65/2.80 Iterator e = iterator(); 7.65/2.80 if (o==null) { 7.65/2.80 while (e.hasNext()) { 7.65/2.80 if (e.next()==null) { 7.65/2.80 e.remove(); 7.65/2.80 return true; 7.65/2.80 } 7.65/2.80 } 7.65/2.80 } else { 7.65/2.80 while (e.hasNext()) { 7.65/2.80 if (o.equals(e.next())) { 7.65/2.80 e.remove(); 7.65/2.80 return true; 7.65/2.80 } 7.65/2.80 } 7.65/2.80 } 7.65/2.80 return false; 7.65/2.80 } 7.65/2.80 7.65/2.80 7.65/2.80 // Bulk Operations 7.65/2.80 7.65/2.80 /** 7.65/2.80 * {@inheritDoc} 7.65/2.80 * 7.65/2.80 *

This implementation iterates over the specified collection, 7.65/2.80 * checking each element returned by the iterator in turn to see 7.65/2.80 * if it's contained in this collection. If all elements are so 7.65/2.80 * contained true is returned, otherwise false. 7.65/2.80 * 7.65/2.80 * @throws ClassCastException {@inheritDoc} 7.65/2.80 * @throws NullPointerException {@inheritDoc} 7.65/2.80 * @see #contains(Object) 7.65/2.80 */ 7.65/2.80 public boolean containsAll(Collection c) { 7.65/2.80 Iterator e = c.iterator(); 7.65/2.80 while (e.hasNext()) 7.65/2.80 if (!contains(e.next())) 7.65/2.80 return false; 7.65/2.80 return true; 7.65/2.80 } 7.65/2.80 7.65/2.80 /** 7.65/2.80 * {@inheritDoc} 7.65/2.80 * 7.65/2.80 *

This implementation iterates over the specified collection, and adds 7.65/2.80 * each object returned by the iterator to this collection, in turn. 7.65/2.80 * 7.65/2.80 *

Note that this implementation will throw an 7.65/2.80 * UnsupportedOperationException unless add is 7.65/2.80 * overridden (assuming the specified collection is non-empty). 7.65/2.80 * 7.65/2.80 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.80 * @throws ClassCastException {@inheritDoc} 7.65/2.80 * @throws NullPointerException {@inheritDoc} 7.65/2.80 * @throws IllegalArgumentException {@inheritDoc} 7.65/2.80 * @throws IllegalStateException {@inheritDoc} 7.65/2.80 * 7.65/2.80 * @see #add(Object) 7.65/2.80 */ 7.65/2.80 public boolean addAll(Collection c) { 7.65/2.80 boolean modified = false; 7.65/2.80 Iterator e = c.iterator(); 7.65/2.80 while (e.hasNext()) { 7.65/2.80 if (add(e.next())) 7.65/2.80 modified = true; 7.65/2.80 } 7.65/2.80 return modified; 7.65/2.80 } 7.65/2.80 7.65/2.80 /** 7.65/2.80 * {@inheritDoc} 7.65/2.80 * 7.65/2.80 *

This implementation iterates over this collection, checking each 7.65/2.80 * element returned by the iterator in turn to see if it's contained 7.65/2.80 * in the specified collection. If it's so contained, it's removed from 7.65/2.80 * this collection with the iterator's remove method. 7.65/2.80 * 7.65/2.80 *

Note that this implementation will throw an 7.65/2.80 * UnsupportedOperationException if the iterator returned by the 7.65/2.80 * iterator method does not implement the remove method 7.65/2.80 * and this collection contains one or more elements in common with the 7.65/2.80 * specified collection. 7.65/2.80 * 7.65/2.80 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.80 * @throws ClassCastException {@inheritDoc} 7.65/2.80 * @throws NullPointerException {@inheritDoc} 7.65/2.80 * 7.65/2.80 * @see #remove(Object) 7.65/2.80 * @see #contains(Object) 7.65/2.80 */ 7.65/2.80 public boolean removeAll(Collection c) { 7.65/2.80 boolean modified = false; 7.65/2.80 Iterator e = iterator(); 7.65/2.80 while (e.hasNext()) { 7.65/2.80 if (c.contains(e.next())) { 7.65/2.80 e.remove(); 7.65/2.80 modified = true; 7.65/2.80 } 7.65/2.80 } 7.65/2.80 return modified; 7.65/2.80 } 7.65/2.80 7.65/2.80 /** 7.65/2.80 * {@inheritDoc} 7.65/2.80 * 7.65/2.80 *

This implementation iterates over this collection, checking each 7.65/2.80 * element returned by the iterator in turn to see if it's contained 7.65/2.80 * in the specified collection. If it's not so contained, it's removed 7.65/2.80 * from this collection with the iterator's remove method. 7.65/2.80 * 7.65/2.80 *

Note that this implementation will throw an 7.65/2.80 * UnsupportedOperationException if the iterator returned by the 7.65/2.80 * iterator method does not implement the remove method 7.65/2.80 * and this collection contains one or more elements not present in the 7.65/2.80 * specified collection. 7.65/2.80 * 7.65/2.80 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.80 * @throws ClassCastException {@inheritDoc} 7.65/2.80 * @throws NullPointerException {@inheritDoc} 7.65/2.80 * 7.65/2.80 * @see #remove(Object) 7.65/2.80 * @see #contains(Object) 7.65/2.80 */ 7.65/2.80 public boolean retainAll(Collection c) { 7.65/2.80 boolean modified = false; 7.65/2.80 Iterator e = iterator(); 7.65/2.80 while (e.hasNext()) { 7.65/2.80 if (!c.contains(e.next())) { 7.65/2.80 e.remove(); 7.65/2.80 modified = true; 7.65/2.80 } 7.65/2.80 } 7.65/2.80 return modified; 7.65/2.80 } 7.65/2.80 7.65/2.80 /** 7.65/2.80 * {@inheritDoc} 7.65/2.80 * 7.65/2.80 *

This implementation iterates over this collection, removing each 7.65/2.80 * element using the Iterator.remove operation. Most 7.65/2.80 * implementations will probably choose to override this method for 7.65/2.80 * efficiency. 7.65/2.80 * 7.65/2.80 *

Note that this implementation will throw an 7.65/2.80 * UnsupportedOperationException if the iterator returned by this 7.65/2.80 * collection's iterator method does not implement the 7.65/2.80 * remove method and this collection is non-empty. 7.65/2.80 * 7.65/2.80 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.80 */ 7.65/2.80 public void clear() { 7.65/2.80 Iterator e = iterator(); 7.65/2.80 while (e.hasNext()) { 7.65/2.80 e.next(); 7.65/2.80 e.remove(); 7.65/2.80 } 7.65/2.80 } 7.65/2.80 7.65/2.80 7.65/2.80 // String conversion 7.65/2.80 7.65/2.80 /** 7.65/2.80 * Returns a string representation of this collection. The string 7.65/2.80 * representation consists of a list of the collection's elements in the 7.65/2.80 * order they are returned by its iterator, enclosed in square brackets 7.65/2.80 * ("[]"). Adjacent elements are separated by the characters 7.65/2.80 * ", " (comma and space). Elements are converted to strings as 7.65/2.80 * by {@link String#valueOf(Object)}. 7.65/2.80 * 7.65/2.80 * @return a string representation of this collection 7.65/2.80 */ 7.65/2.80 public String toString() { 7.65/2.80 Iterator i = iterator(); 7.65/2.80 if (! i.hasNext()) 7.65/2.80 return "[]"; 7.65/2.80 7.65/2.80 String sb = ""; 7.65/2.80 sb = sb + "["; 7.65/2.80 for (;;) { 7.65/2.80 E e = i.next(); 7.65/2.80 sb = sb + (e == this ? "(this Collection)" : e); 7.65/2.80 if (! i.hasNext()) { 7.65/2.80 sb = sb + "]"; 7.65/2.80 return sb; 7.65/2.80 } 7.65/2.80 sb = sb + ", "; 7.65/2.80 } 7.65/2.80 } 7.65/2.80 7.65/2.80 } 7.65/2.80 7.65/2.80 7.65/2.80 /* 7.65/2.80 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. 7.65/2.80 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.65/2.80 * 7.65/2.80 * This code is free software; you can redistribute it and/or modify it 7.65/2.80 * under the terms of the GNU General Public License version 2 only, as 7.65/2.80 * published by the Free Software Foundation. Sun designates this 7.65/2.80 * particular file as subject to the "Classpath" exception as provided 7.65/2.80 * by Sun in the LICENSE file that accompanied this code. 7.65/2.80 * 7.65/2.80 * This code is distributed in the hope that it will be useful, but WITHOUT 7.65/2.80 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.65/2.80 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.65/2.80 * version 2 for more details (a copy is included in the LICENSE file that 7.65/2.80 * accompanied this code). 7.65/2.80 * 7.65/2.80 * You should have received a copy of the GNU General Public License version 7.65/2.80 * 2 along with this work; if not, write to the Free Software Foundation, 7.65/2.80 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.65/2.80 * 7.65/2.80 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 7.65/2.80 * CA 95054 USA or visit www.sun.com if you need additional information or 7.65/2.80 * have any questions. 7.65/2.80 */ 7.65/2.80 7.65/2.80 package javaUtilEx; 7.65/2.80 import javaUtilEx.Map.Entry; 7.65/2.80 7.65/2.80 /** 7.65/2.80 * This class provides a skeletal implementation of the Map 7.65/2.80 * interface, to minimize the effort required to implement this interface. 7.65/2.80 * 7.65/2.80 *

To implement an unmodifiable map, the programmer needs only to extend this 7.65/2.80 * class and provide an implementation for the entrySet method, which 7.65/2.80 * returns a set-view of the map's mappings. Typically, the returned set 7.65/2.80 * will, in turn, be implemented atop AbstractSet. This set should 7.65/2.80 * not support the add or remove methods, and its iterator 7.65/2.80 * should not support the remove method. 7.65/2.80 * 7.65/2.80 *

To implement a modifiable map, the programmer must additionally override 7.65/2.80 * this class's put method (which otherwise throws an 7.65/2.80 * UnsupportedOperationException), and the iterator returned by 7.65/2.80 * entrySet().iterator() must additionally implement its 7.65/2.80 * remove method. 7.65/2.80 * 7.65/2.80 *

The programmer should generally provide a void (no argument) and map 7.65/2.80 * constructor, as per the recommendation in the Map interface 7.65/2.80 * specification. 7.65/2.80 * 7.65/2.80 *

The documentation for each non-abstract method in this class describes its 7.65/2.80 * implementation in detail. Each of these methods may be overridden if the 7.65/2.80 * map being implemented admits a more efficient implementation. 7.65/2.80 * 7.65/2.80 *

This class is a member of the 7.65/2.80 * 7.65/2.80 * Java Collections Framework. 7.65/2.80 * 7.65/2.80 * @param the type of keys maintained by this map 7.65/2.80 * @param the type of mapped values 7.65/2.80 * 7.65/2.80 * @author Josh Bloch 7.65/2.80 * @author Neal Gafter 7.65/2.80 * @see Map 7.65/2.80 * @see Collection 7.65/2.80 * @since 1.2 7.65/2.80 */ 7.65/2.80 7.65/2.80 public abstract class AbstractMap implements Map { 7.65/2.80 /** 7.65/2.80 * Sole constructor. (For invocation by subclass constructors, typically 7.65/2.80 * implicit.) 7.65/2.80 */ 7.65/2.80 protected AbstractMap() { 7.65/2.80 } 7.65/2.80 7.65/2.80 // Query Operations 7.65/2.80 7.65/2.80 /** 7.65/2.80 * {@inheritDoc} 7.65/2.80 * 7.65/2.80 *

This implementation returns entrySet().size(). 7.65/2.80 */ 7.65/2.80 public int size() { 7.65/2.80 return entrySet().size(); 7.65/2.80 } 7.65/2.80 7.65/2.80 /** 7.65/2.80 * {@inheritDoc} 7.65/2.80 * 7.65/2.80 *

This implementation returns size() == 0. 7.65/2.80 */ 7.65/2.80 public boolean isEmpty() { 7.65/2.80 return size() == 0; 7.65/2.80 } 7.65/2.80 7.65/2.80 /** 7.65/2.80 * {@inheritDoc} 7.65/2.80 * 7.65/2.80 *

This implementation iterates over entrySet() searching 7.65/2.80 * for an entry with the specified value. If such an entry is found, 7.65/2.80 * true is returned. If the iteration terminates without 7.65/2.80 * finding such an entry, false is returned. Note that this 7.65/2.80 * implementation requires linear time in the size of the map. 7.65/2.80 * 7.65/2.80 * @throws ClassCastException {@inheritDoc} 7.65/2.80 * @throws NullPointerException {@inheritDoc} 7.65/2.80 */ 7.65/2.80 public boolean containsValue(Object value) { 7.65/2.80 Iterator> i = entrySet().iterator(); 7.65/2.80 if (value==null) { 7.65/2.80 while (i.hasNext()) { 7.65/2.80 Entry e = i.next(); 7.65/2.80 if (e.getValue()==null) 7.65/2.80 return true; 7.65/2.80 } 7.65/2.80 } else { 7.65/2.80 while (i.hasNext()) { 7.65/2.80 Entry e = i.next(); 7.65/2.80 if (value.equals(e.getValue())) 7.65/2.80 return true; 7.65/2.80 } 7.65/2.80 } 7.65/2.80 return false; 7.65/2.80 } 7.65/2.80 7.65/2.80 /** 7.65/2.80 * {@inheritDoc} 7.65/2.80 * 7.65/2.80 *

This implementation iterates over entrySet() searching 7.65/2.80 * for an entry with the specified key. If such an entry is found, 7.65/2.80 * true is returned. If the iteration terminates without 7.65/2.80 * finding such an entry, false is returned. Note that this 7.65/2.80 * implementation requires linear time in the size of the map; many 7.65/2.80 * implementations will override this method. 7.65/2.80 * 7.65/2.80 * @throws ClassCastException {@inheritDoc} 7.65/2.80 * @throws NullPointerException {@inheritDoc} 7.65/2.80 */ 7.65/2.80 public boolean containsKey(Object key) { 7.65/2.80 Iterator> i = entrySet().iterator(); 7.65/2.80 if (key==null) { 7.65/2.80 while (i.hasNext()) { 7.65/2.80 Entry e = i.next(); 7.65/2.80 if (e.getKey()==null) 7.65/2.80 return true; 7.65/2.80 } 7.65/2.80 } else { 7.65/2.80 while (i.hasNext()) { 7.65/2.81 Entry e = i.next(); 7.65/2.81 if (key.equals(e.getKey())) 7.65/2.81 return true; 7.65/2.81 } 7.65/2.81 } 7.65/2.81 return false; 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * {@inheritDoc} 7.65/2.81 * 7.65/2.81 *

This implementation iterates over entrySet() searching 7.65/2.81 * for an entry with the specified key. If such an entry is found, 7.65/2.81 * the entry's value is returned. If the iteration terminates without 7.65/2.81 * finding such an entry, null is returned. Note that this 7.65/2.81 * implementation requires linear time in the size of the map; many 7.65/2.81 * implementations will override this method. 7.65/2.81 * 7.65/2.81 * @throws ClassCastException {@inheritDoc} 7.65/2.81 * @throws NullPointerException {@inheritDoc} 7.65/2.81 */ 7.65/2.81 public V get(Object key) { 7.65/2.81 Iterator> i = entrySet().iterator(); 7.65/2.81 if (key==null) { 7.65/2.81 while (i.hasNext()) { 7.65/2.81 Entry e = i.next(); 7.65/2.81 if (e.getKey()==null) 7.65/2.81 return e.getValue(); 7.65/2.81 } 7.65/2.81 } else { 7.65/2.81 while (i.hasNext()) { 7.65/2.81 Entry e = i.next(); 7.65/2.81 if (key.equals(e.getKey())) 7.65/2.81 return e.getValue(); 7.65/2.81 } 7.65/2.81 } 7.65/2.81 return null; 7.65/2.81 } 7.65/2.81 7.65/2.81 7.65/2.81 // Modification Operations 7.65/2.81 7.65/2.81 /** 7.65/2.81 * {@inheritDoc} 7.65/2.81 * 7.65/2.81 *

This implementation always throws an 7.65/2.81 * UnsupportedOperationException. 7.65/2.81 * 7.65/2.81 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.81 * @throws ClassCastException {@inheritDoc} 7.65/2.81 * @throws NullPointerException {@inheritDoc} 7.65/2.81 * @throws IllegalArgumentException {@inheritDoc} 7.65/2.81 */ 7.65/2.81 public V put(K key, V value) { 7.65/2.81 throw new UnsupportedOperationException(); 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * {@inheritDoc} 7.65/2.81 * 7.65/2.81 *

This implementation iterates over entrySet() searching for an 7.65/2.81 * entry with the specified key. If such an entry is found, its value is 7.65/2.81 * obtained with its getValue operation, the entry is removed 7.65/2.81 * from the collection (and the backing map) with the iterator's 7.65/2.81 * remove operation, and the saved value is returned. If the 7.65/2.81 * iteration terminates without finding such an entry, null is 7.65/2.81 * returned. Note that this implementation requires linear time in the 7.65/2.81 * size of the map; many implementations will override this method. 7.65/2.81 * 7.65/2.81 *

Note that this implementation throws an 7.65/2.81 * UnsupportedOperationException if the entrySet 7.65/2.81 * iterator does not support the remove method and this map 7.65/2.81 * contains a mapping for the specified key. 7.65/2.81 * 7.65/2.81 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.81 * @throws ClassCastException {@inheritDoc} 7.65/2.81 * @throws NullPointerException {@inheritDoc} 7.65/2.81 */ 7.65/2.81 public V remove(Object key) { 7.65/2.81 Iterator> i = entrySet().iterator(); 7.65/2.81 Entry correctEntry = null; 7.65/2.81 if (key==null) { 7.65/2.81 while (correctEntry==null && i.hasNext()) { 7.65/2.81 Entry e = i.next(); 7.65/2.81 if (e.getKey()==null) 7.65/2.81 correctEntry = e; 7.65/2.81 } 7.65/2.81 } else { 7.65/2.81 while (correctEntry==null && i.hasNext()) { 7.65/2.81 Entry e = i.next(); 7.65/2.81 if (key.equals(e.getKey())) 7.65/2.81 correctEntry = e; 7.65/2.81 } 7.65/2.81 } 7.65/2.81 7.65/2.81 V oldValue = null; 7.65/2.81 if (correctEntry !=null) { 7.65/2.81 oldValue = correctEntry.getValue(); 7.65/2.81 i.remove(); 7.65/2.81 } 7.65/2.81 return oldValue; 7.65/2.81 } 7.65/2.81 7.65/2.81 7.65/2.81 // Bulk Operations 7.65/2.81 7.65/2.81 /** 7.65/2.81 * {@inheritDoc} 7.65/2.81 * 7.65/2.81 *

This implementation iterates over the specified map's 7.65/2.81 * entrySet() collection, and calls this map's put 7.65/2.81 * operation once for each entry returned by the iteration. 7.65/2.81 * 7.65/2.81 *

Note that this implementation throws an 7.65/2.81 * UnsupportedOperationException if this map does not support 7.65/2.81 * the put operation and the specified map is nonempty. 7.65/2.81 * 7.65/2.81 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.81 * @throws ClassCastException {@inheritDoc} 7.65/2.81 * @throws NullPointerException {@inheritDoc} 7.65/2.81 * @throws IllegalArgumentException {@inheritDoc} 7.65/2.81 */ 7.65/2.81 public void putAll(Map m) { 7.65/2.81 Iterator it = m.entrySet().iterator(); 7.65/2.81 while (it.hasNext()) { 7.65/2.81 Map.Entry e = (Map.Entry) it.next(); 7.65/2.81 put((K) e.getKey(), (V) e.getValue()); 7.65/2.81 } 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * {@inheritDoc} 7.65/2.81 * 7.65/2.81 *

This implementation calls entrySet().clear(). 7.65/2.81 * 7.65/2.81 *

Note that this implementation throws an 7.65/2.81 * UnsupportedOperationException if the entrySet 7.65/2.81 * does not support the clear operation. 7.65/2.81 * 7.65/2.81 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.81 */ 7.65/2.81 public void clear() { 7.65/2.81 entrySet().clear(); 7.65/2.81 } 7.65/2.81 7.65/2.81 7.65/2.81 // Views 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Each of these fields are initialized to contain an instance of the 7.65/2.81 * appropriate view the first time this view is requested. The views are 7.65/2.81 * stateless, so there's no reason to create more than one of each. 7.65/2.81 */ 7.65/2.81 transient volatile Set keySet = null; 7.65/2.81 transient volatile Collection values = null; 7.65/2.81 7.65/2.81 /** 7.65/2.81 * {@inheritDoc} 7.65/2.81 * 7.65/2.81 *

This implementation returns a set that subclasses {@link AbstractSet}. 7.65/2.81 * The subclass's iterator method returns a "wrapper object" over this 7.65/2.81 * map's entrySet() iterator. The size method 7.65/2.81 * delegates to this map's size method and the 7.65/2.81 * contains method delegates to this map's 7.65/2.81 * containsKey method. 7.65/2.81 * 7.65/2.81 *

The set is created the first time this method is called, 7.65/2.81 * and returned in response to all subsequent calls. No synchronization 7.65/2.81 * is performed, so there is a slight chance that multiple calls to this 7.65/2.81 * method will not all return the same set. 7.65/2.81 */ 7.65/2.81 public Set keySet() { 7.65/2.81 if (keySet == null) { 7.65/2.81 keySet = new AbstractSet() { 7.65/2.81 public Iterator iterator() { 7.65/2.81 return new Iterator() { 7.65/2.81 private Iterator> i = entrySet().iterator(); 7.65/2.81 7.65/2.81 public boolean hasNext() { 7.65/2.81 return i.hasNext(); 7.65/2.81 } 7.65/2.81 7.65/2.81 public K next() { 7.65/2.81 return i.next().getKey(); 7.65/2.81 } 7.65/2.81 7.65/2.81 public void remove() { 7.65/2.81 i.remove(); 7.65/2.81 } 7.65/2.81 }; 7.65/2.81 } 7.65/2.81 7.65/2.81 public int size() { 7.65/2.81 return AbstractMap.this.size(); 7.65/2.81 } 7.65/2.81 7.65/2.81 public boolean isEmpty() { 7.65/2.81 return AbstractMap.this.isEmpty(); 7.65/2.81 } 7.65/2.81 7.65/2.81 public void clear() { 7.65/2.81 AbstractMap.this.clear(); 7.65/2.81 } 7.65/2.81 7.65/2.81 public boolean contains(Object k) { 7.65/2.81 return AbstractMap.this.containsKey(k); 7.65/2.81 } 7.65/2.81 7.65/2.81 public Object[] toArray() { 7.65/2.81 Object[] res = new Object[AbstractMap.this.size()]; 7.65/2.81 Iterator> it = entrySet().iterator(); 7.65/2.81 int i = 0; 7.65/2.81 while (it.hasNext()) 7.65/2.81 res[i++] = it.next().getKey(); 7.65/2.81 return res; 7.65/2.81 } 7.65/2.81 7.65/2.81 public T[] toArray(T[] a) { 7.65/2.81 a = (T[])java.lang.reflect.Array.newInstance( 7.65/2.81 a.getClass().getComponentType(), AbstractMap.this.size()); 7.65/2.81 Object[] res = a; 7.65/2.81 Iterator> it = entrySet().iterator(); 7.65/2.81 int i = 0; 7.65/2.81 while (it.hasNext()) 7.65/2.81 res[i++] = it.next().getKey(); 7.65/2.81 return a; 7.65/2.81 } 7.65/2.81 }; 7.65/2.81 } 7.65/2.81 return keySet; 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * {@inheritDoc} 7.65/2.81 * 7.65/2.81 *

This implementation returns a collection that subclasses {@link 7.65/2.81 * AbstractCollection}. The subclass's iterator method returns a 7.65/2.81 * "wrapper object" over this map's entrySet() iterator. 7.65/2.81 * The size method delegates to this map's size 7.65/2.81 * method and the contains method delegates to this map's 7.65/2.81 * containsValue method. 7.65/2.81 * 7.65/2.81 *

The collection is created the first time this method is called, and 7.65/2.81 * returned in response to all subsequent calls. No synchronization is 7.65/2.81 * performed, so there is a slight chance that multiple calls to this 7.65/2.81 * method will not all return the same collection. 7.65/2.81 */ 7.65/2.81 public Collection values() { 7.65/2.81 if (values == null) { 7.65/2.81 values = new AbstractCollection() { 7.65/2.81 public Iterator iterator() { 7.65/2.81 return new Iterator() { 7.65/2.81 private Iterator> i = entrySet().iterator(); 7.65/2.81 7.65/2.81 public boolean hasNext() { 7.65/2.81 return i.hasNext(); 7.65/2.81 } 7.65/2.81 7.65/2.81 public V next() { 7.65/2.81 return i.next().getValue(); 7.65/2.81 } 7.65/2.81 7.65/2.81 public void remove() { 7.65/2.81 i.remove(); 7.65/2.81 } 7.65/2.81 }; 7.65/2.81 } 7.65/2.81 7.65/2.81 public int size() { 7.65/2.81 return AbstractMap.this.size(); 7.65/2.81 } 7.65/2.81 7.65/2.81 public boolean isEmpty() { 7.65/2.81 return AbstractMap.this.isEmpty(); 7.65/2.81 } 7.65/2.81 7.65/2.81 public void clear() { 7.65/2.81 AbstractMap.this.clear(); 7.65/2.81 } 7.65/2.81 7.65/2.81 public boolean contains(Object v) { 7.65/2.81 return AbstractMap.this.containsValue(v); 7.65/2.81 } 7.65/2.81 }; 7.65/2.81 } 7.65/2.81 return values; 7.65/2.81 } 7.65/2.81 7.65/2.81 public abstract Set> entrySet(); 7.65/2.81 7.65/2.81 7.65/2.81 // Comparison and hashing 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Compares the specified object with this map for equality. Returns 7.65/2.81 * true if the given object is also a map and the two maps 7.65/2.81 * represent the same mappings. More formally, two maps m1 and 7.65/2.81 * m2 represent the same mappings if 7.65/2.81 * m1.entrySet().equals(m2.entrySet()). This ensures that the 7.65/2.81 * equals method works properly across different implementations 7.65/2.81 * of the Map interface. 7.65/2.81 * 7.65/2.81 *

This implementation first checks if the specified object is this map; 7.65/2.81 * if so it returns true. Then, it checks if the specified 7.65/2.81 * object is a map whose size is identical to the size of this map; if 7.65/2.81 * not, it returns false. If so, it iterates over this map's 7.65/2.81 * entrySet collection, and checks that the specified map 7.65/2.81 * contains each mapping that this map contains. If the specified map 7.65/2.81 * fails to contain such a mapping, false is returned. If the 7.65/2.81 * iteration completes, true is returned. 7.65/2.81 * 7.65/2.81 * @param o object to be compared for equality with this map 7.65/2.81 * @return true if the specified object is equal to this map 7.65/2.81 */ 7.65/2.81 public boolean equals(Object o) { 7.65/2.81 if (o == this) 7.65/2.81 return true; 7.65/2.81 7.65/2.81 if (!(o instanceof Map)) 7.65/2.81 return false; 7.65/2.81 Map m = (Map) o; 7.65/2.81 if (m.size() != size()) 7.65/2.81 return false; 7.65/2.81 7.65/2.81 try { 7.65/2.81 Iterator> i = entrySet().iterator(); 7.65/2.81 while (i.hasNext()) { 7.65/2.81 Entry e = i.next(); 7.65/2.81 K key = e.getKey(); 7.65/2.81 V value = e.getValue(); 7.65/2.81 if (value == null) { 7.65/2.81 if (!(m.get(key)==null && m.containsKey(key))) 7.65/2.81 return false; 7.65/2.81 } else { 7.65/2.81 if (!value.equals(m.get(key))) 7.65/2.81 return false; 7.65/2.81 } 7.65/2.81 } 7.65/2.81 } catch (ClassCastException unused) { 7.65/2.81 return false; 7.65/2.81 } catch (NullPointerException unused) { 7.65/2.81 return false; 7.65/2.81 } 7.65/2.81 7.65/2.81 return true; 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Returns the hash code value for this map. The hash code of a map is 7.65/2.81 * defined to be the sum of the hash codes of each entry in the map's 7.65/2.81 * entrySet() view. This ensures that m1.equals(m2) 7.65/2.81 * implies that m1.hashCode()==m2.hashCode() for any two maps 7.65/2.81 * m1 and m2, as required by the general contract of 7.65/2.81 * {@link Object#hashCode}. 7.65/2.81 * 7.65/2.81 *

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

7.65/2.81	         *   (e1.getKey()==null ?
7.65/2.81	         *    e2.getKey()==null :
7.65/2.81	         *    e1.getKey().equals(e2.getKey()))
7.65/2.81	         *   &&
7.65/2.81	         *   (e1.getValue()==null ?
7.65/2.81	         *    e2.getValue()==null :
7.65/2.81	         *    e1.getValue().equals(e2.getValue()))
7.65/2.81 * This ensures that the {@code equals} method works properly across 7.65/2.81 * different implementations of the {@code Map.Entry} interface. 7.65/2.81 * 7.65/2.81 * @param o object to be compared for equality with this map entry 7.65/2.81 * @return {@code true} if the specified object is equal to this map 7.65/2.81 * entry 7.65/2.81 * @see #hashCode 7.65/2.81 */ 7.65/2.81 public boolean equals(Object o) { 7.65/2.81 if (!(o instanceof Map.Entry)) 7.65/2.81 return false; 7.65/2.81 Map.Entry e = (Map.Entry)o; 7.65/2.81 return eq(key, e.getKey()) && eq(value, e.getValue()); 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Returns the hash code value for this map entry. The hash code 7.65/2.81 * of a map entry {@code e} is defined to be:
7.65/2.81	         *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
7.65/2.81	         *   (e.getValue()==null ? 0 : e.getValue().hashCode())
7.65/2.81 * This ensures that {@code e1.equals(e2)} implies that 7.65/2.81 * {@code e1.hashCode()==e2.hashCode()} for any two Entries 7.65/2.81 * {@code e1} and {@code e2}, as required by the general 7.65/2.81 * contract of {@link Object#hashCode}. 7.65/2.81 * 7.65/2.81 * @return the hash code value for this map entry 7.65/2.81 * @see #equals 7.65/2.81 */ 7.65/2.81 public int hashCode() { 7.65/2.81 return (key == null ? 0 : key.hashCode()) ^ 7.65/2.81 (value == null ? 0 : value.hashCode()); 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Returns a String representation of this map entry. This 7.65/2.81 * implementation returns the string representation of this 7.65/2.81 * entry's key followed by the equals character ("=") 7.65/2.81 * followed by the string representation of this entry's value. 7.65/2.81 * 7.65/2.81 * @return a String representation of this map entry 7.65/2.81 */ 7.65/2.81 public String toString() { 7.65/2.81 return key + "=" + value; 7.65/2.81 } 7.65/2.81 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * An Entry maintaining an immutable key and value. This class 7.65/2.81 * does not support method setValue. This class may be 7.65/2.81 * convenient in methods that return thread-safe snapshots of 7.65/2.81 * key-value mappings. 7.65/2.81 * 7.65/2.81 * @since 1.6 7.65/2.81 */ 7.65/2.81 public static class SimpleImmutableEntry 7.65/2.81 implements Entry, java.io.Serializable 7.65/2.81 { 7.65/2.81 private static final long serialVersionUID = 7138329143949025153L; 7.65/2.81 7.65/2.81 private final K key; 7.65/2.81 private final V value; 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Creates an entry representing a mapping from the specified 7.65/2.81 * key to the specified value. 7.65/2.81 * 7.65/2.81 * @param key the key represented by this entry 7.65/2.81 * @param value the value represented by this entry 7.65/2.81 */ 7.65/2.81 public SimpleImmutableEntry(K key, V value) { 7.65/2.81 this.key = key; 7.65/2.81 this.value = value; 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Creates an entry representing the same mapping as the 7.65/2.81 * specified entry. 7.65/2.81 * 7.65/2.81 * @param entry the entry to copy 7.65/2.81 */ 7.65/2.81 public SimpleImmutableEntry(Entry entry) { 7.65/2.81 this.key = entry.getKey(); 7.65/2.81 this.value = entry.getValue(); 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Returns the key corresponding to this entry. 7.65/2.81 * 7.65/2.81 * @return the key corresponding to this entry 7.65/2.81 */ 7.65/2.81 public K getKey() { 7.65/2.81 return key; 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Returns the value corresponding to this entry. 7.65/2.81 * 7.65/2.81 * @return the value corresponding to this entry 7.65/2.81 */ 7.65/2.81 public V getValue() { 7.65/2.81 return value; 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Replaces the value corresponding to this entry with the specified 7.65/2.81 * value (optional operation). This implementation simply throws 7.65/2.81 * UnsupportedOperationException, as this class implements 7.65/2.81 * an immutable map entry. 7.65/2.81 * 7.65/2.81 * @param value new value to be stored in this entry 7.65/2.81 * @return (Does not return) 7.65/2.81 * @throws UnsupportedOperationException always 7.65/2.81 */ 7.65/2.81 public V setValue(V value) { 7.65/2.81 throw new UnsupportedOperationException(); 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Compares the specified object with this entry for equality. 7.65/2.81 * Returns {@code true} if the given object is also a map entry and 7.65/2.81 * the two entries represent the same mapping. More formally, two 7.65/2.81 * entries {@code e1} and {@code e2} represent the same mapping 7.65/2.81 * if
7.65/2.81	         *   (e1.getKey()==null ?
7.65/2.81	         *    e2.getKey()==null :
7.65/2.81	         *    e1.getKey().equals(e2.getKey()))
7.65/2.81	         *   &&
7.65/2.81	         *   (e1.getValue()==null ?
7.65/2.81	         *    e2.getValue()==null :
7.65/2.81	         *    e1.getValue().equals(e2.getValue()))
7.65/2.81 * This ensures that the {@code equals} method works properly across 7.65/2.81 * different implementations of the {@code Map.Entry} interface. 7.65/2.81 * 7.65/2.81 * @param o object to be compared for equality with this map entry 7.65/2.81 * @return {@code true} if the specified object is equal to this map 7.65/2.81 * entry 7.65/2.81 * @see #hashCode 7.65/2.81 */ 7.65/2.81 public boolean equals(Object o) { 7.65/2.81 if (!(o instanceof Map.Entry)) 7.65/2.81 return false; 7.65/2.81 Map.Entry e = (Map.Entry)o; 7.65/2.81 return eq(key, e.getKey()) && eq(value, e.getValue()); 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Returns the hash code value for this map entry. The hash code 7.65/2.81 * of a map entry {@code e} is defined to be:
7.65/2.81	         *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
7.65/2.81	         *   (e.getValue()==null ? 0 : e.getValue().hashCode())
7.65/2.81 * This ensures that {@code e1.equals(e2)} implies that 7.65/2.81 * {@code e1.hashCode()==e2.hashCode()} for any two Entries 7.65/2.81 * {@code e1} and {@code e2}, as required by the general 7.65/2.81 * contract of {@link Object#hashCode}. 7.65/2.81 * 7.65/2.81 * @return the hash code value for this map entry 7.65/2.81 * @see #equals 7.65/2.81 */ 7.65/2.81 public int hashCode() { 7.65/2.81 return (key == null ? 0 : key.hashCode()) ^ 7.65/2.81 (value == null ? 0 : value.hashCode()); 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Returns a String representation of this map entry. This 7.65/2.81 * implementation returns the string representation of this 7.65/2.81 * entry's key followed by the equals character ("=") 7.65/2.81 * followed by the string representation of this entry's value. 7.65/2.81 * 7.65/2.81 * @return a String representation of this map entry 7.65/2.81 */ 7.65/2.81 public String toString() { 7.65/2.81 return key + "=" + value; 7.65/2.81 } 7.65/2.81 7.65/2.81 } 7.65/2.81 7.65/2.81 } 7.65/2.81 7.65/2.81 7.65/2.81 /* 7.65/2.81 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 7.65/2.81 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.65/2.81 * 7.65/2.81 * This code is free software; you can redistribute it and/or modify it 7.65/2.81 * under the terms of the GNU General Public License version 2 only, as 7.65/2.81 * published by the Free Software Foundation. Sun designates this 7.65/2.81 * particular file as subject to the "Classpath" exception as provided 7.65/2.81 * by Sun in the LICENSE file that accompanied this code. 7.65/2.81 * 7.65/2.81 * This code is distributed in the hope that it will be useful, but WITHOUT 7.65/2.81 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.65/2.81 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.65/2.81 * version 2 for more details (a copy is included in the LICENSE file that 7.65/2.81 * accompanied this code). 7.65/2.81 * 7.65/2.81 * You should have received a copy of the GNU General Public License version 7.65/2.81 * 2 along with this work; if not, write to the Free Software Foundation, 7.65/2.81 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.65/2.81 * 7.65/2.81 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 7.65/2.81 * CA 95054 USA or visit www.sun.com if you need additional information or 7.65/2.81 * have any questions. 7.65/2.81 */ 7.65/2.81 7.65/2.81 package javaUtilEx; 7.65/2.81 7.65/2.81 /** 7.65/2.81 * This class provides a skeletal implementation of the Set 7.65/2.81 * interface to minimize the effort required to implement this 7.65/2.81 * interface.

7.65/2.81 * 7.65/2.81 * The process of implementing a set by extending this class is identical 7.65/2.81 * to that of implementing a Collection by extending AbstractCollection, 7.65/2.81 * except that all of the methods and constructors in subclasses of this 7.65/2.81 * class must obey the additional constraints imposed by the Set 7.65/2.81 * interface (for instance, the add method must not permit addition of 7.65/2.81 * multiple instances of an object to a set).

7.65/2.81 * 7.65/2.81 * Note that this class does not override any of the implementations from 7.65/2.81 * the AbstractCollection class. It merely adds implementations 7.65/2.81 * for equals and hashCode.

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

7.65/2.81 * 7.65/2.81 * This implementation first checks if the specified object is this 7.65/2.81 * set; if so it returns true. Then, it checks if the 7.65/2.81 * specified object is a set whose size is identical to the size of 7.65/2.81 * this set; if not, it returns false. If so, it returns 7.65/2.81 * containsAll((Collection) o). 7.65/2.81 * 7.65/2.81 * @param o object to be compared for equality with this set 7.65/2.81 * @return true if the specified object is equal to this set 7.65/2.81 */ 7.65/2.81 public boolean equals(Object o) { 7.65/2.81 if (o == this) 7.65/2.81 return true; 7.65/2.81 7.65/2.81 if (!(o instanceof Set)) 7.65/2.81 return false; 7.65/2.81 Collection c = (Collection) o; 7.65/2.81 if (c.size() != size()) 7.65/2.81 return false; 7.65/2.81 try { 7.65/2.81 return containsAll(c); 7.65/2.81 } catch (ClassCastException unused) { 7.65/2.81 return false; 7.65/2.81 } catch (NullPointerException unused) { 7.65/2.81 return false; 7.65/2.81 } 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Returns the hash code value for this set. The hash code of a set is 7.65/2.81 * defined to be the sum of the hash codes of the elements in the set, 7.65/2.81 * where the hash code of a null element is defined to be zero. 7.65/2.81 * This ensures that s1.equals(s2) implies that 7.65/2.81 * s1.hashCode()==s2.hashCode() for any two sets s1 7.65/2.81 * and s2, as required by the general contract of 7.65/2.81 * {@link Object#hashCode}. 7.65/2.81 * 7.65/2.81 *

This implementation iterates over the set, calling the 7.65/2.81 * hashCode method on each element in the set, and adding up 7.65/2.81 * the results. 7.65/2.81 * 7.65/2.81 * @return the hash code value for this set 7.65/2.81 * @see Object#equals(Object) 7.65/2.81 * @see Set#equals(Object) 7.65/2.81 */ 7.65/2.81 public int hashCode() { 7.65/2.81 int h = 0; 7.65/2.81 Iterator i = iterator(); 7.65/2.81 while (i.hasNext()) { 7.65/2.81 E obj = i.next(); 7.65/2.81 if (obj != null) 7.65/2.81 h += obj.hashCode(); 7.65/2.81 } 7.65/2.81 return h; 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Removes from this set all of its elements that are contained in the 7.65/2.81 * specified collection (optional operation). If the specified 7.65/2.81 * collection is also a set, this operation effectively modifies this 7.65/2.81 * set so that its value is the asymmetric set difference of 7.65/2.81 * the two sets. 7.65/2.81 * 7.65/2.81 *

This implementation determines which is the smaller of this set 7.65/2.81 * and the specified collection, by invoking the size 7.65/2.81 * method on each. If this set has fewer elements, then the 7.65/2.81 * implementation iterates over this set, checking each element 7.65/2.81 * returned by the iterator in turn to see if it is contained in 7.65/2.81 * the specified collection. If it is so contained, it is removed 7.65/2.81 * from this set with the iterator's remove method. If 7.65/2.81 * the specified collection has fewer elements, then the 7.65/2.81 * implementation iterates over the specified collection, removing 7.65/2.81 * from this set each element returned by the iterator, using this 7.65/2.81 * set's remove method. 7.65/2.81 * 7.65/2.81 *

Note that this implementation will throw an 7.65/2.81 * UnsupportedOperationException if the iterator returned by the 7.65/2.81 * iterator method does not implement the remove method. 7.65/2.81 * 7.65/2.81 * @param c collection containing elements to be removed from this set 7.65/2.81 * @return true if this set changed as a result of the call 7.65/2.81 * @throws UnsupportedOperationException if the removeAll operation 7.65/2.81 * is not supported by this set 7.65/2.81 * @throws ClassCastException if the class of an element of this set 7.65/2.81 * is incompatible with the specified collection (optional) 7.65/2.81 * @throws NullPointerException if this set contains a null element and the 7.65/2.81 * specified collection does not permit null elements (optional), 7.65/2.81 * or if the specified collection is null 7.65/2.81 * @see #remove(Object) 7.65/2.81 * @see #contains(Object) 7.65/2.81 */ 7.65/2.81 public boolean removeAll(Collection c) { 7.65/2.81 boolean modified = false; 7.65/2.81 7.65/2.81 if (size() > c.size()) { 7.65/2.81 for (Iterator i = c.iterator(); i.hasNext(); ) 7.65/2.81 modified |= remove(i.next()); 7.65/2.81 } else { 7.65/2.81 for (Iterator i = iterator(); i.hasNext(); ) { 7.65/2.81 if (c.contains(i.next())) { 7.65/2.81 i.remove(); 7.65/2.81 modified = true; 7.65/2.81 } 7.65/2.81 } 7.65/2.81 } 7.65/2.81 return modified; 7.65/2.81 } 7.65/2.81 7.65/2.81 } 7.65/2.81 7.65/2.81 7.65/2.81 /* 7.65/2.81 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 7.65/2.81 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.65/2.81 * 7.65/2.81 * This code is free software; you can redistribute it and/or modify it 7.65/2.81 * under the terms of the GNU General Public License version 2 only, as 7.65/2.81 * published by the Free Software Foundation. Sun designates this 7.65/2.81 * particular file as subject to the "Classpath" exception as provided 7.65/2.81 * by Sun in the LICENSE file that accompanied this code. 7.65/2.81 * 7.65/2.81 * This code is distributed in the hope that it will be useful, but WITHOUT 7.65/2.81 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.65/2.81 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.65/2.81 * version 2 for more details (a copy is included in the LICENSE file that 7.65/2.81 * accompanied this code). 7.65/2.81 * 7.65/2.81 * You should have received a copy of the GNU General Public License version 7.65/2.81 * 2 along with this work; if not, write to the Free Software Foundation, 7.65/2.81 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.65/2.81 * 7.65/2.81 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 7.65/2.81 * CA 95054 USA or visit www.sun.com if you need additional information or 7.65/2.81 * have any questions. 7.65/2.81 */ 7.65/2.81 7.65/2.81 package javaUtilEx; 7.65/2.81 7.65/2.81 /** 7.65/2.81 * The root interface in the collection hierarchy. A collection 7.65/2.81 * represents a group of objects, known as its elements. Some 7.65/2.81 * collections allow duplicate elements and others do not. Some are ordered 7.65/2.81 * and others unordered. The JDK does not provide any direct 7.65/2.81 * implementations of this interface: it provides implementations of more 7.65/2.81 * specific subinterfaces like Set and List. This interface 7.65/2.81 * is typically used to pass collections around and manipulate them where 7.65/2.81 * maximum generality is desired. 7.65/2.81 * 7.65/2.81 *

Bags or multisets (unordered collections that may contain 7.65/2.81 * duplicate elements) should implement this interface directly. 7.65/2.81 * 7.65/2.81 *

All general-purpose Collection implementation classes (which 7.65/2.81 * typically implement Collection indirectly through one of its 7.65/2.81 * subinterfaces) should provide two "standard" constructors: a void (no 7.65/2.81 * arguments) constructor, which creates an empty collection, and a 7.65/2.81 * constructor with a single argument of type Collection, which 7.65/2.81 * creates a new collection with the same elements as its argument. In 7.65/2.81 * effect, the latter constructor allows the user to copy any collection, 7.65/2.81 * producing an equivalent collection of the desired implementation type. 7.65/2.81 * There is no way to enforce this convention (as interfaces cannot contain 7.65/2.81 * constructors) but all of the general-purpose Collection 7.65/2.81 * implementations in the Java platform libraries comply. 7.65/2.81 * 7.65/2.81 *

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

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

It is up to each collection to determine its own synchronization 7.65/2.81 * policy. In the absence of a stronger guarantee by the 7.65/2.81 * implementation, undefined behavior may result from the invocation 7.65/2.81 * of any method on a collection that is being mutated by another 7.65/2.81 * thread; this includes direct invocations, passing the collection to 7.65/2.81 * a method that might perform invocations, and using an existing 7.65/2.81 * iterator to examine the collection. 7.65/2.81 * 7.65/2.81 *

Many methods in Collections Framework interfaces are defined in 7.65/2.81 * terms of the {@link Object#equals(Object) equals} method. For example, 7.65/2.81 * the specification for the {@link #contains(Object) contains(Object o)} 7.65/2.81 * method says: "returns true if and only if this collection 7.65/2.81 * contains at least one element e such that 7.65/2.81 * (o==null ? e==null : o.equals(e))." This specification should 7.65/2.81 * not be construed to imply that invoking Collection.contains 7.65/2.81 * with a non-null argument o will cause o.equals(e) to be 7.65/2.81 * invoked for any element e. Implementations are free to implement 7.65/2.81 * optimizations whereby the equals invocation is avoided, for 7.65/2.81 * example, by first comparing the hash codes of the two elements. (The 7.65/2.81 * {@link Object#hashCode()} specification guarantees that two objects with 7.65/2.81 * unequal hash codes cannot be equal.) More generally, implementations of 7.65/2.81 * the various Collections Framework interfaces are free to take advantage of 7.65/2.81 * the specified behavior of underlying {@link Object} methods wherever the 7.65/2.81 * implementor deems it appropriate. 7.65/2.81 * 7.65/2.81 *

This interface is a member of the 7.65/2.81 * 7.65/2.81 * Java Collections Framework. 7.65/2.81 * 7.65/2.81 * @author Josh Bloch 7.65/2.81 * @author Neal Gafter 7.65/2.81 * @see Set 7.65/2.81 * @see List 7.65/2.81 * @see Map 7.65/2.81 * @see SortedSet 7.65/2.81 * @see SortedMap 7.65/2.81 * @see HashSet 7.65/2.81 * @see TreeSet 7.65/2.81 * @see ArrayList 7.65/2.81 * @see LinkedList 7.65/2.81 * @see Vector 7.65/2.81 * @see Collections 7.65/2.81 * @see Arrays 7.65/2.81 * @see AbstractCollection 7.65/2.81 * @since 1.2 7.65/2.81 */ 7.65/2.81 7.65/2.81 public interface Collection { 7.65/2.81 // Query Operations 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Returns the number of elements in this collection. If this collection 7.65/2.81 * contains more than Integer.MAX_VALUE elements, returns 7.65/2.81 * Integer.MAX_VALUE. 7.65/2.81 * 7.65/2.81 * @return the number of elements in this collection 7.65/2.81 */ 7.65/2.81 int size(); 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Returns true if this collection contains no elements. 7.65/2.81 * 7.65/2.81 * @return true if this collection contains no elements 7.65/2.81 */ 7.65/2.81 boolean isEmpty(); 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Returns true if this collection contains the specified element. 7.65/2.81 * More formally, returns true if and only if this collection 7.65/2.81 * contains at least one element e such that 7.65/2.81 * (o==null ? e==null : o.equals(e)). 7.65/2.81 * 7.65/2.81 * @param o element whose presence in this collection is to be tested 7.65/2.81 * @return true if this collection contains the specified 7.65/2.81 * element 7.65/2.81 * @throws ClassCastException if the type of the specified element 7.65/2.81 * is incompatible with this collection (optional) 7.65/2.81 * @throws NullPointerException if the specified element is null and this 7.65/2.81 * collection does not permit null elements (optional) 7.65/2.81 */ 7.65/2.81 boolean contains(Object o); 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Returns an iterator over the elements in this collection. There are no 7.65/2.81 * guarantees concerning the order in which the elements are returned 7.65/2.81 * (unless this collection is an instance of some class that provides a 7.65/2.81 * guarantee). 7.65/2.81 * 7.65/2.81 * @return an Iterator over the elements in this collection 7.65/2.81 */ 7.65/2.81 Iterator iterator(); 7.65/2.81 7.65/2.81 // Modification Operations 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Ensures that this collection contains the specified element (optional 7.65/2.81 * operation). Returns true if this collection changed as a 7.65/2.81 * result of the call. (Returns false if this collection does 7.65/2.81 * not permit duplicates and already contains the specified element.)

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

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

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

7.65/2.81 * 7.65/2.81 * The general contract for the Object.equals method states that 7.65/2.81 * equals must be symmetric (in other words, a.equals(b) if and 7.65/2.81 * only if b.equals(a)). The contracts for List.equals 7.65/2.81 * and Set.equals state that lists are only equal to other lists, 7.65/2.81 * and sets to other sets. Thus, a custom equals method for a 7.65/2.81 * collection class that implements neither the List nor 7.65/2.81 * Set interface must return false when this collection 7.65/2.81 * is compared to any list or set. (By the same logic, it is not possible 7.65/2.81 * to write a class that correctly implements both the Set and 7.65/2.81 * List interfaces.) 7.65/2.81 * 7.65/2.81 * @param o object to be compared for equality with this collection 7.65/2.81 * @return true if the specified object is equal to this 7.65/2.81 * collection 7.65/2.81 * 7.65/2.81 * @see Object#equals(Object) 7.65/2.81 * @see Set#equals(Object) 7.65/2.81 * @see List#equals(Object) 7.65/2.81 */ 7.65/2.81 boolean equals(Object o); 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Returns the hash code value for this collection. While the 7.65/2.81 * Collection interface adds no stipulations to the general 7.65/2.81 * contract for the Object.hashCode method, programmers should 7.65/2.81 * take note that any class that overrides the Object.equals 7.65/2.81 * method must also override the Object.hashCode method in order 7.65/2.81 * to satisfy the general contract for the Object.hashCodemethod. 7.65/2.81 * In particular, c1.equals(c2) implies that 7.65/2.81 * c1.hashCode()==c2.hashCode(). 7.65/2.81 * 7.65/2.81 * @return the hash code value for this collection 7.65/2.81 * 7.65/2.81 * @see Object#hashCode() 7.65/2.81 * @see Object#equals(Object) 7.65/2.81 */ 7.65/2.81 int hashCode(); 7.65/2.81 } 7.65/2.81 7.65/2.81 7.65/2.81 /* 7.65/2.81 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 7.65/2.81 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.65/2.81 * 7.65/2.81 * This code is free software; you can redistribute it and/or modify it 7.65/2.81 * under the terms of the GNU General Public License version 2 only, as 7.65/2.81 * published by the Free Software Foundation. Sun designates this 7.65/2.81 * particular file as subject to the "Classpath" exception as provided 7.65/2.81 * by Sun in the LICENSE file that accompanied this code. 7.65/2.81 * 7.65/2.81 * This code is distributed in the hope that it will be useful, but WITHOUT 7.65/2.81 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.65/2.81 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.65/2.81 * version 2 for more details (a copy is included in the LICENSE file that 7.65/2.81 * accompanied this code). 7.65/2.81 * 7.65/2.81 * You should have received a copy of the GNU General Public License version 7.65/2.81 * 2 along with this work; if not, write to the Free Software Foundation, 7.65/2.81 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.65/2.81 * 7.65/2.81 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 7.65/2.81 * CA 95054 USA or visit www.sun.com if you need additional information or 7.65/2.81 * have any questions. 7.65/2.81 */ 7.65/2.81 7.65/2.81 package javaUtilEx; 7.65/2.81 7.65/2.81 /** 7.65/2.81 * This exception may be thrown by methods that have detected concurrent 7.65/2.81 * modification of an object when such modification is not permissible. 7.65/2.81 *

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

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

Note that fail-fast behavior cannot be guaranteed as it is, generally 7.65/2.81 * speaking, impossible to make any hard guarantees in the presence of 7.65/2.81 * unsynchronized concurrent modification. Fail-fast operations 7.65/2.81 * throw ConcurrentModificationException on a best-effort basis. 7.65/2.81 * Therefore, it would be wrong to write a program that depended on this 7.65/2.81 * exception for its correctness: ConcurrentModificationException 7.65/2.81 * should be used only to detect bugs. 7.65/2.81 * 7.65/2.81 * @author Josh Bloch 7.65/2.81 * @see Collection 7.65/2.81 * @see Iterator 7.65/2.81 * @see ListIterator 7.65/2.81 * @see Vector 7.65/2.81 * @see LinkedList 7.65/2.81 * @see HashSet 7.65/2.81 * @see Hashtable 7.65/2.81 * @see TreeMap 7.65/2.81 * @see AbstractList 7.65/2.81 * @since 1.2 7.65/2.81 */ 7.65/2.81 public class ConcurrentModificationException extends RuntimeException { 7.65/2.81 /** 7.65/2.81 * Constructs a ConcurrentModificationException with no 7.65/2.81 * detail message. 7.65/2.81 */ 7.65/2.81 public ConcurrentModificationException() { 7.65/2.81 } 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Constructs a ConcurrentModificationException with the 7.65/2.81 * specified detail message. 7.65/2.81 * 7.65/2.81 * @param message the detail message pertaining to this exception. 7.65/2.81 */ 7.65/2.81 public ConcurrentModificationException(String message) { 7.65/2.81 super(message); 7.65/2.81 } 7.65/2.81 } 7.65/2.81 7.65/2.81 7.65/2.81 /* 7.65/2.81 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. 7.65/2.81 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.65/2.81 * 7.65/2.81 * This code is free software; you can redistribute it and/or modify it 7.65/2.81 * under the terms of the GNU General Public License version 2 only, as 7.65/2.81 * published by the Free Software Foundation. Sun designates this 7.65/2.81 * particular file as subject to the "Classpath" exception as provided 7.65/2.81 * by Sun in the LICENSE file that accompanied this code. 7.65/2.81 * 7.65/2.81 * This code is distributed in the hope that it will be useful, but WITHOUT 7.65/2.81 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.65/2.81 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.65/2.81 * version 2 for more details (a copy is included in the LICENSE file that 7.65/2.81 * accompanied this code). 7.65/2.81 * 7.65/2.81 * You should have received a copy of the GNU General Public License version 7.65/2.81 * 2 along with this work; if not, write to the Free Software Foundation, 7.65/2.81 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.65/2.81 * 7.65/2.81 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 7.65/2.81 * CA 95054 USA or visit www.sun.com if you need additional information or 7.65/2.81 * have any questions. 7.65/2.81 */ 7.65/2.81 7.65/2.81 package javaUtilEx; 7.65/2.81 7.65/2.81 /** 7.65/2.81 * Hash table based implementation of the Map interface. This 7.65/2.81 * implementation provides all of the optional map operations, and permits 7.65/2.81 * null values and the null key. (The HashMap 7.65/2.81 * class is roughly equivalent to Hashtable, except that it is 7.65/2.81 * unsynchronized and permits nulls.) This class makes no guarantees as to 7.65/2.81 * the order of the map; in particular, it does not guarantee that the order 7.65/2.81 * will remain constant over time. 7.65/2.81 * 7.65/2.81 *

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

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

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

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

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

7.65/2.81	 *   Map m = Collections.synchronizedMap(new HashMap(...));
7.65/2.81 * 7.65/2.81 *

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

Note that the fail-fast behavior of an iterator cannot be guaranteed 7.65/2.81 * as it is, generally speaking, impossible to make any hard guarantees in the 7.65/2.81 * presence of unsynchronized concurrent modification. Fail-fast iterators 7.65/2.81 * throw ConcurrentModificationException on a best-effort basis. 7.65/2.81 * Therefore, it would be wrong to write a program that depended on this 7.65/2.81 * exception for its correctness: the fail-fast behavior of iterators 7.65/2.81 * should be used only to detect bugs. 7.65/2.81 * 7.65/2.81 *

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

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

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

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

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

7.65/2.82 * 7.65/2.82 *

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

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

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

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

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

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

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

This interface is a member of the 7.65/2.82 * 7.65/2.82 * Java Collections Framework. 7.65/2.82 * 7.65/2.82 *

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

7.65/2.82 * 7.65/2.82 * To implement an unmodifiable collection, the programmer needs only to 7.65/2.82 * extend this class and provide implementations for the iterator and 7.65/2.82 * size methods. (The iterator returned by the iterator 7.65/2.82 * method must implement hasNext and next.)

7.65/2.82 * 7.65/2.82 * To implement a modifiable collection, the programmer must additionally 7.65/2.82 * override this class's add method (which otherwise throws an 7.65/2.82 * UnsupportedOperationException), and the iterator returned by the 7.65/2.82 * iterator method must additionally implement its remove 7.65/2.82 * method.

7.65/2.82 * 7.65/2.82 * The programmer should generally provide a void (no argument) and 7.65/2.82 * Collection constructor, as per the recommendation in the 7.65/2.82 * Collection interface specification.

7.65/2.82 * 7.65/2.82 * The documentation for each non-abstract method in this class describes its 7.65/2.82 * implementation in detail. Each of these methods may be overridden if 7.65/2.82 * the collection being implemented admits a more efficient implementation.

7.65/2.82 * 7.65/2.82 * This class is a member of the 7.65/2.82 * 7.65/2.82 * Java Collections Framework. 7.65/2.82 * 7.65/2.82 * @author Josh Bloch 7.65/2.82 * @author Neal Gafter 7.65/2.82 * @see Collection 7.65/2.82 * @since 1.2 7.65/2.82 */ 7.65/2.82 7.65/2.82 public abstract class AbstractCollection implements Collection { 7.65/2.82 /** 7.65/2.82 * Sole constructor. (For invocation by subclass constructors, typically 7.65/2.82 * implicit.) 7.65/2.82 */ 7.65/2.82 protected AbstractCollection() { 7.65/2.82 } 7.65/2.82 7.65/2.82 // Query Operations 7.65/2.82 7.65/2.82 /** 7.65/2.82 * Returns an iterator over the elements contained in this collection. 7.65/2.82 * 7.65/2.82 * @return an iterator over the elements contained in this collection 7.65/2.82 */ 7.65/2.82 public abstract Iterator iterator(); 7.65/2.82 7.65/2.82 public abstract int size(); 7.65/2.82 7.65/2.82 /** 7.65/2.82 * {@inheritDoc} 7.65/2.82 * 7.65/2.82 *

This implementation returns size() == 0. 7.65/2.82 */ 7.65/2.82 public boolean isEmpty() { 7.65/2.82 return size() == 0; 7.65/2.82 } 7.65/2.82 7.65/2.82 /** 7.65/2.82 * {@inheritDoc} 7.65/2.82 * 7.65/2.82 *

This implementation iterates over the elements in the collection, 7.65/2.82 * checking each element in turn for equality with the specified element. 7.65/2.82 * 7.65/2.82 * @throws ClassCastException {@inheritDoc} 7.65/2.82 * @throws NullPointerException {@inheritDoc} 7.65/2.82 */ 7.65/2.82 public boolean contains(Object o) { 7.65/2.82 Iterator e = iterator(); 7.65/2.82 if (o==null) { 7.65/2.82 while (e.hasNext()) 7.65/2.82 if (e.next()==null) 7.65/2.82 return true; 7.65/2.82 } else { 7.65/2.82 while (e.hasNext()) 7.65/2.82 if (o.equals(e.next())) 7.65/2.82 return true; 7.65/2.82 } 7.65/2.82 return false; 7.65/2.82 } 7.65/2.82 7.65/2.82 // Modification Operations 7.65/2.82 7.65/2.82 /** 7.65/2.82 * {@inheritDoc} 7.65/2.82 * 7.65/2.82 *

This implementation always throws an 7.65/2.82 * UnsupportedOperationException. 7.65/2.82 * 7.65/2.82 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.82 * @throws ClassCastException {@inheritDoc} 7.65/2.82 * @throws NullPointerException {@inheritDoc} 7.65/2.82 * @throws IllegalArgumentException {@inheritDoc} 7.65/2.82 * @throws IllegalStateException {@inheritDoc} 7.65/2.82 */ 7.65/2.82 public boolean add(E e) { 7.65/2.82 throw new UnsupportedOperationException(); 7.65/2.82 } 7.65/2.82 7.65/2.82 /** 7.65/2.82 * {@inheritDoc} 7.65/2.82 * 7.65/2.82 *

This implementation iterates over the collection looking for the 7.65/2.82 * specified element. If it finds the element, it removes the element 7.65/2.82 * from the collection using the iterator's remove method. 7.65/2.82 * 7.65/2.82 *

Note that this implementation throws an 7.65/2.82 * UnsupportedOperationException if the iterator returned by this 7.65/2.82 * collection's iterator method does not implement the remove 7.65/2.82 * method and this collection contains the specified object. 7.65/2.82 * 7.65/2.82 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.82 * @throws ClassCastException {@inheritDoc} 7.65/2.82 * @throws NullPointerException {@inheritDoc} 7.65/2.82 */ 7.65/2.82 public boolean remove(Object o) { 7.65/2.82 Iterator e = iterator(); 7.65/2.82 if (o==null) { 7.65/2.82 while (e.hasNext()) { 7.65/2.82 if (e.next()==null) { 7.65/2.82 e.remove(); 7.65/2.82 return true; 7.65/2.82 } 7.65/2.82 } 7.65/2.82 } else { 7.65/2.82 while (e.hasNext()) { 7.65/2.82 if (o.equals(e.next())) { 7.65/2.82 e.remove(); 7.65/2.82 return true; 7.65/2.82 } 7.65/2.82 } 7.65/2.82 } 7.65/2.82 return false; 7.65/2.82 } 7.65/2.82 7.65/2.82 7.65/2.82 // Bulk Operations 7.65/2.82 7.65/2.82 /** 7.65/2.82 * {@inheritDoc} 7.65/2.82 * 7.65/2.82 *

This implementation iterates over the specified collection, 7.65/2.82 * checking each element returned by the iterator in turn to see 7.65/2.82 * if it's contained in this collection. If all elements are so 7.65/2.82 * contained true is returned, otherwise false. 7.65/2.82 * 7.65/2.82 * @throws ClassCastException {@inheritDoc} 7.65/2.82 * @throws NullPointerException {@inheritDoc} 7.65/2.82 * @see #contains(Object) 7.65/2.82 */ 7.65/2.82 public boolean containsAll(Collection c) { 7.65/2.82 Iterator e = c.iterator(); 7.65/2.82 while (e.hasNext()) 7.65/2.82 if (!contains(e.next())) 7.65/2.82 return false; 7.65/2.82 return true; 7.65/2.82 } 7.65/2.82 7.65/2.82 /** 7.65/2.82 * {@inheritDoc} 7.65/2.82 * 7.65/2.82 *

This implementation iterates over the specified collection, and adds 7.65/2.82 * each object returned by the iterator to this collection, in turn. 7.65/2.82 * 7.65/2.82 *

Note that this implementation will throw an 7.65/2.82 * UnsupportedOperationException unless add is 7.65/2.82 * overridden (assuming the specified collection is non-empty). 7.65/2.82 * 7.65/2.82 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.82 * @throws ClassCastException {@inheritDoc} 7.65/2.82 * @throws NullPointerException {@inheritDoc} 7.65/2.82 * @throws IllegalArgumentException {@inheritDoc} 7.65/2.82 * @throws IllegalStateException {@inheritDoc} 7.65/2.82 * 7.65/2.82 * @see #add(Object) 7.65/2.82 */ 7.65/2.82 public boolean addAll(Collection c) { 7.65/2.82 boolean modified = false; 7.65/2.82 Iterator e = c.iterator(); 7.65/2.82 while (e.hasNext()) { 7.65/2.82 if (add(e.next())) 7.65/2.82 modified = true; 7.65/2.82 } 7.65/2.82 return modified; 7.65/2.82 } 7.65/2.82 7.65/2.82 /** 7.65/2.82 * {@inheritDoc} 7.65/2.82 * 7.65/2.82 *

This implementation iterates over this collection, checking each 7.65/2.82 * element returned by the iterator in turn to see if it's contained 7.65/2.82 * in the specified collection. If it's so contained, it's removed from 7.65/2.82 * this collection with the iterator's remove method. 7.65/2.82 * 7.65/2.82 *

Note that this implementation will throw an 7.65/2.82 * UnsupportedOperationException if the iterator returned by the 7.65/2.82 * iterator method does not implement the remove method 7.65/2.82 * and this collection contains one or more elements in common with the 7.65/2.82 * specified collection. 7.65/2.82 * 7.65/2.82 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.82 * @throws ClassCastException {@inheritDoc} 7.65/2.82 * @throws NullPointerException {@inheritDoc} 7.65/2.82 * 7.65/2.82 * @see #remove(Object) 7.65/2.82 * @see #contains(Object) 7.65/2.82 */ 7.65/2.82 public boolean removeAll(Collection c) { 7.65/2.82 boolean modified = false; 7.65/2.82 Iterator e = iterator(); 7.65/2.82 while (e.hasNext()) { 7.65/2.82 if (c.contains(e.next())) { 7.65/2.82 e.remove(); 7.65/2.82 modified = true; 7.65/2.82 } 7.65/2.82 } 7.65/2.82 return modified; 7.65/2.82 } 7.65/2.82 7.65/2.82 /** 7.65/2.82 * {@inheritDoc} 7.65/2.82 * 7.65/2.82 *

This implementation iterates over this collection, checking each 7.65/2.82 * element returned by the iterator in turn to see if it's contained 7.65/2.82 * in the specified collection. If it's not so contained, it's removed 7.65/2.82 * from this collection with the iterator's remove method. 7.65/2.82 * 7.65/2.82 *

Note that this implementation will throw an 7.65/2.82 * UnsupportedOperationException if the iterator returned by the 7.65/2.82 * iterator method does not implement the remove method 7.65/2.82 * and this collection contains one or more elements not present in the 7.65/2.82 * specified collection. 7.65/2.82 * 7.65/2.82 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.82 * @throws ClassCastException {@inheritDoc} 7.65/2.82 * @throws NullPointerException {@inheritDoc} 7.65/2.82 * 7.65/2.82 * @see #remove(Object) 7.65/2.82 * @see #contains(Object) 7.65/2.82 */ 7.65/2.82 public boolean retainAll(Collection c) { 7.65/2.82 boolean modified = false; 7.65/2.82 Iterator e = iterator(); 7.65/2.82 while (e.hasNext()) { 7.65/2.82 if (!c.contains(e.next())) { 7.65/2.82 e.remove(); 7.65/2.82 modified = true; 7.65/2.82 } 7.65/2.82 } 7.65/2.82 return modified; 7.65/2.82 } 7.65/2.82 7.65/2.82 /** 7.65/2.82 * {@inheritDoc} 7.65/2.82 * 7.65/2.82 *

This implementation iterates over this collection, removing each 7.65/2.82 * element using the Iterator.remove operation. Most 7.65/2.82 * implementations will probably choose to override this method for 7.65/2.82 * efficiency. 7.65/2.82 * 7.65/2.82 *

Note that this implementation will throw an 7.65/2.82 * UnsupportedOperationException if the iterator returned by this 7.65/2.82 * collection's iterator method does not implement the 7.65/2.82 * remove method and this collection is non-empty. 7.65/2.82 * 7.65/2.82 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.82 */ 7.65/2.82 public void clear() { 7.65/2.82 Iterator e = iterator(); 7.65/2.82 while (e.hasNext()) { 7.65/2.82 e.next(); 7.65/2.82 e.remove(); 7.65/2.82 } 7.65/2.82 } 7.65/2.82 7.65/2.82 7.65/2.82 // String conversion 7.65/2.82 7.65/2.82 /** 7.65/2.82 * Returns a string representation of this collection. The string 7.65/2.82 * representation consists of a list of the collection's elements in the 7.65/2.82 * order they are returned by its iterator, enclosed in square brackets 7.65/2.82 * ("[]"). Adjacent elements are separated by the characters 7.65/2.82 * ", " (comma and space). Elements are converted to strings as 7.65/2.82 * by {@link String#valueOf(Object)}. 7.65/2.82 * 7.65/2.82 * @return a string representation of this collection 7.65/2.82 */ 7.65/2.82 public String toString() { 7.65/2.82 Iterator i = iterator(); 7.65/2.82 if (! i.hasNext()) 7.65/2.82 return "[]"; 7.65/2.82 7.65/2.82 String sb = ""; 7.65/2.82 sb = sb + "["; 7.65/2.82 for (;;) { 7.65/2.82 E e = i.next(); 7.65/2.82 sb = sb + (e == this ? "(this Collection)" : e); 7.65/2.82 if (! i.hasNext()) { 7.65/2.82 sb = sb + "]"; 7.65/2.82 return sb; 7.65/2.82 } 7.65/2.82 sb = sb + ", "; 7.65/2.82 } 7.65/2.82 } 7.65/2.82 7.65/2.82 } 7.65/2.82 7.65/2.82 7.65/2.82 /* 7.65/2.82 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. 7.65/2.82 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.65/2.82 * 7.65/2.82 * This code is free software; you can redistribute it and/or modify it 7.65/2.82 * under the terms of the GNU General Public License version 2 only, as 7.65/2.82 * published by the Free Software Foundation. Sun designates this 7.65/2.82 * particular file as subject to the "Classpath" exception as provided 7.65/2.82 * by Sun in the LICENSE file that accompanied this code. 7.65/2.82 * 7.65/2.82 * This code is distributed in the hope that it will be useful, but WITHOUT 7.65/2.82 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.65/2.82 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.65/2.82 * version 2 for more details (a copy is included in the LICENSE file that 7.65/2.82 * accompanied this code). 7.65/2.82 * 7.65/2.82 * You should have received a copy of the GNU General Public License version 7.65/2.82 * 2 along with this work; if not, write to the Free Software Foundation, 7.65/2.82 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.65/2.82 * 7.65/2.82 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 7.65/2.82 * CA 95054 USA or visit www.sun.com if you need additional information or 7.65/2.82 * have any questions. 7.65/2.82 */ 7.65/2.82 7.65/2.82 package javaUtilEx; 7.65/2.82 import javaUtilEx.Map.Entry; 7.65/2.82 7.65/2.82 /** 7.65/2.82 * This class provides a skeletal implementation of the Map 7.65/2.82 * interface, to minimize the effort required to implement this interface. 7.65/2.82 * 7.65/2.82 *

To implement an unmodifiable map, the programmer needs only to extend this 7.65/2.82 * class and provide an implementation for the entrySet method, which 7.65/2.82 * returns a set-view of the map's mappings. Typically, the returned set 7.65/2.82 * will, in turn, be implemented atop AbstractSet. This set should 7.65/2.82 * not support the add or remove methods, and its iterator 7.65/2.82 * should not support the remove method. 7.65/2.82 * 7.65/2.82 *

To implement a modifiable map, the programmer must additionally override 7.65/2.82 * this class's put method (which otherwise throws an 7.65/2.82 * UnsupportedOperationException), and the iterator returned by 7.65/2.82 * entrySet().iterator() must additionally implement its 7.65/2.82 * remove method. 7.65/2.82 * 7.65/2.82 *

The programmer should generally provide a void (no argument) and map 7.65/2.82 * constructor, as per the recommendation in the Map interface 7.65/2.82 * specification. 7.65/2.82 * 7.65/2.82 *

The documentation for each non-abstract method in this class describes its 7.65/2.82 * implementation in detail. Each of these methods may be overridden if the 7.65/2.82 * map being implemented admits a more efficient implementation. 7.65/2.82 * 7.65/2.82 *

This class is a member of the 7.65/2.82 * 7.65/2.82 * Java Collections Framework. 7.65/2.82 * 7.65/2.82 * @param the type of keys maintained by this map 7.65/2.82 * @param the type of mapped values 7.65/2.82 * 7.65/2.82 * @author Josh Bloch 7.65/2.82 * @author Neal Gafter 7.65/2.82 * @see Map 7.65/2.82 * @see Collection 7.65/2.82 * @since 1.2 7.65/2.82 */ 7.65/2.82 7.65/2.82 public abstract class AbstractMap implements Map { 7.65/2.82 /** 7.65/2.82 * Sole constructor. (For invocation by subclass constructors, typically 7.65/2.82 * implicit.) 7.65/2.82 */ 7.65/2.82 protected AbstractMap() { 7.65/2.82 } 7.65/2.82 7.65/2.82 // Query Operations 7.65/2.82 7.65/2.82 /** 7.65/2.82 * {@inheritDoc} 7.65/2.82 * 7.65/2.82 *

This implementation returns entrySet().size(). 7.65/2.82 */ 7.65/2.82 public int size() { 7.65/2.82 return entrySet().size(); 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * {@inheritDoc} 7.65/2.83 * 7.65/2.83 *

This implementation returns size() == 0. 7.65/2.83 */ 7.65/2.83 public boolean isEmpty() { 7.65/2.83 return size() == 0; 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * {@inheritDoc} 7.65/2.83 * 7.65/2.83 *

This implementation iterates over entrySet() searching 7.65/2.83 * for an entry with the specified value. If such an entry is found, 7.65/2.83 * true is returned. If the iteration terminates without 7.65/2.83 * finding such an entry, false is returned. Note that this 7.65/2.83 * implementation requires linear time in the size of the map. 7.65/2.83 * 7.65/2.83 * @throws ClassCastException {@inheritDoc} 7.65/2.83 * @throws NullPointerException {@inheritDoc} 7.65/2.83 */ 7.65/2.83 public boolean containsValue(Object value) { 7.65/2.83 Iterator> i = entrySet().iterator(); 7.65/2.83 if (value==null) { 7.65/2.83 while (i.hasNext()) { 7.65/2.83 Entry e = i.next(); 7.65/2.83 if (e.getValue()==null) 7.65/2.83 return true; 7.65/2.83 } 7.65/2.83 } else { 7.65/2.83 while (i.hasNext()) { 7.65/2.83 Entry e = i.next(); 7.65/2.83 if (value.equals(e.getValue())) 7.65/2.83 return true; 7.65/2.83 } 7.65/2.83 } 7.65/2.83 return false; 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * {@inheritDoc} 7.65/2.83 * 7.65/2.83 *

This implementation iterates over entrySet() searching 7.65/2.83 * for an entry with the specified key. If such an entry is found, 7.65/2.83 * true is returned. If the iteration terminates without 7.65/2.83 * finding such an entry, false is returned. Note that this 7.65/2.83 * implementation requires linear time in the size of the map; many 7.65/2.83 * implementations will override this method. 7.65/2.83 * 7.65/2.83 * @throws ClassCastException {@inheritDoc} 7.65/2.83 * @throws NullPointerException {@inheritDoc} 7.65/2.83 */ 7.65/2.83 public boolean containsKey(Object key) { 7.65/2.83 Iterator> i = entrySet().iterator(); 7.65/2.83 if (key==null) { 7.65/2.83 while (i.hasNext()) { 7.65/2.83 Entry e = i.next(); 7.65/2.83 if (e.getKey()==null) 7.65/2.83 return true; 7.65/2.83 } 7.65/2.83 } else { 7.65/2.83 while (i.hasNext()) { 7.65/2.83 Entry e = i.next(); 7.65/2.83 if (key.equals(e.getKey())) 7.65/2.83 return true; 7.65/2.83 } 7.65/2.83 } 7.65/2.83 return false; 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * {@inheritDoc} 7.65/2.83 * 7.65/2.83 *

This implementation iterates over entrySet() searching 7.65/2.83 * for an entry with the specified key. If such an entry is found, 7.65/2.83 * the entry's value is returned. If the iteration terminates without 7.65/2.83 * finding such an entry, null is returned. Note that this 7.65/2.83 * implementation requires linear time in the size of the map; many 7.65/2.83 * implementations will override this method. 7.65/2.83 * 7.65/2.83 * @throws ClassCastException {@inheritDoc} 7.65/2.83 * @throws NullPointerException {@inheritDoc} 7.65/2.83 */ 7.65/2.83 public V get(Object key) { 7.65/2.83 Iterator> i = entrySet().iterator(); 7.65/2.83 if (key==null) { 7.65/2.83 while (i.hasNext()) { 7.65/2.83 Entry e = i.next(); 7.65/2.83 if (e.getKey()==null) 7.65/2.83 return e.getValue(); 7.65/2.83 } 7.65/2.83 } else { 7.65/2.83 while (i.hasNext()) { 7.65/2.83 Entry e = i.next(); 7.65/2.83 if (key.equals(e.getKey())) 7.65/2.83 return e.getValue(); 7.65/2.83 } 7.65/2.83 } 7.65/2.83 return null; 7.65/2.83 } 7.65/2.83 7.65/2.83 7.65/2.83 // Modification Operations 7.65/2.83 7.65/2.83 /** 7.65/2.83 * {@inheritDoc} 7.65/2.83 * 7.65/2.83 *

This implementation always throws an 7.65/2.83 * UnsupportedOperationException. 7.65/2.83 * 7.65/2.83 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.83 * @throws ClassCastException {@inheritDoc} 7.65/2.83 * @throws NullPointerException {@inheritDoc} 7.65/2.83 * @throws IllegalArgumentException {@inheritDoc} 7.65/2.83 */ 7.65/2.83 public V put(K key, V value) { 7.65/2.83 throw new UnsupportedOperationException(); 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * {@inheritDoc} 7.65/2.83 * 7.65/2.83 *

This implementation iterates over entrySet() searching for an 7.65/2.83 * entry with the specified key. If such an entry is found, its value is 7.65/2.83 * obtained with its getValue operation, the entry is removed 7.65/2.83 * from the collection (and the backing map) with the iterator's 7.65/2.83 * remove operation, and the saved value is returned. If the 7.65/2.83 * iteration terminates without finding such an entry, null is 7.65/2.83 * returned. Note that this implementation requires linear time in the 7.65/2.83 * size of the map; many implementations will override this method. 7.65/2.83 * 7.65/2.83 *

Note that this implementation throws an 7.65/2.83 * UnsupportedOperationException if the entrySet 7.65/2.83 * iterator does not support the remove method and this map 7.65/2.83 * contains a mapping for the specified key. 7.65/2.83 * 7.65/2.83 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.83 * @throws ClassCastException {@inheritDoc} 7.65/2.83 * @throws NullPointerException {@inheritDoc} 7.65/2.83 */ 7.65/2.83 public V remove(Object key) { 7.65/2.83 Iterator> i = entrySet().iterator(); 7.65/2.83 Entry correctEntry = null; 7.65/2.83 if (key==null) { 7.65/2.83 while (correctEntry==null && i.hasNext()) { 7.65/2.83 Entry e = i.next(); 7.65/2.83 if (e.getKey()==null) 7.65/2.83 correctEntry = e; 7.65/2.83 } 7.65/2.83 } else { 7.65/2.83 while (correctEntry==null && i.hasNext()) { 7.65/2.83 Entry e = i.next(); 7.65/2.83 if (key.equals(e.getKey())) 7.65/2.83 correctEntry = e; 7.65/2.83 } 7.65/2.83 } 7.65/2.83 7.65/2.83 V oldValue = null; 7.65/2.83 if (correctEntry !=null) { 7.65/2.83 oldValue = correctEntry.getValue(); 7.65/2.83 i.remove(); 7.65/2.83 } 7.65/2.83 return oldValue; 7.65/2.83 } 7.65/2.83 7.65/2.83 7.65/2.83 // Bulk Operations 7.65/2.83 7.65/2.83 /** 7.65/2.83 * {@inheritDoc} 7.65/2.83 * 7.65/2.83 *

This implementation iterates over the specified map's 7.65/2.83 * entrySet() collection, and calls this map's put 7.65/2.83 * operation once for each entry returned by the iteration. 7.65/2.83 * 7.65/2.83 *

Note that this implementation throws an 7.65/2.83 * UnsupportedOperationException if this map does not support 7.65/2.83 * the put operation and the specified map is nonempty. 7.65/2.83 * 7.65/2.83 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.83 * @throws ClassCastException {@inheritDoc} 7.65/2.83 * @throws NullPointerException {@inheritDoc} 7.65/2.83 * @throws IllegalArgumentException {@inheritDoc} 7.65/2.83 */ 7.65/2.83 public void putAll(Map m) { 7.65/2.83 Iterator it = m.entrySet().iterator(); 7.65/2.83 while (it.hasNext()) { 7.65/2.83 Map.Entry e = (Map.Entry) it.next(); 7.65/2.83 put((K) e.getKey(), (V) e.getValue()); 7.65/2.83 } 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * {@inheritDoc} 7.65/2.83 * 7.65/2.83 *

This implementation calls entrySet().clear(). 7.65/2.83 * 7.65/2.83 *

Note that this implementation throws an 7.65/2.83 * UnsupportedOperationException if the entrySet 7.65/2.83 * does not support the clear operation. 7.65/2.83 * 7.65/2.83 * @throws UnsupportedOperationException {@inheritDoc} 7.65/2.83 */ 7.65/2.83 public void clear() { 7.65/2.83 entrySet().clear(); 7.65/2.83 } 7.65/2.83 7.65/2.83 7.65/2.83 // Views 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Each of these fields are initialized to contain an instance of the 7.65/2.83 * appropriate view the first time this view is requested. The views are 7.65/2.83 * stateless, so there's no reason to create more than one of each. 7.65/2.83 */ 7.65/2.83 transient volatile Set keySet = null; 7.65/2.83 transient volatile Collection values = null; 7.65/2.83 7.65/2.83 /** 7.65/2.83 * {@inheritDoc} 7.65/2.83 * 7.65/2.83 *

This implementation returns a set that subclasses {@link AbstractSet}. 7.65/2.83 * The subclass's iterator method returns a "wrapper object" over this 7.65/2.83 * map's entrySet() iterator. The size method 7.65/2.83 * delegates to this map's size method and the 7.65/2.83 * contains method delegates to this map's 7.65/2.83 * containsKey method. 7.65/2.83 * 7.65/2.83 *

The set is created the first time this method is called, 7.65/2.83 * and returned in response to all subsequent calls. No synchronization 7.65/2.83 * is performed, so there is a slight chance that multiple calls to this 7.65/2.83 * method will not all return the same set. 7.65/2.83 */ 7.65/2.83 public Set keySet() { 7.65/2.83 if (keySet == null) { 7.65/2.83 keySet = new AbstractSet() { 7.65/2.83 public Iterator iterator() { 7.65/2.83 return new Iterator() { 7.65/2.83 private Iterator> i = entrySet().iterator(); 7.65/2.83 7.65/2.83 public boolean hasNext() { 7.65/2.83 return i.hasNext(); 7.65/2.83 } 7.65/2.83 7.65/2.83 public K next() { 7.65/2.83 return i.next().getKey(); 7.65/2.83 } 7.65/2.83 7.65/2.83 public void remove() { 7.65/2.83 i.remove(); 7.65/2.83 } 7.65/2.83 }; 7.65/2.83 } 7.65/2.83 7.65/2.83 public int size() { 7.65/2.83 return AbstractMap.this.size(); 7.65/2.83 } 7.65/2.83 7.65/2.83 public boolean isEmpty() { 7.65/2.83 return AbstractMap.this.isEmpty(); 7.65/2.83 } 7.65/2.83 7.65/2.83 public void clear() { 7.65/2.83 AbstractMap.this.clear(); 7.65/2.83 } 7.65/2.83 7.65/2.83 public boolean contains(Object k) { 7.65/2.83 return AbstractMap.this.containsKey(k); 7.65/2.83 } 7.65/2.83 7.65/2.83 public Object[] toArray() { 7.65/2.83 Object[] res = new Object[AbstractMap.this.size()]; 7.65/2.83 Iterator> it = entrySet().iterator(); 7.65/2.83 int i = 0; 7.65/2.83 while (it.hasNext()) 7.65/2.83 res[i++] = it.next().getKey(); 7.65/2.83 return res; 7.65/2.83 } 7.65/2.83 7.65/2.83 public T[] toArray(T[] a) { 7.65/2.83 a = (T[])java.lang.reflect.Array.newInstance( 7.65/2.83 a.getClass().getComponentType(), AbstractMap.this.size()); 7.65/2.83 Object[] res = a; 7.65/2.83 Iterator> it = entrySet().iterator(); 7.65/2.83 int i = 0; 7.65/2.83 while (it.hasNext()) 7.65/2.83 res[i++] = it.next().getKey(); 7.65/2.83 return a; 7.65/2.83 } 7.65/2.83 }; 7.65/2.83 } 7.65/2.83 return keySet; 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * {@inheritDoc} 7.65/2.83 * 7.65/2.83 *

This implementation returns a collection that subclasses {@link 7.65/2.83 * AbstractCollection}. The subclass's iterator method returns a 7.65/2.83 * "wrapper object" over this map's entrySet() iterator. 7.65/2.83 * The size method delegates to this map's size 7.65/2.83 * method and the contains method delegates to this map's 7.65/2.83 * containsValue method. 7.65/2.83 * 7.65/2.83 *

The collection is created the first time this method is called, and 7.65/2.83 * returned in response to all subsequent calls. No synchronization is 7.65/2.83 * performed, so there is a slight chance that multiple calls to this 7.65/2.83 * method will not all return the same collection. 7.65/2.83 */ 7.65/2.83 public Collection values() { 7.65/2.83 if (values == null) { 7.65/2.83 values = new AbstractCollection() { 7.65/2.83 public Iterator iterator() { 7.65/2.83 return new Iterator() { 7.65/2.83 private Iterator> i = entrySet().iterator(); 7.65/2.83 7.65/2.83 public boolean hasNext() { 7.65/2.83 return i.hasNext(); 7.65/2.83 } 7.65/2.83 7.65/2.83 public V next() { 7.65/2.83 return i.next().getValue(); 7.65/2.83 } 7.65/2.83 7.65/2.83 public void remove() { 7.65/2.83 i.remove(); 7.65/2.83 } 7.65/2.83 }; 7.65/2.83 } 7.65/2.83 7.65/2.83 public int size() { 7.65/2.83 return AbstractMap.this.size(); 7.65/2.83 } 7.65/2.83 7.65/2.83 public boolean isEmpty() { 7.65/2.83 return AbstractMap.this.isEmpty(); 7.65/2.83 } 7.65/2.83 7.65/2.83 public void clear() { 7.65/2.83 AbstractMap.this.clear(); 7.65/2.83 } 7.65/2.83 7.65/2.83 public boolean contains(Object v) { 7.65/2.83 return AbstractMap.this.containsValue(v); 7.65/2.83 } 7.65/2.83 }; 7.65/2.83 } 7.65/2.83 return values; 7.65/2.83 } 7.65/2.83 7.65/2.83 public abstract Set> entrySet(); 7.65/2.83 7.65/2.83 7.65/2.83 // Comparison and hashing 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Compares the specified object with this map for equality. Returns 7.65/2.83 * true if the given object is also a map and the two maps 7.65/2.83 * represent the same mappings. More formally, two maps m1 and 7.65/2.83 * m2 represent the same mappings if 7.65/2.83 * m1.entrySet().equals(m2.entrySet()). This ensures that the 7.65/2.83 * equals method works properly across different implementations 7.65/2.83 * of the Map interface. 7.65/2.83 * 7.65/2.83 *

This implementation first checks if the specified object is this map; 7.65/2.83 * if so it returns true. Then, it checks if the specified 7.65/2.83 * object is a map whose size is identical to the size of this map; if 7.65/2.83 * not, it returns false. If so, it iterates over this map's 7.65/2.83 * entrySet collection, and checks that the specified map 7.65/2.83 * contains each mapping that this map contains. If the specified map 7.65/2.83 * fails to contain such a mapping, false is returned. If the 7.65/2.83 * iteration completes, true is returned. 7.65/2.83 * 7.65/2.83 * @param o object to be compared for equality with this map 7.65/2.83 * @return true if the specified object is equal to this map 7.65/2.83 */ 7.65/2.83 public boolean equals(Object o) { 7.65/2.83 if (o == this) 7.65/2.83 return true; 7.65/2.83 7.65/2.83 if (!(o instanceof Map)) 7.65/2.83 return false; 7.65/2.83 Map m = (Map) o; 7.65/2.83 if (m.size() != size()) 7.65/2.83 return false; 7.65/2.83 7.65/2.83 try { 7.65/2.83 Iterator> i = entrySet().iterator(); 7.65/2.83 while (i.hasNext()) { 7.65/2.83 Entry e = i.next(); 7.65/2.83 K key = e.getKey(); 7.65/2.83 V value = e.getValue(); 7.65/2.83 if (value == null) { 7.65/2.83 if (!(m.get(key)==null && m.containsKey(key))) 7.65/2.83 return false; 7.65/2.83 } else { 7.65/2.83 if (!value.equals(m.get(key))) 7.65/2.83 return false; 7.65/2.83 } 7.65/2.83 } 7.65/2.83 } catch (ClassCastException unused) { 7.65/2.83 return false; 7.65/2.83 } catch (NullPointerException unused) { 7.65/2.83 return false; 7.65/2.83 } 7.65/2.83 7.65/2.83 return true; 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Returns the hash code value for this map. The hash code of a map is 7.65/2.83 * defined to be the sum of the hash codes of each entry in the map's 7.65/2.83 * entrySet() view. This ensures that m1.equals(m2) 7.65/2.83 * implies that m1.hashCode()==m2.hashCode() for any two maps 7.65/2.83 * m1 and m2, as required by the general contract of 7.65/2.83 * {@link Object#hashCode}. 7.65/2.83 * 7.65/2.83 *

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

7.65/2.83	         *   (e1.getKey()==null ?
7.65/2.83	         *    e2.getKey()==null :
7.65/2.83	         *    e1.getKey().equals(e2.getKey()))
7.65/2.83	         *   &&
7.65/2.83	         *   (e1.getValue()==null ?
7.65/2.83	         *    e2.getValue()==null :
7.65/2.83	         *    e1.getValue().equals(e2.getValue()))
7.65/2.83 * This ensures that the {@code equals} method works properly across 7.65/2.83 * different implementations of the {@code Map.Entry} interface. 7.65/2.83 * 7.65/2.83 * @param o object to be compared for equality with this map entry 7.65/2.83 * @return {@code true} if the specified object is equal to this map 7.65/2.83 * entry 7.65/2.83 * @see #hashCode 7.65/2.83 */ 7.65/2.83 public boolean equals(Object o) { 7.65/2.83 if (!(o instanceof Map.Entry)) 7.65/2.83 return false; 7.65/2.83 Map.Entry e = (Map.Entry)o; 7.65/2.83 return eq(key, e.getKey()) && eq(value, e.getValue()); 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Returns the hash code value for this map entry. The hash code 7.65/2.83 * of a map entry {@code e} is defined to be:
7.65/2.83	         *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
7.65/2.83	         *   (e.getValue()==null ? 0 : e.getValue().hashCode())
7.65/2.83 * This ensures that {@code e1.equals(e2)} implies that 7.65/2.83 * {@code e1.hashCode()==e2.hashCode()} for any two Entries 7.65/2.83 * {@code e1} and {@code e2}, as required by the general 7.65/2.83 * contract of {@link Object#hashCode}. 7.65/2.83 * 7.65/2.83 * @return the hash code value for this map entry 7.65/2.83 * @see #equals 7.65/2.83 */ 7.65/2.83 public int hashCode() { 7.65/2.83 return (key == null ? 0 : key.hashCode()) ^ 7.65/2.83 (value == null ? 0 : value.hashCode()); 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Returns a String representation of this map entry. This 7.65/2.83 * implementation returns the string representation of this 7.65/2.83 * entry's key followed by the equals character ("=") 7.65/2.83 * followed by the string representation of this entry's value. 7.65/2.83 * 7.65/2.83 * @return a String representation of this map entry 7.65/2.83 */ 7.65/2.83 public String toString() { 7.65/2.83 return key + "=" + value; 7.65/2.83 } 7.65/2.83 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * An Entry maintaining an immutable key and value. This class 7.65/2.83 * does not support method setValue. This class may be 7.65/2.83 * convenient in methods that return thread-safe snapshots of 7.65/2.83 * key-value mappings. 7.65/2.83 * 7.65/2.83 * @since 1.6 7.65/2.83 */ 7.65/2.83 public static class SimpleImmutableEntry 7.65/2.83 implements Entry, java.io.Serializable 7.65/2.83 { 7.65/2.83 private static final long serialVersionUID = 7138329143949025153L; 7.65/2.83 7.65/2.83 private final K key; 7.65/2.83 private final V value; 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Creates an entry representing a mapping from the specified 7.65/2.83 * key to the specified value. 7.65/2.83 * 7.65/2.83 * @param key the key represented by this entry 7.65/2.83 * @param value the value represented by this entry 7.65/2.83 */ 7.65/2.83 public SimpleImmutableEntry(K key, V value) { 7.65/2.83 this.key = key; 7.65/2.83 this.value = value; 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Creates an entry representing the same mapping as the 7.65/2.83 * specified entry. 7.65/2.83 * 7.65/2.83 * @param entry the entry to copy 7.65/2.83 */ 7.65/2.83 public SimpleImmutableEntry(Entry entry) { 7.65/2.83 this.key = entry.getKey(); 7.65/2.83 this.value = entry.getValue(); 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Returns the key corresponding to this entry. 7.65/2.83 * 7.65/2.83 * @return the key corresponding to this entry 7.65/2.83 */ 7.65/2.83 public K getKey() { 7.65/2.83 return key; 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Returns the value corresponding to this entry. 7.65/2.83 * 7.65/2.83 * @return the value corresponding to this entry 7.65/2.83 */ 7.65/2.83 public V getValue() { 7.65/2.83 return value; 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Replaces the value corresponding to this entry with the specified 7.65/2.83 * value (optional operation). This implementation simply throws 7.65/2.83 * UnsupportedOperationException, as this class implements 7.65/2.83 * an immutable map entry. 7.65/2.83 * 7.65/2.83 * @param value new value to be stored in this entry 7.65/2.83 * @return (Does not return) 7.65/2.83 * @throws UnsupportedOperationException always 7.65/2.83 */ 7.65/2.83 public V setValue(V value) { 7.65/2.83 throw new UnsupportedOperationException(); 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Compares the specified object with this entry for equality. 7.65/2.83 * Returns {@code true} if the given object is also a map entry and 7.65/2.83 * the two entries represent the same mapping. More formally, two 7.65/2.83 * entries {@code e1} and {@code e2} represent the same mapping 7.65/2.83 * if
7.65/2.83	         *   (e1.getKey()==null ?
7.65/2.83	         *    e2.getKey()==null :
7.65/2.83	         *    e1.getKey().equals(e2.getKey()))
7.65/2.83	         *   &&
7.65/2.83	         *   (e1.getValue()==null ?
7.65/2.83	         *    e2.getValue()==null :
7.65/2.83	         *    e1.getValue().equals(e2.getValue()))
7.65/2.83 * This ensures that the {@code equals} method works properly across 7.65/2.83 * different implementations of the {@code Map.Entry} interface. 7.65/2.83 * 7.65/2.83 * @param o object to be compared for equality with this map entry 7.65/2.83 * @return {@code true} if the specified object is equal to this map 7.65/2.83 * entry 7.65/2.83 * @see #hashCode 7.65/2.83 */ 7.65/2.83 public boolean equals(Object o) { 7.65/2.83 if (!(o instanceof Map.Entry)) 7.65/2.83 return false; 7.65/2.83 Map.Entry e = (Map.Entry)o; 7.65/2.83 return eq(key, e.getKey()) && eq(value, e.getValue()); 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Returns the hash code value for this map entry. The hash code 7.65/2.83 * of a map entry {@code e} is defined to be:
7.65/2.83	         *   (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
7.65/2.83	         *   (e.getValue()==null ? 0 : e.getValue().hashCode())
7.65/2.83 * This ensures that {@code e1.equals(e2)} implies that 7.65/2.83 * {@code e1.hashCode()==e2.hashCode()} for any two Entries 7.65/2.83 * {@code e1} and {@code e2}, as required by the general 7.65/2.83 * contract of {@link Object#hashCode}. 7.65/2.83 * 7.65/2.83 * @return the hash code value for this map entry 7.65/2.83 * @see #equals 7.65/2.83 */ 7.65/2.83 public int hashCode() { 7.65/2.83 return (key == null ? 0 : key.hashCode()) ^ 7.65/2.83 (value == null ? 0 : value.hashCode()); 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Returns a String representation of this map entry. This 7.65/2.83 * implementation returns the string representation of this 7.65/2.83 * entry's key followed by the equals character ("=") 7.65/2.83 * followed by the string representation of this entry's value. 7.65/2.83 * 7.65/2.83 * @return a String representation of this map entry 7.65/2.83 */ 7.65/2.83 public String toString() { 7.65/2.83 return key + "=" + value; 7.65/2.83 } 7.65/2.83 7.65/2.83 } 7.65/2.83 7.65/2.83 } 7.65/2.83 7.65/2.83 7.65/2.83 /* 7.65/2.83 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 7.65/2.83 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.65/2.83 * 7.65/2.83 * This code is free software; you can redistribute it and/or modify it 7.65/2.83 * under the terms of the GNU General Public License version 2 only, as 7.65/2.83 * published by the Free Software Foundation. Sun designates this 7.65/2.83 * particular file as subject to the "Classpath" exception as provided 7.65/2.83 * by Sun in the LICENSE file that accompanied this code. 7.65/2.83 * 7.65/2.83 * This code is distributed in the hope that it will be useful, but WITHOUT 7.65/2.83 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.65/2.83 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.65/2.83 * version 2 for more details (a copy is included in the LICENSE file that 7.65/2.83 * accompanied this code). 7.65/2.83 * 7.65/2.83 * You should have received a copy of the GNU General Public License version 7.65/2.83 * 2 along with this work; if not, write to the Free Software Foundation, 7.65/2.83 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.65/2.83 * 7.65/2.83 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 7.65/2.83 * CA 95054 USA or visit www.sun.com if you need additional information or 7.65/2.83 * have any questions. 7.65/2.83 */ 7.65/2.83 7.65/2.83 package javaUtilEx; 7.65/2.83 7.65/2.83 /** 7.65/2.83 * This class provides a skeletal implementation of the Set 7.65/2.83 * interface to minimize the effort required to implement this 7.65/2.83 * interface.

7.65/2.83 * 7.65/2.83 * The process of implementing a set by extending this class is identical 7.65/2.83 * to that of implementing a Collection by extending AbstractCollection, 7.65/2.83 * except that all of the methods and constructors in subclasses of this 7.65/2.83 * class must obey the additional constraints imposed by the Set 7.65/2.83 * interface (for instance, the add method must not permit addition of 7.65/2.83 * multiple instances of an object to a set).

7.65/2.83 * 7.65/2.83 * Note that this class does not override any of the implementations from 7.65/2.83 * the AbstractCollection class. It merely adds implementations 7.65/2.83 * for equals and hashCode.

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

7.65/2.83 * 7.65/2.83 * This implementation first checks if the specified object is this 7.65/2.83 * set; if so it returns true. Then, it checks if the 7.65/2.83 * specified object is a set whose size is identical to the size of 7.65/2.83 * this set; if not, it returns false. If so, it returns 7.65/2.83 * containsAll((Collection) o). 7.65/2.83 * 7.65/2.83 * @param o object to be compared for equality with this set 7.65/2.83 * @return true if the specified object is equal to this set 7.65/2.83 */ 7.65/2.83 public boolean equals(Object o) { 7.65/2.83 if (o == this) 7.65/2.83 return true; 7.65/2.83 7.65/2.83 if (!(o instanceof Set)) 7.65/2.83 return false; 7.65/2.83 Collection c = (Collection) o; 7.65/2.83 if (c.size() != size()) 7.65/2.83 return false; 7.65/2.83 try { 7.65/2.83 return containsAll(c); 7.65/2.83 } catch (ClassCastException unused) { 7.65/2.83 return false; 7.65/2.83 } catch (NullPointerException unused) { 7.65/2.83 return false; 7.65/2.83 } 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Returns the hash code value for this set. The hash code of a set is 7.65/2.83 * defined to be the sum of the hash codes of the elements in the set, 7.65/2.83 * where the hash code of a null element is defined to be zero. 7.65/2.83 * This ensures that s1.equals(s2) implies that 7.65/2.83 * s1.hashCode()==s2.hashCode() for any two sets s1 7.65/2.83 * and s2, as required by the general contract of 7.65/2.83 * {@link Object#hashCode}. 7.65/2.83 * 7.65/2.83 *

This implementation iterates over the set, calling the 7.65/2.83 * hashCode method on each element in the set, and adding up 7.65/2.83 * the results. 7.65/2.83 * 7.65/2.83 * @return the hash code value for this set 7.65/2.83 * @see Object#equals(Object) 7.65/2.83 * @see Set#equals(Object) 7.65/2.83 */ 7.65/2.83 public int hashCode() { 7.65/2.83 int h = 0; 7.65/2.83 Iterator i = iterator(); 7.65/2.83 while (i.hasNext()) { 7.65/2.83 E obj = i.next(); 7.65/2.83 if (obj != null) 7.65/2.83 h += obj.hashCode(); 7.65/2.83 } 7.65/2.83 return h; 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Removes from this set all of its elements that are contained in the 7.65/2.83 * specified collection (optional operation). If the specified 7.65/2.83 * collection is also a set, this operation effectively modifies this 7.65/2.83 * set so that its value is the asymmetric set difference of 7.65/2.83 * the two sets. 7.65/2.83 * 7.65/2.83 *

This implementation determines which is the smaller of this set 7.65/2.83 * and the specified collection, by invoking the size 7.65/2.83 * method on each. If this set has fewer elements, then the 7.65/2.83 * implementation iterates over this set, checking each element 7.65/2.83 * returned by the iterator in turn to see if it is contained in 7.65/2.83 * the specified collection. If it is so contained, it is removed 7.65/2.83 * from this set with the iterator's remove method. If 7.65/2.83 * the specified collection has fewer elements, then the 7.65/2.83 * implementation iterates over the specified collection, removing 7.65/2.83 * from this set each element returned by the iterator, using this 7.65/2.83 * set's remove method. 7.65/2.83 * 7.65/2.83 *

Note that this implementation will throw an 7.65/2.83 * UnsupportedOperationException if the iterator returned by the 7.65/2.83 * iterator method does not implement the remove method. 7.65/2.83 * 7.65/2.83 * @param c collection containing elements to be removed from this set 7.65/2.83 * @return true if this set changed as a result of the call 7.65/2.83 * @throws UnsupportedOperationException if the removeAll operation 7.65/2.83 * is not supported by this set 7.65/2.83 * @throws ClassCastException if the class of an element of this set 7.65/2.83 * is incompatible with the specified collection (optional) 7.65/2.83 * @throws NullPointerException if this set contains a null element and the 7.65/2.83 * specified collection does not permit null elements (optional), 7.65/2.83 * or if the specified collection is null 7.65/2.83 * @see #remove(Object) 7.65/2.83 * @see #contains(Object) 7.65/2.83 */ 7.65/2.83 public boolean removeAll(Collection c) { 7.65/2.83 boolean modified = false; 7.65/2.83 7.65/2.83 if (size() > c.size()) { 7.65/2.83 for (Iterator i = c.iterator(); i.hasNext(); ) 7.65/2.83 modified |= remove(i.next()); 7.65/2.83 } else { 7.65/2.83 for (Iterator i = iterator(); i.hasNext(); ) { 7.65/2.83 if (c.contains(i.next())) { 7.65/2.83 i.remove(); 7.65/2.83 modified = true; 7.65/2.83 } 7.65/2.83 } 7.65/2.83 } 7.65/2.83 return modified; 7.65/2.83 } 7.65/2.83 7.65/2.83 } 7.65/2.83 7.65/2.83 7.65/2.83 /* 7.65/2.83 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 7.65/2.83 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.65/2.83 * 7.65/2.83 * This code is free software; you can redistribute it and/or modify it 7.65/2.83 * under the terms of the GNU General Public License version 2 only, as 7.65/2.83 * published by the Free Software Foundation. Sun designates this 7.65/2.83 * particular file as subject to the "Classpath" exception as provided 7.65/2.83 * by Sun in the LICENSE file that accompanied this code. 7.65/2.83 * 7.65/2.83 * This code is distributed in the hope that it will be useful, but WITHOUT 7.65/2.83 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.65/2.83 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.65/2.83 * version 2 for more details (a copy is included in the LICENSE file that 7.65/2.83 * accompanied this code). 7.65/2.83 * 7.65/2.83 * You should have received a copy of the GNU General Public License version 7.65/2.83 * 2 along with this work; if not, write to the Free Software Foundation, 7.65/2.83 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.65/2.83 * 7.65/2.83 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 7.65/2.83 * CA 95054 USA or visit www.sun.com if you need additional information or 7.65/2.83 * have any questions. 7.65/2.83 */ 7.65/2.83 7.65/2.83 package javaUtilEx; 7.65/2.83 7.65/2.83 /** 7.65/2.83 * The root interface in the collection hierarchy. A collection 7.65/2.83 * represents a group of objects, known as its elements. Some 7.65/2.83 * collections allow duplicate elements and others do not. Some are ordered 7.65/2.83 * and others unordered. The JDK does not provide any direct 7.65/2.83 * implementations of this interface: it provides implementations of more 7.65/2.83 * specific subinterfaces like Set and List. This interface 7.65/2.83 * is typically used to pass collections around and manipulate them where 7.65/2.83 * maximum generality is desired. 7.65/2.83 * 7.65/2.83 *

Bags or multisets (unordered collections that may contain 7.65/2.83 * duplicate elements) should implement this interface directly. 7.65/2.83 * 7.65/2.83 *

All general-purpose Collection implementation classes (which 7.65/2.83 * typically implement Collection indirectly through one of its 7.65/2.83 * subinterfaces) should provide two "standard" constructors: a void (no 7.65/2.83 * arguments) constructor, which creates an empty collection, and a 7.65/2.83 * constructor with a single argument of type Collection, which 7.65/2.83 * creates a new collection with the same elements as its argument. In 7.65/2.83 * effect, the latter constructor allows the user to copy any collection, 7.65/2.83 * producing an equivalent collection of the desired implementation type. 7.65/2.83 * There is no way to enforce this convention (as interfaces cannot contain 7.65/2.83 * constructors) but all of the general-purpose Collection 7.65/2.83 * implementations in the Java platform libraries comply. 7.65/2.83 * 7.65/2.83 *

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

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

It is up to each collection to determine its own synchronization 7.65/2.83 * policy. In the absence of a stronger guarantee by the 7.65/2.83 * implementation, undefined behavior may result from the invocation 7.65/2.83 * of any method on a collection that is being mutated by another 7.65/2.83 * thread; this includes direct invocations, passing the collection to 7.65/2.83 * a method that might perform invocations, and using an existing 7.65/2.83 * iterator to examine the collection. 7.65/2.83 * 7.65/2.83 *

Many methods in Collections Framework interfaces are defined in 7.65/2.83 * terms of the {@link Object#equals(Object) equals} method. For example, 7.65/2.83 * the specification for the {@link #contains(Object) contains(Object o)} 7.65/2.83 * method says: "returns true if and only if this collection 7.65/2.83 * contains at least one element e such that 7.65/2.83 * (o==null ? e==null : o.equals(e))." This specification should 7.65/2.83 * not be construed to imply that invoking Collection.contains 7.65/2.83 * with a non-null argument o will cause o.equals(e) to be 7.65/2.83 * invoked for any element e. Implementations are free to implement 7.65/2.83 * optimizations whereby the equals invocation is avoided, for 7.65/2.83 * example, by first comparing the hash codes of the two elements. (The 7.65/2.83 * {@link Object#hashCode()} specification guarantees that two objects with 7.65/2.83 * unequal hash codes cannot be equal.) More generally, implementations of 7.65/2.83 * the various Collections Framework interfaces are free to take advantage of 7.65/2.83 * the specified behavior of underlying {@link Object} methods wherever the 7.65/2.83 * implementor deems it appropriate. 7.65/2.83 * 7.65/2.83 *

This interface is a member of the 7.65/2.83 * 7.65/2.83 * Java Collections Framework. 7.65/2.83 * 7.65/2.83 * @author Josh Bloch 7.65/2.83 * @author Neal Gafter 7.65/2.83 * @see Set 7.65/2.83 * @see List 7.65/2.83 * @see Map 7.65/2.83 * @see SortedSet 7.65/2.83 * @see SortedMap 7.65/2.83 * @see HashSet 7.65/2.83 * @see TreeSet 7.65/2.83 * @see ArrayList 7.65/2.83 * @see LinkedList 7.65/2.83 * @see Vector 7.65/2.83 * @see Collections 7.65/2.83 * @see Arrays 7.65/2.83 * @see AbstractCollection 7.65/2.83 * @since 1.2 7.65/2.83 */ 7.65/2.83 7.65/2.83 public interface Collection { 7.65/2.83 // Query Operations 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Returns the number of elements in this collection. If this collection 7.65/2.83 * contains more than Integer.MAX_VALUE elements, returns 7.65/2.83 * Integer.MAX_VALUE. 7.65/2.83 * 7.65/2.83 * @return the number of elements in this collection 7.65/2.83 */ 7.65/2.83 int size(); 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Returns true if this collection contains no elements. 7.65/2.83 * 7.65/2.83 * @return true if this collection contains no elements 7.65/2.83 */ 7.65/2.83 boolean isEmpty(); 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Returns true if this collection contains the specified element. 7.65/2.83 * More formally, returns true if and only if this collection 7.65/2.83 * contains at least one element e such that 7.65/2.83 * (o==null ? e==null : o.equals(e)). 7.65/2.83 * 7.65/2.83 * @param o element whose presence in this collection is to be tested 7.65/2.83 * @return true if this collection contains the specified 7.65/2.83 * element 7.65/2.83 * @throws ClassCastException if the type of the specified element 7.65/2.83 * is incompatible with this collection (optional) 7.65/2.83 * @throws NullPointerException if the specified element is null and this 7.65/2.83 * collection does not permit null elements (optional) 7.65/2.83 */ 7.65/2.83 boolean contains(Object o); 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Returns an iterator over the elements in this collection. There are no 7.65/2.83 * guarantees concerning the order in which the elements are returned 7.65/2.83 * (unless this collection is an instance of some class that provides a 7.65/2.83 * guarantee). 7.65/2.83 * 7.65/2.83 * @return an Iterator over the elements in this collection 7.65/2.83 */ 7.65/2.83 Iterator iterator(); 7.65/2.83 7.65/2.83 // Modification Operations 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Ensures that this collection contains the specified element (optional 7.65/2.83 * operation). Returns true if this collection changed as a 7.65/2.83 * result of the call. (Returns false if this collection does 7.65/2.83 * not permit duplicates and already contains the specified element.)

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

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

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

7.65/2.83 * 7.65/2.83 * The general contract for the Object.equals method states that 7.65/2.83 * equals must be symmetric (in other words, a.equals(b) if and 7.65/2.83 * only if b.equals(a)). The contracts for List.equals 7.65/2.83 * and Set.equals state that lists are only equal to other lists, 7.65/2.83 * and sets to other sets. Thus, a custom equals method for a 7.65/2.83 * collection class that implements neither the List nor 7.65/2.83 * Set interface must return false when this collection 7.65/2.83 * is compared to any list or set. (By the same logic, it is not possible 7.65/2.83 * to write a class that correctly implements both the Set and 7.65/2.83 * List interfaces.) 7.65/2.83 * 7.65/2.83 * @param o object to be compared for equality with this collection 7.65/2.83 * @return true if the specified object is equal to this 7.65/2.83 * collection 7.65/2.83 * 7.65/2.83 * @see Object#equals(Object) 7.65/2.83 * @see Set#equals(Object) 7.65/2.83 * @see List#equals(Object) 7.65/2.83 */ 7.65/2.83 boolean equals(Object o); 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Returns the hash code value for this collection. While the 7.65/2.83 * Collection interface adds no stipulations to the general 7.65/2.83 * contract for the Object.hashCode method, programmers should 7.65/2.83 * take note that any class that overrides the Object.equals 7.65/2.83 * method must also override the Object.hashCode method in order 7.65/2.83 * to satisfy the general contract for the Object.hashCodemethod. 7.65/2.83 * In particular, c1.equals(c2) implies that 7.65/2.83 * c1.hashCode()==c2.hashCode(). 7.65/2.83 * 7.65/2.83 * @return the hash code value for this collection 7.65/2.83 * 7.65/2.83 * @see Object#hashCode() 7.65/2.83 * @see Object#equals(Object) 7.65/2.83 */ 7.65/2.83 int hashCode(); 7.65/2.83 } 7.65/2.83 7.65/2.83 7.65/2.83 /* 7.65/2.83 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 7.65/2.83 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.65/2.83 * 7.65/2.83 * This code is free software; you can redistribute it and/or modify it 7.65/2.83 * under the terms of the GNU General Public License version 2 only, as 7.65/2.83 * published by the Free Software Foundation. Sun designates this 7.65/2.83 * particular file as subject to the "Classpath" exception as provided 7.65/2.83 * by Sun in the LICENSE file that accompanied this code. 7.65/2.83 * 7.65/2.83 * This code is distributed in the hope that it will be useful, but WITHOUT 7.65/2.83 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.65/2.83 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.65/2.83 * version 2 for more details (a copy is included in the LICENSE file that 7.65/2.83 * accompanied this code). 7.65/2.83 * 7.65/2.83 * You should have received a copy of the GNU General Public License version 7.65/2.83 * 2 along with this work; if not, write to the Free Software Foundation, 7.65/2.83 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.65/2.83 * 7.65/2.83 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 7.65/2.83 * CA 95054 USA or visit www.sun.com if you need additional information or 7.65/2.83 * have any questions. 7.65/2.83 */ 7.65/2.83 7.65/2.83 package javaUtilEx; 7.65/2.83 7.65/2.83 /** 7.65/2.83 * This exception may be thrown by methods that have detected concurrent 7.65/2.83 * modification of an object when such modification is not permissible. 7.65/2.83 *

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

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

Note that fail-fast behavior cannot be guaranteed as it is, generally 7.65/2.83 * speaking, impossible to make any hard guarantees in the presence of 7.65/2.83 * unsynchronized concurrent modification. Fail-fast operations 7.65/2.83 * throw ConcurrentModificationException on a best-effort basis. 7.65/2.83 * Therefore, it would be wrong to write a program that depended on this 7.65/2.83 * exception for its correctness: ConcurrentModificationException 7.65/2.83 * should be used only to detect bugs. 7.65/2.83 * 7.65/2.83 * @author Josh Bloch 7.65/2.83 * @see Collection 7.65/2.83 * @see Iterator 7.65/2.83 * @see ListIterator 7.65/2.83 * @see Vector 7.65/2.83 * @see LinkedList 7.65/2.83 * @see HashSet 7.65/2.83 * @see Hashtable 7.65/2.83 * @see TreeMap 7.65/2.83 * @see AbstractList 7.65/2.83 * @since 1.2 7.65/2.83 */ 7.65/2.83 public class ConcurrentModificationException extends RuntimeException { 7.65/2.83 /** 7.65/2.83 * Constructs a ConcurrentModificationException with no 7.65/2.83 * detail message. 7.65/2.83 */ 7.65/2.83 public ConcurrentModificationException() { 7.65/2.83 } 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Constructs a ConcurrentModificationException with the 7.65/2.83 * specified detail message. 7.65/2.83 * 7.65/2.83 * @param message the detail message pertaining to this exception. 7.65/2.83 */ 7.65/2.83 public ConcurrentModificationException(String message) { 7.65/2.83 super(message); 7.65/2.83 } 7.65/2.83 } 7.65/2.83 7.65/2.83 7.65/2.83 /* 7.65/2.83 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. 7.65/2.83 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.65/2.83 * 7.65/2.83 * This code is free software; you can redistribute it and/or modify it 7.65/2.83 * under the terms of the GNU General Public License version 2 only, as 7.65/2.83 * published by the Free Software Foundation. Sun designates this 7.65/2.83 * particular file as subject to the "Classpath" exception as provided 7.65/2.83 * by Sun in the LICENSE file that accompanied this code. 7.65/2.83 * 7.65/2.83 * This code is distributed in the hope that it will be useful, but WITHOUT 7.65/2.83 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.65/2.83 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.65/2.83 * version 2 for more details (a copy is included in the LICENSE file that 7.65/2.83 * accompanied this code). 7.65/2.83 * 7.65/2.83 * You should have received a copy of the GNU General Public License version 7.65/2.83 * 2 along with this work; if not, write to the Free Software Foundation, 7.65/2.83 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.65/2.83 * 7.65/2.83 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 7.65/2.83 * CA 95054 USA or visit www.sun.com if you need additional information or 7.65/2.83 * have any questions. 7.65/2.83 */ 7.65/2.83 7.65/2.83 package javaUtilEx; 7.65/2.83 7.65/2.83 /** 7.65/2.83 * Hash table based implementation of the Map interface. This 7.65/2.83 * implementation provides all of the optional map operations, and permits 7.65/2.83 * null values and the null key. (The HashMap 7.65/2.83 * class is roughly equivalent to Hashtable, except that it is 7.65/2.83 * unsynchronized and permits nulls.) This class makes no guarantees as to 7.65/2.83 * the order of the map; in particular, it does not guarantee that the order 7.65/2.83 * will remain constant over time. 7.65/2.83 * 7.65/2.83 *

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

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

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

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

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

7.65/2.83	 *   Map m = Collections.synchronizedMap(new HashMap(...));
7.65/2.83 * 7.65/2.83 *

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

Note that the fail-fast behavior of an iterator cannot be guaranteed 7.65/2.83 * as it is, generally speaking, impossible to make any hard guarantees in the 7.65/2.83 * presence of unsynchronized concurrent modification. Fail-fast iterators 7.65/2.83 * throw ConcurrentModificationException on a best-effort basis. 7.65/2.83 * Therefore, it would be wrong to write a program that depended on this 7.65/2.83 * exception for its correctness: the fail-fast behavior of iterators 7.65/2.83 * should be used only to detect bugs. 7.65/2.83 * 7.65/2.83 *

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

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

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

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

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

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

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

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

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

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

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

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

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

This interface is a member of the 7.65/2.84 * 7.65/2.84 * Java Collections Framework. 7.65/2.84 * 7.65/2.84 *

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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