/** * Returns a deep copy of the receiver; uses <code>clone()</code> and casts the result. * * @return a deep copy of the receiver. */ @SuppressWarnings("unchecked") // seemingly unavoidable. public AbstractFloatObjectMap<T> copy() { return this.getClass().cast(clone()); }
@Override public boolean apply(float key, Object value) { return other.containsKey(key) && other.get(key) == value; } }
/** * 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 float key) { return !forEachKey( new FloatProcedure() { @Override public boolean apply(float iterKey) { return (key != iterKey); } } ); }
/** * Returns a list filled with all values 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(FloatProcedure)}. <p> This method can be used to iterate over the values of the receiver. * * @return the values. */ public List<T> values() { List<T> list = new ArrayList<T>(size()); values(list); return list; }
/** * 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(FloatArrayList keyList) { pairsSortedByValue(keyList, new ArrayList<T>(size())); }
/** * Returns a string representation of the receiver, containing the String representation of each key-value pair, * sorted ascending by key. */ public String toString() { FloatArrayList theKeys = keys(); theKeys.sort(); StringBuilder buf = new StringBuilder(); buf.append('['); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { float 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 FloatObjectProcedure() { @Override other.forEachPair( new FloatObjectProcedure() { @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(FloatProcedure)}. <p> This method can be used to iterate over the keys of the receiver. * * @return the keys. */ public FloatArrayList keys() { FloatArrayList list = new FloatArrayList(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, according to natural ordering. */ public String toStringByValue() { FloatArrayList theKeys = new FloatArrayList(); keysSortedByValue(theKeys); StringBuilder buf = new StringBuilder(); buf.append('['); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { float 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(float key) { list.add(get(key)); return true; } }
/** * Returns <tt>true</tt> if the receiver contains the specified value. Tests for identity. * * @return <tt>true</tt> if the receiver contains the specified value. */ public boolean containsValue(final T value) { return !forEachPair( new FloatObjectProcedure<T>() { @Override public boolean apply(float iterKey, Object 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) {
/** * 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(FloatArrayList keyList, List<T> valueList) { keys(keyList); keyList.sort(); // the following is straightforward if not the most space-efficient possibility Object[] tempValueList = new Object[keyList.size()]; for (int i = keyList.size(); --i >= 0;) { tempValueList[i] = get(keyList.getQuick(i)); } valueList.clear(); for (Object value : tempValueList) { valueList.add((T) value); } }
public int hashCode() { final int[] buf = new int[size()]; forEachPair( new FloatObjectProcedure() { int i = 0; @Override public boolean apply(float key, Object value) { buf[i++] = HashUtils.hash(key) ^ value.hashCode(); return true; } } ); Arrays.sort(buf); return IntBuffer.wrap(buf).hashCode(); }
/** * Returns a list filled with all values 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(FloatProcedure)}. <p> This method can be used to iterate over the values of the receiver. * * @return the values. */ public List<T> values() { List<T> list = new ArrayList<T>(size()); values(list); return list; }
/** * 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(FloatArrayList keyList) { pairsSortedByValue(keyList, new ArrayList<T>(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(FloatProcedure)}. <p> This method can be used to iterate over the keys of the receiver. * * @return the keys. */ public FloatArrayList keys() { FloatArrayList list = new FloatArrayList(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, according to natural ordering. */ public String toStringByValue() { FloatArrayList theKeys = new FloatArrayList(); keysSortedByValue(theKeys); StringBuilder buf = new StringBuilder(); buf.append('['); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { float 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(); }