equal
deleted
inserted
replaced
138 * @throws NullPointerException if <tt>m</tt> is null |
138 * @throws NullPointerException if <tt>m</tt> is null |
139 */ |
139 */ |
140 public EnumMap(EnumMap<K, ? extends V> m) { |
140 public EnumMap(EnumMap<K, ? extends V> m) { |
141 keyType = m.keyType; |
141 keyType = m.keyType; |
142 keyUniverse = m.keyUniverse; |
142 keyUniverse = m.keyUniverse; |
143 vals = (Object[]) m.vals.clone(); |
143 vals = m.vals.clone(); |
144 size = m.size; |
144 size = m.size; |
145 } |
145 } |
146 |
146 |
147 /** |
147 /** |
148 * Creates an enum map initialized from the specified map. If the |
148 * Creates an enum map initialized from the specified map. If the |
159 public EnumMap(Map<K, ? extends V> m) { |
159 public EnumMap(Map<K, ? extends V> m) { |
160 if (m instanceof EnumMap) { |
160 if (m instanceof EnumMap) { |
161 EnumMap<K, ? extends V> em = (EnumMap<K, ? extends V>) m; |
161 EnumMap<K, ? extends V> em = (EnumMap<K, ? extends V>) m; |
162 keyType = em.keyType; |
162 keyType = em.keyType; |
163 keyUniverse = em.keyUniverse; |
163 keyUniverse = em.keyUniverse; |
164 vals = (Object[]) em.vals.clone(); |
164 vals = em.vals.clone(); |
165 size = em.size; |
165 size = em.size; |
166 } else { |
166 } else { |
167 if (m.isEmpty()) |
167 if (m.isEmpty()) |
168 throw new IllegalArgumentException("Specified map is empty"); |
168 throw new IllegalArgumentException("Specified map is empty"); |
169 keyType = m.keySet().iterator().next().getDeclaringClass(); |
169 keyType = m.keySet().iterator().next().getDeclaringClass(); |
255 * @throws NullPointerException if the specified key is null |
255 * @throws NullPointerException if the specified key is null |
256 */ |
256 */ |
257 public V put(K key, V value) { |
257 public V put(K key, V value) { |
258 typeCheck(key); |
258 typeCheck(key); |
259 |
259 |
260 int index = ((Enum)key).ordinal(); |
260 int index = key.ordinal(); |
261 Object oldValue = vals[index]; |
261 Object oldValue = vals[index]; |
262 vals[index] = maskNull(value); |
262 vals[index] = maskNull(value); |
263 if (oldValue == null) |
263 if (oldValue == null) |
264 size++; |
264 size++; |
265 return unmaskNull(oldValue); |
265 return unmaskNull(oldValue); |
660 try { |
660 try { |
661 result = (EnumMap<K, V>) super.clone(); |
661 result = (EnumMap<K, V>) super.clone(); |
662 } catch(CloneNotSupportedException e) { |
662 } catch(CloneNotSupportedException e) { |
663 throw new AssertionError(); |
663 throw new AssertionError(); |
664 } |
664 } |
665 result.vals = (Object[]) result.vals.clone(); |
665 result.vals = result.vals.clone(); |
666 return result; |
666 return result; |
667 } |
667 } |
668 |
668 |
669 /** |
669 /** |
670 * Throws an exception if e is not of the correct type for this enum set. |
670 * Throws an exception if e is not of the correct type for this enum set. |