@Override public int get(K key) { return map.get(key); }
@Override public void put(K key, int value) { map.put(key, value); }
/** * Increments the primitive value mapped to key by 1 * * @param key the key of the value to increment * @return true if a mapping was found and modified. */ public boolean increment(K key) { return adjustValue(key, (int) 1); }
/** * Inserts a key/value pair into the map if the specified key is not already associated with a * value. * * @param key an <code>Object</code> value * @param value an <code>int</code> value * @return the previous value associated with <tt>key</tt>, or (int)0 if none was found. */ public int putIfAbsent(K key, int value) { int index = insertionIndex(key); if (index < 0) return _values[-index - 1]; return doPut(key, value, index); }
/** * Deletes a key/value pair from the map. * * @param key an <code>Object</code> value * @return an <code>int</code> value or (int)0 if no such mapping exists. */ public int remove(K key) { int prev = (int) 0; int index = index(key); if (index >= 0) { prev = _values[index]; removeAt(index); // clear key,state; adjust size } return prev; }
/** * Copies all of the mappings from the specified map to this map These mappings will replace any * mappings that this map had for any of the keys currently in the specified map. * * @param map mappings to be stored in this map. * @throws NullPointerException if the specified map is null. */ public void putAll(TObjectIntHashMap<K> map) { for (TObjectIntIterator<K> it = map.iterator(); it.hasNext(); ) { put(it.key(), it.value()); } }
/** * Compares this map with another map for equality of their stored entries. * * @param other an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean equals(Object other) { if (!(other instanceof TObjectIntHashMap)) { return false; } TObjectIntHashMap that = (TObjectIntHashMap) other; if (that.size() != this.size()) { return false; } return forEachEntry(new EqProcedure(that)); }
/** * retrieves the value for <tt>key</tt> * * @param key an <code>Object</code> value * @return the value of <tt>key</tt> or (int)0 if no such mapping exists. */ public int get(K key) { int index = index(key); return index < 0 ? (int) 0 : _values[index]; }
/** * Executes <tt>procedure</tt> for each key in the map. * * @param procedure a <code>TObjectProcedure</code> value * @return false if the loop over the keys terminated because the procedure returned false for * some key. */ public boolean forEachKey(TObjectProcedure<K> procedure) { return forEach(procedure); }
@Override public boolean containsKey(K key) { return map.containsKey(key); }
@Override public void clear() { map.clear(); } }
/** * checks for the present of <tt>key</tt> in the keys of the map. * * @param key an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean containsKey(K key) { return contains(key); }
public void writeExternal(ObjectOutput out) throws IOException { // VERSION out.writeByte(0); // NUMBER OF ENTRIES out.writeInt(_size); // ENTRIES SerializationProcedure writeProcedure = new SerializationProcedure(out); if (!forEachEntry(writeProcedure)) { throw writeProcedure.exception; } }
/** * Inserts a key/value pair into the map. * * @param key an <code>Object</code> value * @param value an <code>int</code> value * @return the previous value associated with <tt>key</tt>, or (int)0 if none was found. */ public int put(K key, int value) { int index = insertionIndex(key); return doPut(key, value, index); }
/** * Adjusts the primitive value mapped to key. * * @param key the key of the value to increment * @param amount the amount to adjust the value by. * @return true if a mapping was found and modified. */ public boolean adjustValue(K key, int amount) { int index = index(key); if (index < 0) { return false; } else { _values[index] += amount; return true; } }