public void remove() { checkLastReturnedIndex(); if (vals[lastReturnedIndex] != null) { vals[lastReturnedIndex] = null; size--; } lastReturnedIndex = -1; }
public void remove() { checkLastReturnedIndex(); if (vals[lastReturnedIndex] != null) { vals[lastReturnedIndex] = null; size--; } lastReturnedIndex = -1; }
/** * Save the state of the <tt>EnumMap</tt> instance to a stream (i.e., * serialize it). * * @serialData The <i>size</i> of the enum map (the number of key-value * mappings) is emitted (int), followed by the key (Object) * and value (Object) for each key-value mapping represented * by the enum map. */ private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { // Write out the key type and any hidden stuff s.defaultWriteObject(); // Write out size (number of Mappings) s.writeInt(size); // Write out keys and values (alternating) int entriesToBeWritten = size; for (int i = 0; entriesToBeWritten > 0; i++) { if (null != vals[i]) { s.writeObject(keyUniverse[i]); s.writeObject(unmaskNull(vals[i])); entriesToBeWritten--; } } }
/** * Save the state of the <tt>EnumMap</tt> instance to a stream (i.e., * serialize it). * * @serialData The <i>size</i> of the enum map (the number of key-value * mappings) is emitted (int), followed by the key (Object) * and value (Object) for each key-value mapping represented * by the enum map. */ private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { // Write out the key type and any hidden stuff s.defaultWriteObject(); // Write out size (number of Mappings) s.writeInt(size); // Write out keys and values (alternating) int entriesToBeWritten = size; for (int i = 0; entriesToBeWritten > 0; i++) { if (null != vals[i]) { s.writeObject(keyUniverse[i]); s.writeObject(unmaskNull(vals[i])); entriesToBeWritten--; } } }
/** * Returns the value to which the specified key is mapped, * or {@code null} if this map contains no mapping for the key. * * <p>More formally, if this map contains a mapping from a key * {@code k} to a value {@code v} such that {@code (key == k)}, * then this method returns {@code v}; otherwise it returns * {@code null}. (There can be at most one such mapping.) * * <p>A return value of {@code null} does not <i>necessarily</i> * indicate that the map contains no mapping for the key; it's also * possible that the map explicitly maps the key to {@code null}. * The {@link #containsKey containsKey} operation may be used to * distinguish these two cases. */ public V get(Object key) { return (isValidKey(key) ? unmaskNull(vals[((Enum)key).ordinal()]) : null); }
/** * Returns the value to which the specified key is mapped, * or {@code null} if this map contains no mapping for the key. * * <p>More formally, if this map contains a mapping from a key * {@code k} to a value {@code v} such that {@code (key == k)}, * then this method returns {@code v}; otherwise it returns * {@code null}. (There can be at most one such mapping.) * * <p>A return value of {@code null} does not <i>necessarily</i> * indicate that the map contains no mapping for the key; it's also * possible that the map explicitly maps the key to {@code null}. * The {@link #containsKey containsKey} operation may be used to * distinguish these two cases. */ public V get(Object key) { return (isValidKey(key) ? unmaskNull(vals[((Enum)key).ordinal()]) : null); }
if (null != vals[i]) { K key = keyUniverse[i]; V value = unmaskNull(vals[i]); if (null == value) { if (!((null == m.get(key)) && m.containsKey(key)))
if (null != vals[i]) { K key = keyUniverse[i]; V value = unmaskNull(vals[i]); if (null == value) { if (!((null == m.get(key)) && m.containsKey(key)))
/** * Associates the specified value with the specified key in this map. * If the map previously contained a mapping for this key, the old * value is replaced. * * @param key the key with which the specified value is to be associated * @param value the value to be associated with the specified key * * @return the previous value associated with specified key, or * <tt>null</tt> if there was no mapping for key. (A <tt>null</tt> * return can also indicate that the map previously associated * <tt>null</tt> with the specified key.) * @throws NullPointerException if the specified key is null */ public V put(K key, V value) { typeCheck(key); int index = key.ordinal(); Object oldValue = vals[index]; vals[index] = maskNull(value); if (oldValue == null) size++; return unmaskNull(oldValue); }
/** * Associates the specified value with the specified key in this map. * If the map previously contained a mapping for this key, the old * value is replaced. * * @param key the key with which the specified value is to be associated * @param value the value to be associated with the specified key * * @return the previous value associated with specified key, or * <tt>null</tt> if there was no mapping for key. (A <tt>null</tt> * return can also indicate that the map previously associated * <tt>null</tt> with the specified key.) * @throws NullPointerException if the specified key is null */ public V put(K key, V value) { typeCheck(key); int index = key.ordinal(); Object oldValue = vals[index]; vals[index] = maskNull(value); if (oldValue == null) size++; return unmaskNull(oldValue); }