Package io.permazen.util
Class NavigableSets
java.lang.Object
io.permazen.util.NavigableSets
Utility methods relating to
NavigableSet.-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> NavigableSet<E>difference(NavigableSet<E> set1, NavigableSet<E> set2) Create a read-only view of the difference of twoNavigableSets that have a consistent sort order.static <E> NavigableSet<E>empty()Create an emptyNavigableSet.static <E> NavigableSet<E>empty(Comparator<? super E> comparator) Create an emptyNavigableSetwith a specifiedComparator.static <E> NavigableSet<E>intersection(Collection<? extends NavigableSet<E>> sets) Create a read-only view of the intersection of two or moreNavigableSets that have a consistent sort order.static <E> NavigableSet<E>intersection(NavigableSet<E>... sets) Create a read-only view of the intersection of two or moreNavigableSets that have a consistent sort order.static <E> NavigableSet<E>singleton(E value) Create aNavigableSetcontaining a single element and natural ordering.static <E> NavigableSet<E>singleton(Comparator<? super E> comparator, E value) Create aNavigableSetcontaining a single element.static <E> NavigableSet<E>symmetricDifference(NavigableSet<E> set1, NavigableSet<E> set2) Create a read-only view of the symmetric difference of twoNavigableSets that have a consistent sort order.static <E> NavigableSet<E>union(Collection<? extends NavigableSet<E>> sets) Create a read-only view of the union of two or moreNavigableSets that have a consistent sort order.static <E> NavigableSet<E>union(NavigableSet<E>... sets) Create a read-only view of the union of two or moreNavigableSets that have a consistent sort order.
-
Method Details
-
intersection
Create a read-only view of the intersection of two or moreNavigableSets 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 thesetsdo not have equalComparatorsIllegalArgumentException- ifsets, or anyNavigableSettherein, is null
-
union
Create a read-only view of the union of two or moreNavigableSets 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 thesetsdo not have equalComparatorsIllegalArgumentException- ifsets, or anyNavigableSettherein, is null
-
singleton
Create aNavigableSetcontaining a single element and natural ordering.- Type Parameters:
E- element type- Parameters:
value- singleton value- Returns:
- singleton set
- Throws:
IllegalArgumentException- ifvalueis null orvalue's class has no natural ordering (i.e., does not implementComparable)
-
singleton
Create aNavigableSetcontaining a single element.- Type Parameters:
E- element type- Parameters:
comparator- comparator, or null for natural orderingvalue- singleton value (possibly null)- Returns:
- singleton set
- Throws:
IllegalArgumentException- ifcomparatoris null and eithervalueis null orvalue's class has no natural ordering (i.e., does not implementComparable)
-
empty
Create an emptyNavigableSet. The returned set'scomparator()method will return null.- Type Parameters:
E- element type- Returns:
- empty set
-
empty
Create an emptyNavigableSetwith a specifiedComparator.- Type Parameters:
E- element type- Parameters:
comparator- comparator, or null for natural ordering- Returns:
- empty set
-