List of utility methods to do Collection Element Get
Map | getCardinalityMap(final Collection col) Returns a Map mapping each unique element in the given Collection to an Integer representing the number of occurances of that element in the Collection . HashMap count = new HashMap(); Iterator it = col.iterator(); while (it.hasNext()) { Object obj = it.next(); Integer c = (Integer) (count.get(obj)); if (null == c) { count.put(obj, new Integer(1)); } else { ... |
Map | getCardinalityMap(final Collection get Cardinality Map Map count = new HashMap<T, Integer>(); for (T item : coll) { Integer c = (Integer) (count.get(item)); if (c == null) { count.put(item, INTEGER_ONE); } else { count.put(item, new Integer(c.intValue() + 1)); return count; |
String | getCaseInsensitive(Collection get Case Insensitive for (String curString : data) if (curString.equalsIgnoreCase(needle)) return curString; return null; |
Class> | getClassFromCollection(Collection collection) Finds a class type that is in the containing collection, will always return something (failsafe to Object.class) Class<?> c = Object.class; if (collection != null) { if (!collection.isEmpty()) { c = collection.iterator().next().getClass(); } else { c = Object.class; return c; |
String | getClosest(final String pattern, Collection get Closest int score = -1; String best = null; for (String target : targets) { int thisScore = matchLength(pattern, target); if (thisScore > score) { score = thisScore; best = target; return best; |
Collection | getCollection(final Iterable get Collection final Enumeration<Object[]> e = new Enumeration<Object[]>() { final Iterator<Path> inner = iterable.iterator(); public boolean hasMoreElements() { return inner.hasNext(); @Override public Object[] nextElement() { return new Object[] { inner.next() }; ... |
int | getCollection(final String iText, final int iStartPosition, final Collection get Collection final StringBuilder buffer = new StringBuilder(); int openPos = iText.indexOf(COLLECTION_BEGIN, iStartPosition); if (openPos == -1) return -1; int currentPos, deep; for (currentPos = openPos + 1, deep = 1; deep > 0; currentPos++) { if (currentPos >= iText.length()) { return -1; ... |
Collection | getCollection(Object entity) get Collection List<Object> rs = new ArrayList<Object>(); rs.add(entity); return rs; |
Collection | getCollection(T... items) Returns a Collection with the given items. List<T> list = new ArrayList<T>(); for (T item : items) { list.add(item); return list; |
Class | getCollectionClass(TT tt) This function helps avoid compile warnings by just having the warning here. return (Class<Collection<TT>>) Collection.class.asSubclass(Collection.class); |