3909N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * A specialized {@link Map} implementation for use with enum type keys. All 0N/A * of the keys in an enum map must come from a single enum type that is 0N/A * specified, explicitly or implicitly, when the map is created. Enum maps 0N/A * are represented internally as arrays. This representation is extremely 0N/A * compact and efficient. 0N/A * <p>Enum maps are maintained in the <i>natural order</i> of their keys 0N/A * (the order in which the enum constants are declared). This is reflected 0N/A * in the iterators returned by the collections views ({@link #keySet()}, 0N/A * {@link #entrySet()}, and {@link #values()}). 0N/A * <p>Iterators returned by the collection views are <i>weakly consistent</i>: 0N/A * they will never throw {@link ConcurrentModificationException} and they may 0N/A * or may not show the effects of any modifications to the map that occur while 0N/A * the iteration is in progress. 0N/A * <p>Null keys are not permitted. Attempts to insert a null key will 0N/A * throw {@link NullPointerException}. Attempts to test for the 0N/A * presence of a null key or to remove one will, however, function properly. 0N/A * Null values are permitted. 0N/A * <P>Like most collection implementations <tt>EnumMap</tt> is not 0N/A * synchronized. If multiple threads access an enum map concurrently, and at 0N/A * least one of the threads modifies the map, it should be synchronized 0N/A * externally. This is typically accomplished by synchronizing on some 0N/A * object that naturally encapsulates the enum map. If no such object exists, 0N/A * the map should be "wrapped" using the {@link Collections#synchronizedMap} 0N/A * method. This is best done at creation time, to prevent accidental 0N/A * unsynchronized access: 0N/A * Map<EnumKey, V> m 0N/A * = Collections.synchronizedMap(new EnumMap<EnumKey, V>(...)); 0N/A * <p>Implementation note: All basic operations execute in constant time. 0N/A * They are likely (though not guaranteed) to be faster than their 0N/A * {@link HashMap} counterparts. 0N/A * <p>This class is a member of the 0N/A * Java Collections Framework</a>. 0N/A * @author Josh Bloch 0N/A * The <tt>Class</tt> object for the enum type of all the keys of this map. 0N/A * All of the values comprising K. (Cached for performance.) 0N/A * Array representation of this map. The ith element is the value 0N/A * to which universe[i] is currently mapped, or null if it isn't 0N/A * mapped to anything, or NULL if it's mapped to null. 0N/A * The number of mappings in this map. 0N/A * Distinguished non-null value for representing null values. 4625N/A return "java.util.EnumMap.NULL";
0N/A * Creates an empty enum map with the specified key type. 0N/A * @param keyType the class object of the key type for this enum map 0N/A * @throws NullPointerException if <tt>keyType</tt> is null 0N/A * Creates an enum map with the same key type as the specified enum 0N/A * map, initially containing the same mappings (if any). 0N/A * @param m the enum map from which to initialize this enum map 0N/A * @throws NullPointerException if <tt>m</tt> is null 0N/A * Creates an enum map initialized from the specified map. If the 0N/A * specified map is an <tt>EnumMap</tt> instance, this constructor behaves 0N/A * identically to {@link #EnumMap(EnumMap)}. Otherwise, the specified map 0N/A * must contain at least one mapping (in order to determine the new 0N/A * enum map's key type). 0N/A * @param m the map from which to initialize this enum map 0N/A * @throws IllegalArgumentException if <tt>m</tt> is not an 0N/A * <tt>EnumMap</tt> instance and contains no mappings 0N/A * @throws NullPointerException if <tt>m</tt> is null 0N/A * Returns the number of key-value mappings in this map. 0N/A * @return the number of key-value mappings in this map 0N/A * Returns <tt>true</tt> if this map maps one or more keys to the 0N/A * @param value the value whose presence in this map is to be tested 0N/A * @return <tt>true</tt> if this map maps one or more keys to this value 0N/A * Returns <tt>true</tt> if this map contains a mapping for the specified 0N/A * @param key the key whose presence in this map is to be tested 0N/A * @return <tt>true</tt> if this map contains a mapping for the specified 0N/A * Returns the value to which the specified key is mapped, 0N/A * or {@code null} if this map contains no mapping for the key. 0N/A * <p>More formally, if this map contains a mapping from a key 0N/A * {@code k} to a value {@code v} such that {@code (key == k)}, 0N/A * then this method returns {@code v}; otherwise it returns 0N/A * {@code null}. (There can be at most one such mapping.) 0N/A * <p>A return value of {@code null} does not <i>necessarily</i> 0N/A * indicate that the map contains no mapping for the key; it's also 0N/A * possible that the map explicitly maps the key to {@code null}. 0N/A * The {@link #containsKey containsKey} operation may be used to 0N/A * distinguish these two cases. 0N/A // Modification Operations 0N/A * Associates the specified value with the specified key in this map. 0N/A * If the map previously contained a mapping for this key, the old 0N/A * value is replaced. 0N/A * @param key the key with which the specified value is to be associated 0N/A * @param value the value to be associated with the specified key 0N/A * @return the previous value associated with specified key, or 0N/A * <tt>null</tt> if there was no mapping for key. (A <tt>null</tt> 0N/A * return can also indicate that the map previously associated 0N/A * <tt>null</tt> with the specified key.) 0N/A * @throws NullPointerException if the specified key is null 0N/A * Removes the mapping for this key from this map if present. 0N/A * @param key the key whose mapping is to be removed from the map 0N/A * @return the previous value associated with specified key, or 0N/A * <tt>null</tt> if there was no entry for key. (A <tt>null</tt> 0N/A * return can also indicate that the map previously associated 0N/A * <tt>null</tt> with the specified key.) 0N/A * Returns true if key is of the proper type to be a key in this 0N/A // Cheaper than instanceof Enum followed by getDeclaringClass 0N/A * Copies all of the mappings from the specified map to this map. 0N/A * These mappings will replace any mappings that this map had for 0N/A * any of the keys currently in the specified map. 0N/A * @param m the mappings to be stored in this map 0N/A * @throws NullPointerException the specified map is null, or if 0N/A * one or more keys in the specified map are null 0N/A * Removes all mappings from this map. 0N/A * This field is initialized to contain an instance of the entry set 0N/A * view the first time this view is requested. The view is stateless, 0N/A * so there's no reason to create more than one. 0N/A * Returns a {@link Set} view of the keys contained in this map. 0N/A * The returned set obeys the general contract outlined in 0N/A * {@link Map#keySet()}. The set's iterator will return the keys 0N/A * in their natural order (the order in which the enum constants 0N/A * @return a set view of the keys contained in this enum map 0N/A * Returns a {@link Collection} view of the values contained in this map. 0N/A * The returned collection obeys the general contract outlined in 0N/A * {@link Map#values()}. The collection's iterator will return the 0N/A * values in the order their corresponding keys appear in map, 0N/A * which is their natural order (the order in which the enum constants 0N/A * @return a collection view of the values contained in this map 0N/A * Returns a {@link Set} view of the mappings contained in this map. 0N/A * The returned set obeys the general contract outlined in 0N/A * {@link Map#keySet()}. The set's iterator will return the 0N/A * mappings in the order their keys appear in map, which is their 0N/A * natural order (the order in which the enum constants are declared). 0N/A * @return a set view of the mappings contained in this enum map 0N/A // Lower bound on index of next element to return 0N/A // Index of last returned element, or -1 if none 0N/A // Comparison and hashing 0N/A * Compares the specified object with this map for equality. Returns 0N/A * <tt>true</tt> if the given object is also a map and the two maps 0N/A * represent the same mappings, as specified in the {@link 0N/A * Map#equals(Object)} contract. 0N/A * @param o the object to be compared for equality with this map 0N/A * @return <tt>true</tt> if the specified object is equal to this map 0N/A // Key types match, compare each value 3977N/A * Returns the hash code value for this map. The hash code of a map is 3977N/A * defined to be the sum of the hash codes of each entry in the map. 0N/A * Returns a shallow copy of this enum map. (The values themselves 0N/A * @return a shallow copy of this enum map 0N/A * Throws an exception if e is not of the correct type for this enum set. 0N/A * Returns all of the values comprising K. 0N/A * The result is uncloned, cached, and shared by all callers. 0N/A * Save the state of the <tt>EnumMap</tt> instance to a stream (i.e., 0N/A * @serialData The <i>size</i> of the enum map (the number of key-value 0N/A * mappings) is emitted (int), followed by the key (Object) 0N/A * and value (Object) for each key-value mapping represented 0N/A // Write out the key type and any hidden stuff 0N/A // Write out size (number of Mappings) 0N/A // Write out keys and values (alternating) 0N/A * Reconstitute the <tt>EnumMap</tt> instance from a stream (i.e., 0N/A // Read in the key type and any hidden stuff 0N/A // Read in size (number of Mappings) 0N/A // Read the keys and values, and put the mappings in the HashMap