@Override public short get(K key) { return map.get(key); }
@Override public void put(K key, short value) { map.put(key, value); }
public TroveObjectShortMap() { map = new TObjectShortHashMap<K>(); }
/** * Inserts a key/value pair into the map. * * @param key an <code>Object</code> value * @param value an <code>short</code> value * @return the previous value associated with <tt>key</tt>, or (short)0 if none was found. */ public short put(K key, short value) { int index = insertionIndex(key); return doPut(key, value, index); }
/** * Deletes a key/value pair from the map. * * @param key an <code>Object</code> value * @return an <code>short</code> value or (short)0 if no such mapping exists. */ public short remove(K key) { short prev = (short) 0; int index = index(key); if (index >= 0) { prev = _values[index]; removeAt(index); // clear key,state; adjust size } return prev; }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // NUMBER OF ENTRIES int size = in.readInt(); setUp(size); // ENTRIES while (size-- > 0) { K key = (K) in.readObject(); short val = in.readShort(); put(key, val); } } } // TObjectShortHashMap
/** * 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 TObjectShortHashMap)) { return false; } TObjectShortHashMap that = (TObjectShortHashMap) 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 (short)0 if no such mapping exists. */ public short get(K key) { int index = index(key); return index < 0 ? (short) 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); }
/** * 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, (short) 1); }
/** * 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); }
@Override public boolean containsKey(K key) { return map.containsKey(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 if the specified key is not already associated with a * value. * * @param key an <code>Object</code> value * @param value an <code>short</code> value * @return the previous value associated with <tt>key</tt>, or (short)0 if none was found. */ public short putIfAbsent(K key, short value) { int index = insertionIndex(key); if (index < 0) return _values[-index - 1]; 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, short amount) { int index = index(key); if (index < 0) { return false; } else { _values[index] += amount; return true; } }