/** * 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(ObjectProcedure)}. <p> This method can be used to iterate over the keys of the receiver. * * @return the keys. */ public List<T> keys() { List<T> list = new ArrayList<T>(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() { 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(); }
/** * 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, DoubleArrayList 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))); } }
keys(keyList); values(valueList);
/** * 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(ObjectProcedure)}. <p> This method can be used to iterate over the keys of the receiver. * * @return the keys. */ public List<T> keys() { List<T> list = new ArrayList<T>(size()); keys(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(ObjectProcedure)}. <p> This method can be used to iterate over the keys of the receiver. * * @return the keys. */ public List<T> keys() { List<T> list = new ArrayList<T>(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() { 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(); }
/** * 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, DoubleArrayList 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))); } }
/** * 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, DoubleArrayList 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))); } }
keys(keyList); values(valueList);
keys(keyList); values(valueList);