@Override public boolean apply(T key, long value) { return other.containsKey(key) && other.get(key) == value; } }
@Override public boolean apply(T key) { return procedure.apply(key, get(key)); } }
@Override public boolean apply(T key) { list.add(get(key)); return true; } }
@Override public boolean apply(T key, long value) { return containsKey(key) && get(key) == value; } }
/** * Returns a string representation of the receiver, containing the String representation of each key-value pair, * sorted ascending by key. */ public String toString() { List<T> theKeys = keys(); StringBuilder buf = new StringBuilder(); buf.append('['); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { T 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(); }
/** * Returns a string representation of the receiver, containing the String representation of each key-value pair, * sorted ascending by value. */ public String toStringByValue() { List<T> theKeys = new ArrayList<T>(); keysSortedByValue(theKeys); StringBuilder buf = new StringBuilder(); buf.append('['); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { T 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(); }
/** * 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. */ @SuppressWarnings("unchecked") public void pairsSortedByKey(List<T> keyList, LongArrayList valueList) { keys(keyList); if (keyList.isEmpty()) { return; } T k = keyList.get(0); // some people would demand a more complex type hierarchy here ... if (!(k instanceof Comparable)) { throw new UnsupportedOperationException("The key type for this map does not implement comparable"); } Collections.sort((List) keyList); valueList.setSize(keyList.size()); for (int i = keyList.size(); --i >= 0;) { valueList.setQuick(i, get(keyList.get(i))); } }
/** * 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 long adjustOrPutValue(T key, long newValue, long incrValue) { boolean present = containsKey(key); if (present) { newValue = (long)(get(key) + incrValue); put(key, newValue); } else { put(key, newValue); } return newValue; } }
@Override public boolean apply(T key) { list.add(get(key)); return true; } }
@Override public boolean apply(T key) { return procedure.apply(key, get(key)); } }
@Override public boolean apply(T key) { return procedure.apply(key, get(key)); } }
@Override public boolean apply(T key, long value) { return other.containsKey(key) && other.get(key) == value; } }
@Override public boolean apply(T key, long value) { return other.containsKey(key) && other.get(key) == value; } }
@Override public boolean apply(T key) { list.add(get(key)); return true; } }
@Override public boolean apply(T key, long value) { return containsKey(key) && get(key) == value; } }
@Override public boolean apply(T key, long value) { return containsKey(key) && get(key) == value; } }
/** * Returns a string representation of the receiver, containing the String representation of each key-value pair, * sorted ascending by key. */ public String toString() { List<T> theKeys = keys(); StringBuilder buf = new StringBuilder(); buf.append('['); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { T 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(); }
/** * Returns a string representation of the receiver, containing the String representation of each key-value pair, * sorted ascending by key. */ public String toString() { List<T> theKeys = keys(); StringBuilder buf = new StringBuilder(); buf.append('['); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { T 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(); }
/** * 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 long adjustOrPutValue(T key, long newValue, long incrValue) { boolean present = containsKey(key); if (present) { newValue = (long)(get(key) + incrValue); put(key, newValue); } else { put(key, newValue); } return newValue; } }
/** * 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 long adjustOrPutValue(T key, long newValue, long incrValue) { boolean present = containsKey(key); if (present) { newValue = (long)(get(key) + incrValue); put(key, newValue); } else { put(key, newValue); } return newValue; } }