Class CollectionUtilities

java.lang.Object
com.ibm.icu.dev.util.CollectionUtilities

public final class CollectionUtilities extends Object
Utilities that ought to be on collections, but aren't
  • Field Details

    • ALL_EMPTY

      public static final int ALL_EMPTY
      Used for results of getContainmentRelation
      See Also:
    • NOT_A_SUPERSET_B

      public static final int NOT_A_SUPERSET_B
      Used for results of getContainmentRelation
      See Also:
    • NOT_A_DISJOINT_B

      public static final int NOT_A_DISJOINT_B
      Used for results of getContainmentRelation
      See Also:
    • NOT_A_SUBSET_B

      public static final int NOT_A_SUBSET_B
      Used for results of getContainmentRelation
      See Also:
    • NOT_A_EQUALS_B

      public static final int NOT_A_EQUALS_B
      Used for results of getContainmentRelation
      See Also:
    • A_PROPER_SUBSET_OF_B

      public static final int A_PROPER_SUBSET_OF_B
      Used for results of getContainmentRelation
      See Also:
    • A_PROPER_SUPERSET_B

      public static final int A_PROPER_SUPERSET_B
      Used for results of getContainmentRelation
      See Also:
    • A_PROPER_OVERLAPS_B

      public static final int A_PROPER_OVERLAPS_B
      Used for results of getContainmentRelation
      See Also:
  • Constructor Details

    • CollectionUtilities

      public CollectionUtilities()
  • Method Details

    • join

      public static <T> String join(T[] array, String separator)
      Join an array of items.
      Type Parameters:
      T -
      Parameters:
      array -
      separator -
      Returns:
      string
    • join

      public static <T, U extends Iterable<T>> String join(U collection, String separator)
      Join a collection of items.
      Type Parameters:
      T -
      U -
      Parameters:
      collection -
      separator -
      array -
      Returns:
      string
    • asMap

      public static <T> Map<T,T> asMap(T[][] source, Map<T,T> target, boolean reverse)
      Utility like Arrays.asList()
      Type Parameters:
      T -
      Parameters:
      source -
      target -
      reverse -
      Returns:
    • addAll

      public static <T, U extends Collection<T>> U addAll(Iterator<T> source, U target)
      Add all items in iterator to target collection
      Type Parameters:
      T -
      U -
      Parameters:
      source -
      target -
      Returns:
    • size

      public static int size(Iterator source)
      Get the size of an iterator (number of items in it).
      Parameters:
      source -
      Returns:
    • asMap

      public static <T> Map<T,T> asMap(T[][] source)
      Type Parameters:
      T -
      Parameters:
      source -
      Returns:
    • removeAll

      public static <K, V> Map<K,V> removeAll(Map<K,V> m, Collection<K> itemsToRemove)
      Utility that ought to be on Map
      Type Parameters:
      K -
      V -
      Parameters:
      m -
      itemsToRemove -
      Returns:
      map passed in
    • getFirst

      public <T, U extends Collection<T>> T getFirst(U c)
      Get first item in collection, or null if there is none.
      Type Parameters:
      T -
      U -
      Parameters:
      c -
      Returns:
      first item
    • getBest

      public static <T, U extends Collection<T>> T getBest(U c, Comparator<T> comp, int direction)
      Get the "best" in collection. That is the least if direction is invalid input: '<' 0, otherwise the greatest. The first is chosen if there are multiples.
      Type Parameters:
      T -
      U -
      Parameters:
      c -
      comp -
      direction -
      Returns:
    • removeAll

      public static <T, U extends Collection<T>> U removeAll(U c, CollectionUtilities.ObjectMatcher<T> f)
      Remove matching items
      Type Parameters:
      T -
      U -
      Parameters:
      c -
      f -
      Returns:
    • retainAll

      public static <T, U extends Collection<T>> U retainAll(U c, CollectionUtilities.ObjectMatcher<T> f)
      Retain matching items
      Type Parameters:
      T -
      U -
      Parameters:
      c -
      f -
      Returns:
    • containsSome

      public static boolean containsSome(Collection a, Collection b)
      Parameters:
      a -
      b -
      Returns:
    • containsAll

      public static boolean containsAll(Collection a, Collection b)
    • containsNone

      public static boolean containsNone(Collection a, Collection b)
    • getContainmentRelation

      public static 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 invalid input: '&' CollectionUtilities.NOT_A_SUPERSET_B) == 0
      for A_SUBSET_B, use (x invalid input: '&' CollectionUtilities.NOT_A_SUBSET_B) == 0
      for A_EQUALS_B, use (x invalid input: '&' CollectionUtilities.NOT_A_EQUALS_B) == 0
      for A_DISJOINT_B, use (x invalid input: '&' CollectionUtilities.NOT_A_DISJOINT_B) == 0
      for A_OVERLAPS_B, use (x invalid input: '&' CollectionUtilities.NOT_A_DISJOINT_B) != 0
    • matchesAt

      public static int matchesAt(CharSequence text, int offset, CharSequence other)
      Does one string contain another, starting at a specific offset?
      Parameters:
      text -
      offset -
      other -
      Returns:
    • equals

      public static <T> boolean equals(T a, T b)
      Compare, allowing nulls
      Parameters:
      a -
      b -
      Returns:
    • compare

      public static <T extends Comparable> int compare(T a, T b)
      Compare, allowing nulls and putting them first
      Parameters:
      a -
      b -
      Returns:
    • compare

      public static <T extends Comparable> int compare(Iterator<T> iterator1, Iterator<T> iterator2)
      Compare iterators
      Parameters:
      iterator1 -
      iterator2 -
      Returns:
    • compare

      public static <T extends Comparable, U extends Collection<T>> int compare(U o1, U o2)
      Compare, with shortest first, and otherwise lexicographically
      Parameters:
      a -
      b -
      Returns:
    • compare

      public static <T extends Comparable, U extends Set<T>> int compare(U o1, U o2)
      Compare, with shortest first, and otherwise lexicographically
      Parameters:
      a -
      b -
      Returns:
    • compare

      public static <K extends Comparable, V extends Comparable, T extends Map.Entry<K, V>> int compare(T a, T b)
      Compare, allowing nulls and putting them first
      Parameters:
      a -
      b -
      Returns:
    • compareEntrySets

      public static <K extends Comparable, V extends Comparable, T extends Map.Entry<K, V>> int compareEntrySets(Collection<T> o1, Collection<T> o2)