/** * Returns a deep copy of the receiver; uses <code>clone()</code> and casts the result. * * @return a deep copy of the receiver. */ public AbstractIntIntMap copy() { return (AbstractIntIntMap) clone(); } /**
public boolean apply(int key, int value) { return containsKey(key) && 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 int key) { return !forEachKey(new IntProcedure() { public boolean apply(int 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(IntProcedure)}. * <p> * This method can be used to iterate over the values of the receiver. * * @return the values. */ public IntArrayList values() { IntArrayList list = new IntArrayList(size()); values(list); return list; } /**
/** * 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(IntProcedure)}. * <p> * This method can be used to iterate over the keys of the receiver. * * @return the keys. */ public IntArrayList keys() { IntArrayList list = new IntArrayList(size()); keys(list); return list; } /**
/** * Returns a string representation of the receiver, containing * the String representation of each key-value pair, sorted ascending by key. */ public String toString() { IntArrayList theKeys = keys(); //theKeys.sort(); StringBuffer buf = new StringBuffer(); buf.append("["); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { int 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 <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(final IntArrayList keyList) { pairsSortedByValue(keyList, new IntArrayList(size())); } /**
/** * Returns a string representation of the receiver, containing * the String representation of each key-value pair, sorted ascending by value. */ public String toStringByValue() { IntArrayList theKeys = new IntArrayList(); keysSortedByValue(theKeys); StringBuffer buf = new StringBuffer(); buf.append("["); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { int 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(); } /**
return false; final AbstractIntIntMap other = (AbstractIntIntMap) obj; if (other.size() != size()) return false; return forEachPair(new IntIntProcedure() { public boolean apply(int key, int value) { return other.containsKey(key) && other.get(key) == value; }) && other.forEachPair(new IntIntProcedure() { public boolean apply(int key, int value) { return containsKey(key) && get(key) == value;
/** * 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 int value) { return !forEachPair(new IntIntProcedure() { public boolean apply(int iterKey, int iterValue) { return (value != iterValue); } }); }
public boolean apply(int key) { list.add(get(key)); return true; } }
super.setUp(capacity, minLoadFactor, maxLoadFactor); capacity = nextPrime(capacity); if (capacity==0) capacity=1; // open addressing needs at least one FREE slot at any time.
/** * Returns a string representation of the receiver, containing * the String representation of each key-value pair, sorted ascending by key. */ public String toString() { IntArrayList theKeys = keys(); //theKeys.sort(); StringBuffer buf = new StringBuffer(); buf.append("["); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { int 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 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(IntProcedure)}. * <p> * This method can be used to iterate over the values of the receiver. * * @return the values. */ public IntArrayList values() { IntArrayList list = new IntArrayList(size()); values(list); return list; } /**
/** * 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(IntProcedure)}. * <p> * This method can be used to iterate over the keys of the receiver. * * @return the keys. */ public IntArrayList keys() { IntArrayList list = new IntArrayList(size()); keys(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(final IntArrayList keyList) { pairsSortedByValue(keyList, new IntArrayList(size())); } /**
/** * Returns a string representation of the receiver, containing * the String representation of each key-value pair, sorted ascending by value. */ public String toStringByValue() { IntArrayList theKeys = new IntArrayList(); keysSortedByValue(theKeys); StringBuffer buf = new StringBuffer(); buf.append("["); int maxIndex = theKeys.size() - 1; for (int i = 0; i <= maxIndex; i++) { int 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(); } /**