List of utility methods to do Collection Contain
boolean | containsString(Collection contains String for (String s : coll) { if (s != null && s.contains(str)) return true; return false; |
boolean | containsString(String stringToCheck, Collection Checks if a given collection of strings already contains a given string. for (String item : collection) { if (item.equals(stringToCheck)) { return true; return false; |
boolean | containsStringIgnoreCase(Collection strings, String toCheck) Check if the collection has toCheck str in it, ignoring case sensitivity if (toCheck == null) { return false; for (Iterator it = strings.iterator(); it.hasNext();) { if (toCheck.equalsIgnoreCase((String) it.next())) { return true; return false; |
int | getContainmentRelation(Collection a, Collection b) Assesses all the possible containment relations between collections A and B with one call. Returns an int with bits set, according to a "Venn Diagram" view of A vs B. NOT_A_SUPERSET_B: a - b != {} NOT_A_DISJOINT_B: a * b != {} // * is intersects NOT_A_SUBSET_B: b - a != {} Thus the bits can be used to get the following relations: for A_SUPERSET_B, use (x & CollectionUtilities.NOT_A_SUPERSET_B) == 0 for A_SUBSET_B, use (x & CollectionUtilities.NOT_A_SUBSET_B) == 0 for A_EQUALS_B, use (x & CollectionUtilities.NOT_A_EQUALS_B) == 0 for A_DISJOINT_B, use (x & CollectionUtilities.NOT_A_DISJOINT_B) == 0 for A_OVERLAPS_B, use (x & CollectionUtilities.NOT_A_DISJOINT_B) != 0 if (a.size() == 0) { return (b.size() == 0) ? ALL_EMPTY : NOT_A_SUPERSET_B; } else if (b.size() == 0) { return NOT_A_SUBSET_B; int result = 0; for (Iterator it = a.iterator(); result != 6 && it.hasNext();) { result |= (b.contains(it.next())) ? NOT_A_DISJOINT_B : NOT_A_SUBSET_B; ... |
Collection | intersect(Collection container, Collection contained) intersect Collection copy = new ArrayList(container); copy.retainAll(contained); return copy; |
boolean | isAnyElementContains(String str, Collection is Any Element Contains for (String url : col) { if (str.contains(url)) { return true; return false; |
boolean | isContained(Collection Test if any element in the container contains given string. boolean bReturn = false; if ((container != null) && (!container.isEmpty())) { for (Iterator<String> itrElements = container.iterator(); (itrElements.hasNext() && (!bReturn));) { if ((itrElements.next()).contains(strSearch)) { bReturn = true; return bReturn; |
boolean | isNullOrContains(final Collection> collection, final T item) is Null Or Contains return ((collection == null) || collection.contains(item));
|
boolean | stringContainsOneOfStringsFromCollection(final String pattern, final Collection string Contains One Of Strings From Collection boolean result = false; for (final String string : collection) { if (pattern.contains(string)) { result = true; break; return result; ... |