List of utility methods to do Collection Search
boolean | hasLength(final Collection has Length return collection != null && !collection.isEmpty();
|
boolean | hasNoValue(Collection> collection) has No Value if (collection == null) return true; if (collection.isEmpty()) return true; for (Object val : collection) { if (val == null) return true; if (val instanceof String && ((String) val).isEmpty()) ... |
boolean | hasOneItem(final Collection> col) has One Item return col != null && col.size() == 1;
|
boolean | hasOtherThan(Collection> a, Collection> b) Return true if a contains at least one element which is not contained in if (a.size() > b.size()) return true; return !b.containsAll(a); |
boolean | hasValidElement(Collection> collection) has Valid Element for (Object object : collection) { if (object != null) { return true; return false; |
boolean | hasValue(Collection> collection) Is this a non-null collection w/ at least 1 item in it? return (collection != null) && collection.size() > 0;
|
int | indexOf(Collection Returns index of string in a string collection if (str != null && stringCollection != null) { int i = 0; for (String s : stringCollection) { if (s.equals(str)) { return i; i++; return -1; |
int | indexOf(final Collection c, final Object elem) Get the index position of an element in a collection if (c instanceof List) { return ((List) c).indexOf(elem); } else { int index = 0; for (Object element : c) { if (element == elem) { return index; } else { ... |
int | indexOfInstance(final Collection extends T> collection, final T instance) Determine the index position of the first occurrence of the given object instance in the given collection. if (collection != null && !collection.isEmpty()) { int index = 0; for (final T collectionElement : collection) { if (collectionElement == instance) { return index; index++; return -1; |
int | indexOfObjectIdentity(Collection Returns the index position of the first occurring object within the Collection . int retval = -1; if (collection != null) { Iterator<E> iterator = collection.iterator(); if (iterator != null) { int indexPosition = 0; while (retval < 0 && iterator.hasNext()) { E element = iterator.next(); if (element == object) { ... |