java.lang.Object
org.elasticsearch.common.util.set.Sets

public final class Sets extends Object
  • Method Details

    • newHashSet

      public static <T> HashSet<T> newHashSet(Iterator<T> iterator)
    • newHashSet

      public static <T> HashSet<T> newHashSet(Iterable<T> iterable)
    • newHashSet

      @SafeVarargs public static <T> HashSet<T> newHashSet(T... elements)
    • newHashSetWithExpectedSize

      public static <E> Set<E> newHashSetWithExpectedSize(int expectedSize)
    • newLinkedHashSetWithExpectedSize

      public static <E> LinkedHashSet<E> newLinkedHashSetWithExpectedSize(int expectedSize)
    • haveEmptyIntersection

      public static <T> boolean haveEmptyIntersection(Set<T> left, Set<T> right)
    • haveNonEmptyIntersection

      public static <T> boolean haveNonEmptyIntersection(Set<T> left, Set<T> right)
    • difference

      public static <T> Set<T> difference(Set<T> left, Set<T> right)
      The relative complement, or difference, of the specified left and right set. Namely, the resulting set contains all the elements that are in the left set but not in the right set. Neither input is mutated by this operation, an entirely new set is returned.
      Type Parameters:
      T - the type of the elements of the sets
      Parameters:
      left - the left set
      right - the right set
      Returns:
      the relative complement of the left set with respect to the right set
    • sortedDifference

      public static <T> SortedSet<T> sortedDifference(Set<T> left, Set<T> right)
      The relative complement, or difference, of the specified left and right set, returned as a sorted set. Namely, the resulting set contains all the elements that are in the left set but not in the right set, and the set is sorted using the natural ordering of element type. Neither input is mutated by this operation, an entirely new set is returned.
      Type Parameters:
      T - the type of the elements of the sets
      Parameters:
      left - the left set
      right - the right set
      Returns:
      the sorted relative complement of the left set with respect to the right set
    • toUnmodifiableSortedSet

      public static <T> Collector<T,SortedSet<T>,SortedSet<T>> toUnmodifiableSortedSet()
      Returns a Collector that accumulates the input elements into a sorted set and finishes the resulting set into an unmodifiable set. The resulting read-only view through the unmodifiable set is a sorted set.
      Type Parameters:
      T - the type of the input elements
      Returns:
      an unmodifiable set where the underlying set is sorted
    • union

      public static <T> Set<T> union(Set<T> left, Set<T> right)
    • intersection

      public static <T> Set<T> intersection(Set<T> set1, Set<T> set2)
      The intersection of two sets. Namely, the resulting set contains all the elements that are in both sets. Neither input is mutated by this operation, an entirely new set is returned.
      Parameters:
      set1 - the first set
      set2 - the second set
      Returns:
      the unmodifiable intersection of the two sets
    • addToCopy

      public static <E> Set<E> addToCopy(Set<E> set, E... elements)
      Creates a copy of the given set and adds extra elements.
      Parameters:
      set - set to copy
      elements - elements to add