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 twoNavigableSet
s 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 emptyNavigableSet
with a specifiedComparator
.static <E> NavigableSet<E>
intersection
(Collection<? extends NavigableSet<E>> sets) Create a read-only view of the intersection of two or moreNavigableSet
s 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 moreNavigableSet
s that have a consistent sort order.static <E> NavigableSet<E>
singleton
(E value) Create aNavigableSet
containing a single element and natural ordering.static <E> NavigableSet<E>
singleton
(Comparator<? super E> comparator, E value) Create aNavigableSet
containing a single element.static <E> NavigableSet<E>
symmetricDifference
(NavigableSet<E> set1, NavigableSet<E> set2) Create a read-only view of the symmetric difference of twoNavigableSet
s 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 moreNavigableSet
s 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 moreNavigableSet
s that have a consistent sort order.
-
Method Details
-
intersection
Create a read-only view of the intersection of two or moreNavigableSet
s 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 thesets
do not have equalComparator
sIllegalArgumentException
- ifsets
, or anyNavigableSet
therein, is null
-
union
Create a read-only view of the union of two or moreNavigableSet
s 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 thesets
do not have equalComparator
sIllegalArgumentException
- ifsets
, or anyNavigableSet
therein, is null
-
singleton
Create aNavigableSet
containing a single element and natural ordering.- Type Parameters:
E
- element type- Parameters:
value
- singleton value- Returns:
- singleton set
- Throws:
IllegalArgumentException
- ifvalue
is null orvalue
's class has no natural ordering (i.e., does not implementComparable
)
-
singleton
Create aNavigableSet
containing 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
- ifcomparator
is null and eithervalue
is 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 emptyNavigableSet
with a specifiedComparator
.- Type Parameters:
E
- element type- Parameters:
comparator
- comparator, or null for natural ordering- Returns:
- empty set
-