List of utility methods to do Collection Max
String | toString(Collection> collection, int maxLen) Converts given collection to string of given maximum count of items. StringBuilder builder = new StringBuilder(); builder.append("["); int i = 0; for (Iterator<?> iterator = collection.iterator(); iterator.hasNext() && i < maxLen; i++) { if (i > 0) builder.append(", "); builder.append(iterator.next()); builder.append("]"); return builder.toString(); |
String | toString(Collection> entries, int max) to String StringBuffer sb = new StringBuffer("["); int cnt = Math.min(entries.size(), max); Iterator<?> it = entries.iterator(); for (int i = 0; i < cnt; i++) { if (i > 0) sb.append(","); sb.append(it.next().toString()); if (cnt < entries.size()) { sb.append(",..."); sb.append("]"); return sb.toString(); |
void | transfer(Collection source, Collection dest, int maxElems) Transfer up to 'maxElems' elements from the source to the destination. int j = 0; for (Iterator i = source.iterator(); i.hasNext() && j < maxElems; j++) { dest.add(i.next()); i.remove(); |
Collection | truncate(Collection truncate if (coll.size() > maximumSize) try { Iterator<T> iter = coll.iterator(); for (int i = 0; i < maximumSize; ++i) { iter.next(); while (iter.hasNext()) { iter.next(); ... |
String | valueOfCollection(Collection> c, int maxLength) This returns a String representation of a Collection, with a maximum length specified. if (c == null) return ""; Iterator<?> i = c.iterator(); if (!i.hasNext()) return "[]"; StringBuilder sb = new StringBuilder((int) (maxLength * 1.5)); sb.append('['); for (;;) { ... |