/** * rehashes the map to the new capacity. * * @param newCapacity an <code>int</code> value */ @Override // GemStoneAddition protected void rehash(int newCapacity) { final int oldCapacity = _set.length; final Object[] oldKeys = _set; final Object[] oldVals = _values; final Object[] newKeys = _set = new Object[newCapacity]; final Object[] newVals = _values = new Object[newCapacity]; for (int i = oldCapacity; i-- > 0;) { if(oldKeys[i] != null && oldKeys[i] != REMOVED) { final Object o = oldKeys[i]; final int index = insertionIndex(o); if (index < 0) { throwObjectContractViolation(newKeys[(-index -1)], o); } newKeys[index] = o; newVals[index] = oldVals[i]; } } }
/** * Inserts a key/value pair into the map. * * @param key an <code>Object</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, * or null if none was found. */ public final Object put(Object key, Object value) { if (null == key) { throw new NullPointerException("null keys not supported"); } Object previous = null; Object oldKey = null; int index = insertionIndex(key); if (index < 0) { index = -index -1; previous = _values[index]; } oldKey = _set[index]; _set[index] = key; _values[index] = value; if (null == previous) { postInsertHook(oldKey == null); } return previous; }