MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / putImpl

Method putImpl

vm/JavaAPI/src/java/util/LinkedHashMap.java:377–416  ·  view source on GitHub ↗
(K key, V value)

Source from the content-addressed store, hash-verified

375 }
376
377 V putImpl(K key, V value) {
378 LinkedHashMapEntry<K, V> m;
379 if (elementCount == 0) {
380 head = tail = null;
381 }
382 if (key == null) {
383 m = (LinkedHashMapEntry<K, V>) findNullKeyEntry();
384 if (m == null) {
385 modCount++;
386 // Check if we need to remove the oldest entry. The check
387 // includes accessOrder since an accessOrder LinkedHashMap does
388 // not record the oldest member in 'head'.
389 if (++elementCount > threshold) {
390 rehash();
391 }
392 m = (LinkedHashMapEntry<K, V>) createHashedEntry(null, 0, 0);
393 } else {
394 linkEntry(m);
395 }
396 } else {
397 int hash = key.hashCode();
398 int index = (hash & 0x7FFFFFFF) % elementData.length;
399 m = (LinkedHashMapEntry<K, V>) findNonNullKeyEntry(key, index, hash);
400 if (m == null) {
401 modCount++;
402 if (++elementCount > threshold) {
403 rehash();
404 index = (hash & 0x7FFFFFFF) % elementData.length;
405 }
406 m = (LinkedHashMapEntry<K, V>) createHashedEntry(key, index,
407 hash);
408 } else {
409 linkEntry(m);
410 }
411 }
412
413 V result = m.value;
414 m.value = value;
415 return result;
416 }
417
418 /*
419 * @param m

Callers 1

putMethod · 0.95

Calls 6

createHashedEntryMethod · 0.95
linkEntryMethod · 0.95
hashCodeMethod · 0.65
findNullKeyEntryMethod · 0.45
rehashMethod · 0.45
findNonNullKeyEntryMethod · 0.45

Tested by

no test coverage detected