/** * Returns a deep copy of the receiver; uses <code>clone()</code> and casts the result. * * @return a deep copy of the receiver. */ public AbstractByteByteMap copy() { return (AbstractByteByteMap) clone(); }
/** * Check the map for a key. If present, add an increment to the value. If absent, * store a specified value. * @param key the key. * @param newValue the value to store if the key is not currently in the map. * @param incrValue the value to be added to the current value in the map. **/ public byte adjustOrPutValue(byte key, byte newValue, byte incrValue) { boolean present = containsKey(key); if (present) { newValue = (byte)(get(key) + incrValue); put(key, newValue); } else { put(key, newValue); } return newValue; } }
/** * Returns <tt>true</tt> if the receiver contains the specified key. * * @return <tt>true</tt> if the receiver contains the specified key. */ public boolean containsKey(final byte key) { return !forEachKey( new ByteProcedure() { @Override public boolean apply(byte iterKey) { return key != iterKey; } } ); }
@Override public boolean apply(byte key, byte value) { return other.containsKey(key) && other.get(key) == value; } }
/** * Fills all keys <i>sorted ascending by their associated value</i> into the specified list. Fills into the list, * starting at index 0. After this call returns the specified list has a new size that equals <tt>this.size()</tt>. * Primary sort criterium is "value", secondary sort criterium is "key". This means that if any two values are equal, * the smaller key comes first. <p> <b>Example:</b> <br> <tt>keys = (8,7,6), values = (1,2,2) --> keyList = * (8,6,7)</tt> * * @param keyList the list to be filled, can have any size. */ public void keysSortedByValue(ByteArrayList keyList) { pairsSortedByValue(keyList, new ByteArrayList(size())); }
/** * Returns a string representation of the receiver, containing the String representation of each key-value pair, * sorted ascending by key. */ public String toString() { ByteArrayList theKeys = keys(); //theKeys.sort(); StringBuilder buf = new StringBuilder(); buf.append('['); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { byte key = theKeys.get(i); buf.append(String.valueOf(key)); buf.append("->"); buf.append(String.valueOf(get(key))); if (i < maxIndex) { buf.append(", "); } } buf.append(']'); return buf.toString(); }
if (other.size() != size()) { return false; forEachPair( new ByteByteProcedure() { @Override other.forEachPair( new ByteByteProcedure() { @Override
/** * Returns a list filled with all keys contained in the receiver. The returned list has a size that equals * <tt>this.size()</tt>. Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link * #forEachKey(ByteProcedure)}. <p> This method can be used to iterate over the keys of the receiver. * * @return the keys. */ public ByteArrayList keys() { ByteArrayList list = new ByteArrayList(size()); keys(list); return list; }
/** * Returns a string representation of the receiver, containing the String representation of each key-value pair, * sorted ascending by value. */ public String toStringByValue() { ByteArrayList theKeys = new ByteArrayList(); keysSortedByValue(theKeys); StringBuilder buf = new StringBuilder(); buf.append('['); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { byte key = theKeys.get(i); buf.append(String.valueOf(key)); buf.append("->"); buf.append(String.valueOf(get(key))); if (i < maxIndex) { buf.append(", "); } } buf.append(']'); return buf.toString(); }
@Override public boolean apply(byte key) { list.add(get(key)); return true; } }
/** * Returns <tt>true</tt> if the receiver contains the specified value. * * @return <tt>true</tt> if the receiver contains the specified value. */ public boolean containsValue(final byte value) { return !forEachPair( new ByteByteProcedure() { @Override public boolean apply(byte iterKey, byte iterValue) { return (value != iterValue); } } ); }
final protected void setUp(int initialCapacity, double minLoadFactor, double maxLoadFactor) { int capacity = initialCapacity; super.setUp(capacity, minLoadFactor, maxLoadFactor); capacity = nextPrime(capacity); if (capacity == 0) {
@Override public boolean apply(byte key, byte value) { return containsKey(key) && get(key) == value; } }
/** * Fills all keys and values <i>sorted ascending by key</i> into the specified lists. Fills into the lists, starting * at index 0. After this call returns the specified lists both have a new size that equals <tt>this.size()</tt>. <p> * <b>Example:</b> <br> <tt>keys = (8,7,6), values = (1,2,2) --> keyList = (6,7,8), valueList = (2,2,1)</tt> * * @param keyList the list to be filled with keys, can have any size. * @param valueList the list to be filled with values, can have any size. */ public void pairsSortedByKey(ByteArrayList keyList, ByteArrayList valueList) { keys(keyList); keyList.sort(); valueList.setSize(keyList.size()); for (int i = keyList.size(); --i >= 0;) { valueList.setQuick(i, get(keyList.getQuick(i))); } }
public int hashCode() { final int[] buf = new int[size()]; forEachPair( new ByteByteProcedure() { int i = 0; @Override public boolean apply(byte key, byte value) { buf[i++] = HashUtils.hash(key) ^ HashUtils.hash(value); return true; } } ); Arrays.sort(buf); return IntBuffer.wrap(buf).hashCode(); }
/** * Fills all keys <i>sorted ascending by their associated value</i> into the specified list. Fills into the list, * starting at index 0. After this call returns the specified list has a new size that equals <tt>this.size()</tt>. * Primary sort criterium is "value", secondary sort criterium is "key". This means that if any two values are equal, * the smaller key comes first. <p> <b>Example:</b> <br> <tt>keys = (8,7,6), values = (1,2,2) --> keyList = * (8,6,7)</tt> * * @param keyList the list to be filled, can have any size. */ public void keysSortedByValue(ByteArrayList keyList) { pairsSortedByValue(keyList, new ByteArrayList(size())); }
/** * Returns a list filled with all keys contained in the receiver. The returned list has a size that equals * <tt>this.size()</tt>. Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link * #forEachKey(ByteProcedure)}. <p> This method can be used to iterate over the keys of the receiver. * * @return the keys. */ public ByteArrayList keys() { ByteArrayList list = new ByteArrayList(size()); keys(list); return list; }
/** * Returns a string representation of the receiver, containing the String representation of each key-value pair, * sorted ascending by value. */ public String toStringByValue() { ByteArrayList theKeys = new ByteArrayList(); keysSortedByValue(theKeys); StringBuilder buf = new StringBuilder(); buf.append('['); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { byte key = theKeys.get(i); buf.append(String.valueOf(key)); buf.append("->"); buf.append(String.valueOf(get(key))); if (i < maxIndex) { buf.append(", "); } } buf.append(']'); return buf.toString(); }