in src/main/java/org/apache/commons/collections4/map/StaticBucketMap.java [277:314]
public V put(final K key, final V value) {
final int hash = getHash(key);
synchronized (locks[hash]) {
Node<K, V> n = buckets[hash];
if (n == null) {
n = new Node<>();
n.key = key;
n.value = value;
buckets[hash] = n;
locks[hash].size++;
return null;
}
// Set n to the last node in the linked list. Check each key along the way
// If the key is found, then change the value of that node and return
// the old value.
for (Node<K, V> next = n; next != null; next = next.next) {
n = next;
if (Objects.equals(n.key, key)) {
final V returnVal = n.value;
n.value = value;
return returnVal;
}
}
// The key was not found in the current list of nodes, add it to the end
// in a new node.
final Node<K, V> newNode = new Node<>();
newNode.key = key;
newNode.value = value;
n.next = newNode;
locks[hash].size++;
}
return null;
}