350 } else {
351 super.putAll(m);
352 }
353 }
354
355 /**
356 * Removes all mappings from this map.
357 */
358 public void clear() {
359 Arrays.fill(vals, null);
360 size = 0;
361 }
362
363 // Views
364
365 /**
366 * This field is initialized to contain an instance of the entry set
367 * view the first time this view is requested. The view is stateless,
368 * so there's no reason to create more than one.
369 */
370 private transient Set<Map.Entry<K,V>> entrySet = null;
371
372 /**
373 * Returns a {@link Set} view of the keys contained in this map.
374 * The returned set obeys the general contract outlined in
375 * {@link Map#keySet()}. The set's iterator will return the keys
376 * in their natural order (the order in which the enum constants
377 * are declared).
378 *
379 * @return a set view of the keys contained in this enum map
380 */
381 public Set<K> keySet() {
382 Set<K> ks = keySet;
383 if (ks != null)
384 return ks;
385 else
386 return keySet = new KeySet();
387 }
388
389 private class KeySet extends AbstractSet<K> {
390 public Iterator<K> iterator() {
545
546 private class KeyIterator extends EnumMapIterator<K> {
547 public K next() {
548 if (!hasNext())
549 throw new NoSuchElementException();
550 lastReturnedIndex = index++;
551 return keyUniverse[lastReturnedIndex];
552 }
553 }
554
555 private class ValueIterator extends EnumMapIterator<V> {
556 public V next() {
557 if (!hasNext())
558 throw new NoSuchElementException();
559 lastReturnedIndex = index++;
560 return unmaskNull(vals[lastReturnedIndex]);
561 }
562 }
563
564 private class EntryIterator extends EnumMapIterator<Map.Entry<K,V>> {
565 private Entry lastReturnedEntry = null;
566
567 public Map.Entry<K,V> next() {
568 if (!hasNext())
569 throw new NoSuchElementException();
570 lastReturnedEntry = new Entry(index++);
571 return lastReturnedEntry;
572 }
573
574 public void remove() {
575 lastReturnedIndex =
576 ((null == lastReturnedEntry) ? -1 : lastReturnedEntry.index);
577 super.remove();
578 lastReturnedEntry.index = lastReturnedIndex;
579 lastReturnedEntry = null;
580 }
581
582 private class Entry implements Map.Entry<K,V> {
583 private int index;
584
585 private Entry(int index) {
|
350 } else {
351 super.putAll(m);
352 }
353 }
354
355 /**
356 * Removes all mappings from this map.
357 */
358 public void clear() {
359 Arrays.fill(vals, null);
360 size = 0;
361 }
362
363 // Views
364
365 /**
366 * This field is initialized to contain an instance of the entry set
367 * view the first time this view is requested. The view is stateless,
368 * so there's no reason to create more than one.
369 */
370 private transient Set<Map.Entry<K,V>> entrySet;
371
372 /**
373 * Returns a {@link Set} view of the keys contained in this map.
374 * The returned set obeys the general contract outlined in
375 * {@link Map#keySet()}. The set's iterator will return the keys
376 * in their natural order (the order in which the enum constants
377 * are declared).
378 *
379 * @return a set view of the keys contained in this enum map
380 */
381 public Set<K> keySet() {
382 Set<K> ks = keySet;
383 if (ks != null)
384 return ks;
385 else
386 return keySet = new KeySet();
387 }
388
389 private class KeySet extends AbstractSet<K> {
390 public Iterator<K> iterator() {
545
546 private class KeyIterator extends EnumMapIterator<K> {
547 public K next() {
548 if (!hasNext())
549 throw new NoSuchElementException();
550 lastReturnedIndex = index++;
551 return keyUniverse[lastReturnedIndex];
552 }
553 }
554
555 private class ValueIterator extends EnumMapIterator<V> {
556 public V next() {
557 if (!hasNext())
558 throw new NoSuchElementException();
559 lastReturnedIndex = index++;
560 return unmaskNull(vals[lastReturnedIndex]);
561 }
562 }
563
564 private class EntryIterator extends EnumMapIterator<Map.Entry<K,V>> {
565 private Entry lastReturnedEntry;
566
567 public Map.Entry<K,V> next() {
568 if (!hasNext())
569 throw new NoSuchElementException();
570 lastReturnedEntry = new Entry(index++);
571 return lastReturnedEntry;
572 }
573
574 public void remove() {
575 lastReturnedIndex =
576 ((null == lastReturnedEntry) ? -1 : lastReturnedEntry.index);
577 super.remove();
578 lastReturnedEntry.index = lastReturnedIndex;
579 lastReturnedEntry = null;
580 }
581
582 private class Entry implements Map.Entry<K,V> {
583 private int index;
584
585 private Entry(int index) {
|