/** * Returns a deep copy of the receiver; uses <code>clone()</code> and casts the result. * * @return a deep copy of the receiver. */ public AbstractIntObjectMap copy() { return (AbstractIntObjectMap) clone(); } /**
public boolean apply(int 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 int key) { return !forEachKey(new IntProcedure() { public boolean apply(int iterKey) { return (key != iterKey); } }); }
/** * 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 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 ObjectArrayList values() { ObjectArrayList list = new ObjectArrayList(size()); values(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(); } /**
/** * Returns the matrix cell value at coordinate <tt>index</tt>. * * <p>Provided with invalid parameters this method may return invalid objects without throwing any exception. * <b>You should only use this method when you are absolutely sure that the coordinate is within bounds.</b> * Precondition (unchecked): <tt>index<0 || index>=size()</tt>. * * @param index the index of the cell. * @return the value of the specified cell. */ public Object getQuick(int index) { //if (debug) if (index<0 || index>=size) checkIndex(index); //return elements.get(index(index)); //manually inlined: return elements.get(offset + offsets[zero + index*stride]); } /**
/** * 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 ObjectArrayList(size())); }
/** * 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() { 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(); } /**
if (other.size() != size()) return false; forEachPair( new IntObjectProcedure() { public boolean apply(int key, Object value) { other.forEachPair( new IntObjectProcedure() { public boolean apply(int key, Object value) {
/** * 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 IntObjectProcedure() { public boolean apply(int iterKey, Object iterValue) { return (value != iterValue); } }); }
/** * Returns the number of cells having non-zero values. */ public int cardinality() { if (this.isNoView) return this.elements.size(); else return super.cardinality(); } /**
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 the matrix cell value at coordinate <tt>index</tt>. * * <p>Provided with invalid parameters this method may return invalid objects without throwing any exception. * <b>You should only use this method when you are absolutely sure that the coordinate is within bounds.</b> * Precondition (unchecked): <tt>index<0 || index>=size()</tt>. * * @param index the index of the cell. * @return the value of the specified cell. */ public Object getQuick(int index) { //if (debug) if (index<0 || index>=size) checkIndex(index); //return this.elements.get(index(index)); // manually inlined: return elements.get(zero + index*stride); } /**
/** * 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 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 ObjectArrayList values() { ObjectArrayList list = new ObjectArrayList(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(final IntArrayList keyList) { pairsSortedByValue(keyList, new ObjectArrayList(size())); } /**
/** * 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() { 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(); } /**