Class NavigableSets

java.lang.Object
io.permazen.util.NavigableSets

public final class NavigableSets extends Object
Utility methods relating to NavigableSet.
  • Method Details

    • intersection

      public static <E> NavigableSet<E> intersection(Collection<? extends NavigableSet<E>> sets)
      Create a read-only view of the intersection of two or more NavigableSets that have a consistent sort order. The Comparators of the sets must all be equal (or else all null, for natural ordering).

      The returned intersection iterates efficiently: a complete iteration requires O(N * M) queries, where N is the size of the smallest set, and M is the number of sets.

      Type Parameters:
      E - element type
      Parameters:
      sets - the sets to intersect
      Returns:
      the intersection of all sets
      Throws:
      IllegalArgumentException - if the sets do not have equal Comparators
      IllegalArgumentException - if sets, or any NavigableSet therein, is null
    • intersection

      @SafeVarargs public static <E> NavigableSet<E> intersection(NavigableSet<E>... sets)
      Create a read-only view of the intersection of two or more NavigableSets that have a consistent sort order. The Comparators of the sets must all be equal (or else all null, for natural ordering).

      The returned intersection iterates efficiently: a complete iteration takes time O(N * M) where N is the size of the smallest set, and M is the number of sets.

      Type Parameters:
      E - element type
      Parameters:
      sets - the sets to intersect
      Returns:
      the intersection of all sets
      Throws:
      IllegalArgumentException - if the sets do not have equal Comparators
      IllegalArgumentException - if sets, or any NavigableSet therein, is null
    • union

      @SafeVarargs public static <E> NavigableSet<E> union(NavigableSet<E>... sets)
      Create a read-only view of the union of two or more NavigableSets that have a consistent sort order. The Comparators of the sets must all be equal (or else all null, for natural ordering).
      Type Parameters:
      E - element type
      Parameters:
      sets - the sets to union
      Returns:
      the union of all sets
      Throws:
      IllegalArgumentException - if the sets do not have equal Comparators
      IllegalArgumentException - if sets, or any NavigableSet therein, is null
    • union

      public static <E> NavigableSet<E> union(Collection<? extends NavigableSet<E>> sets)
      Create a read-only view of the union of two or more NavigableSets that have a consistent sort order. The Comparators of the sets must all be equal (or else all null, for natural ordering).
      Type Parameters:
      E - element type
      Parameters:
      sets - the sets to union
      Returns:
      the union of all sets
      Throws:
      IllegalArgumentException - if the sets do not have equal Comparators
      IllegalArgumentException - if sets, or any NavigableSet therein, is null
    • difference

      public static <E> NavigableSet<E> difference(NavigableSet<E> set1, NavigableSet<E> set2)
      Create a read-only view of the difference of two NavigableSets that have a consistent sort order. That is, a set containing all elements contained in the first set but not the second. The Comparators of the sets must all be equal (or else all null, for natural ordering).
      Type Parameters:
      E - element type
      Parameters:
      set1 - original set
      set2 - set of elements to exclude from set1
      Returns:
      the difference of set1 and set2
      Throws:
      IllegalArgumentException - if the set1 and set2 do not have equal Comparators
      IllegalArgumentException - if either parameter is is null
    • symmetricDifference

      public static <E> NavigableSet<E> symmetricDifference(NavigableSet<E> set1, NavigableSet<E> set2)
      Create a read-only view of the symmetric difference of two NavigableSets that have a consistent sort order. That is, the set containing all elements contained in the first set or the second set, but not in both sets. The Comparators of the sets must all be equal (or else all null, for natural ordering).
      Type Parameters:
      E - element type
      Parameters:
      set1 - first set
      set2 - second set
      Returns:
      the symmetric difference of set1 and set2
      Throws:
      IllegalArgumentException - if the set1 and set2 do not have equal Comparators
      IllegalArgumentException - if either parameter is is null
    • singleton

      public static <E> NavigableSet<E> singleton(E value)
      Create a NavigableSet containing a single element and natural ordering.
      Type Parameters:
      E - element type
      Parameters:
      value - singleton value
      Returns:
      singleton set
      Throws:
      IllegalArgumentException - if value is null or value's class has no natural ordering (i.e., does not implement Comparable)
    • singleton

      public static <E> NavigableSet<E> singleton(Comparator<? super E> comparator, E value)
      Create a NavigableSet containing a single element.
      Type Parameters:
      E - element type
      Parameters:
      comparator - comparator, or null for natural ordering
      value - singleton value (possibly null)
      Returns:
      singleton set
      Throws:
      IllegalArgumentException - if comparator is null and either value is null or value's class has no natural ordering (i.e., does not implement Comparable)
    • empty

      public static <E> NavigableSet<E> empty()
      Create an empty NavigableSet. The returned set's comparator() method will return null.
      Type Parameters:
      E - element type
      Returns:
      empty set
    • empty

      public static <E> NavigableSet<E> empty(Comparator<? super E> comparator)
      Create an empty NavigableSet with a specified Comparator.
      Type Parameters:
      E - element type
      Parameters:
      comparator - comparator, or null for natural ordering
      Returns:
      empty set