public synchronized Object put(Object key, Object value) { Object old = super.put(key, value); if (old == null) { Object[] old_values = _values; _values = _factory.createTypedArray(old_values.length + 1); System.arraycopy(old_values, 0, _values, 0, old_values.length); _values[old_values.length] = value; } else { Object[] old_values = _values; int length = old_values.length; // XXX:: doing an explicit copy so that the previous snapshots are not messed upon. _values = _factory.createTypedArray(length); for (int i = 0; i < length; i++) { _values[i] = (old == old_values[i] ? value : old_values[i]); } } return old; }
public synchronized Object remove(Object key) { Object old = super.remove(key); if (old != null) { Object[] old_values = _values; int length = old_values.length; _values = _factory.createTypedArray(length - 1); int i = 0; boolean found = false; for (int j = 0; j < length; j++) { if (found || old != old_values[j]) { _values[i++] = old_values[j]; } else { found = true; } } } return old; }
public synchronized void clear() { super.clear(); _values = _factory.createTypedArray(0); }
public CopyOnWriteArrayMap(int initialCapacity, TypedArrayFactory factory) { super(initialCapacity); _factory = factory; _values = _factory.createTypedArray(0); }
public CopyOnWriteArrayMap(TypedArrayFactory factory) { _factory = factory; _values = _factory.createTypedArray(0); }