|
16 | 16 | import java.util.Enumeration; |
17 | 17 | import java.util.List; |
18 | 18 | import java.util.NoSuchElementException; |
| 19 | +import java.util.Objects; |
19 | 20 |
|
20 | 21 | import org.eclipse.core.runtime.Assert; |
21 | 22 | import org.eclipse.core.runtime.ListenerList; |
@@ -585,19 +586,6 @@ public boolean containsKey(Object key) { |
585 | 586 | return getEntry(key) != null; |
586 | 587 | } |
587 | 588 |
|
588 | | - /** |
589 | | - * Answers an Enumeration on the values of this Hashtable. The results of the Enumeration may be |
590 | | - * affected if the contents of this Hashtable are modified. |
591 | | - * |
592 | | - * @return an Enumeration of the values of this Hashtable |
593 | | - */ |
594 | | - public Enumeration<?> elements() { |
595 | | - if (elementCount == 0) { |
596 | | - return EMPTY_ENUMERATOR; |
597 | | - } |
598 | | - return new HashEnumerator(false); |
599 | | - } |
600 | | - |
601 | 589 | /** |
602 | 590 | * Answers the value associated with the specified key in this Hashtable. |
603 | 591 | * |
@@ -673,36 +661,35 @@ public Enumeration<Object> keys() { |
673 | 661 | * @return the old value associated with the specified key, null if the key did not exist |
674 | 662 | */ |
675 | 663 | public Object put(Object key, Object value) { |
676 | | - if (key != null && value != null) { |
677 | | - int index = (hashCode(key) & 0x7F_FFF_FFF) % elementData.length; |
678 | | - HashMapEntry entry = elementData[index]; |
679 | | - while (entry != null && !keyEquals(key, entry.key)) { |
680 | | - entry = entry.next; |
| 664 | + Objects.requireNonNull(key); |
| 665 | + Objects.requireNonNull(value); |
| 666 | + int index = (hashCode(key) & 0x7F_FFF_FFF) % elementData.length; |
| 667 | + HashMapEntry entry = elementData[index]; |
| 668 | + while (entry != null && !keyEquals(key, entry.key)) { |
| 669 | + entry = entry.next; |
| 670 | + } |
| 671 | + if (entry == null) { |
| 672 | + if (++elementCount > threshold) { |
| 673 | + rehash(); |
| 674 | + index = (hashCode(key) & 0x7F_FFF_FFF) % elementData.length; |
681 | 675 | } |
682 | | - if (entry == null) { |
683 | | - if (++elementCount > threshold) { |
684 | | - rehash(); |
685 | | - index = (hashCode(key) & 0x7F_FFF_FFF) % elementData.length; |
686 | | - } |
687 | | - if (index < firstSlot) { |
688 | | - firstSlot = index; |
689 | | - } |
690 | | - if (index > lastSlot) { |
691 | | - lastSlot = index; |
692 | | - } |
693 | | - entry = new HashMapEntry(key, value); |
694 | | - entry.next = elementData[index]; |
695 | | - elementData[index] = entry; |
696 | | - return null; |
| 676 | + if (index < firstSlot) { |
| 677 | + firstSlot = index; |
| 678 | + } |
| 679 | + if (index > lastSlot) { |
| 680 | + lastSlot = index; |
697 | 681 | } |
698 | | - Object result = entry.value; |
699 | | - entry.key = key; |
700 | | - // important to avoid hanging onto keys that |
701 | | - // are equal but "old" -- see bug 30607 |
702 | | - entry.value = value; |
703 | | - return result; |
| 682 | + entry = new HashMapEntry(key, value); |
| 683 | + entry.next = elementData[index]; |
| 684 | + elementData[index] = entry; |
| 685 | + return null; |
704 | 686 | } |
705 | | - throw new NullPointerException(); |
| 687 | + Object result = entry.value; |
| 688 | + entry.key = key; |
| 689 | + // important to avoid hanging onto keys that |
| 690 | + // are equal but "old" -- see bug 30607 |
| 691 | + entry.value = value; |
| 692 | + return result; |
706 | 693 | } |
707 | 694 |
|
708 | 695 | /** |
|
0 commit comments