MCPcopy Create free account
hub / github.com/davidgiven/luje / put

Method put

lib/java/util/Hashtable.java:731–762  ·  view source on GitHub ↗

Associate the specified value with the specified key in this Hashtable. If the key already exists, the old value is replaced. The key and value cannot be null. @param key the key to add. @param value the value to add. @return the old value associated with the specified

(K key, V value)

Source from the content-addressed store, hash-verified

729 * @see java.lang.Object#equals
730 */
731 @Override
732 public synchronized V put(K key, V value) {
733 if (key != null && value != null) {
734 int hash = key.hashCode();
735 int index = (hash & 0x7FFFFFFF) % elementData.length;
736 Entry<K, V> entry = elementData[index];
737 while (entry != null && !entry.equalsKey(key, hash)) {
738 entry = entry.next;
739 }
740 if (entry == null) {
741 modCount++;
742 if (++elementCount > threshold) {
743 rehash();
744 index = (hash & 0x7FFFFFFF) % elementData.length;
745 }
746 if (index < firstSlot) {
747 firstSlot = index;
748 }
749 if (index > lastSlot) {
750 lastSlot = index;
751 }
752 entry = newEntry(key, value, hash);
753 entry.next = elementData[index];
754 elementData[index] = entry;
755 return null;
756 }
757 V result = entry.value;
758 entry.value = value;
759 return result;
760 }
761 throw new NullPointerException();
762 }
763
764 /**
765 * Copies every mapping to this {@code Hashtable} from the specified map.

Callers 1

putAllMethod · 0.95

Calls 4

rehashMethod · 0.95
newEntryMethod · 0.95
equalsKeyMethod · 0.80
hashCodeMethod · 0.65

Tested by

no test coverage detected