@Override public void clear() { if (keys == EMPTY) { return; } assertNotFrozen(); assertNoConcurrentModification(); Arrays.fill(keys, 0, size, null); Arrays.fill(values, 0, size, null); size = 0; }
@Override public void remove(final String key) { if (keys == EMPTY) { return; } final int index = indexOfKey(key); if (index >= 0) { assertNotFrozen(); assertNoConcurrentModification(); System.arraycopy(keys, index + 1, keys, index, size - 1 - index); System.arraycopy(values, index + 1, values, index, size - 1 - index); keys[size - 1] = null; values[size - 1] = null; size--; } }
@Override public void putValue(final String key, final Object value) { assertNotFrozen(); assertNoConcurrentModification(); if (keys == EMPTY) { inflateTable(threshold); } final int index = indexOfKey(key); if (index >= 0) { keys[index] = key; values[index] = value; } else { // not found, so insert. insertAt(~index, key, value); } }
@Override public void putAll(final ReadOnlyStringMap source) { if (source == this || source == null || source.isEmpty()) { // this.putAll(this) does not modify this collection // this.putAll(null) does not modify this collection // this.putAll(empty ReadOnlyStringMap) does not modify this collection return; } assertNotFrozen(); assertNoConcurrentModification(); if (source instanceof SortedArrayStringMap) { if (this.size == 0) { initFrom0((SortedArrayStringMap) source); } else { merge((SortedArrayStringMap) source); } } else if (source != null) { source.forEach(PUT_ALL, this); } }
@Override public void clear() { if (keys == EMPTY) { return; } assertNotFrozen(); assertNoConcurrentModification(); Arrays.fill(keys, 0, size, null); Arrays.fill(values, 0, size, null); size = 0; }
@Override public void remove(final String key) { if (keys == EMPTY) { return; } final int index = indexOfKey(key); if (index >= 0) { assertNotFrozen(); assertNoConcurrentModification(); System.arraycopy(keys, index + 1, keys, index, size - 1 - index); System.arraycopy(values, index + 1, values, index, size - 1 - index); keys[size - 1] = null; values[size - 1] = null; size--; } }
@Override public void putValue(final String key, final Object value) { assertNotFrozen(); assertNoConcurrentModification(); if (keys == EMPTY) { inflateTable(threshold); } final int index = indexOfKey(key); if (index >= 0) { keys[index] = key; values[index] = value; } else { // not found, so insert. insertAt(~index, key, value); } }
@Override public void putAll(final ReadOnlyStringMap source) { if (source == this || source == null || source.isEmpty()) { // this.putAll(this) does not modify this collection // this.putAll(null) does not modify this collection // this.putAll(empty ReadOnlyStringMap) does not modify this collection return; } assertNotFrozen(); assertNoConcurrentModification(); if (source instanceof SortedArrayStringMap) { if (this.size == 0) { initFrom0((SortedArrayStringMap) source); } else { merge((SortedArrayStringMap) source); } } else if (source != null) { source.forEach(PUT_ALL, this); } }