E
- element typepublic class ImmutableNavigableSet<E> extends AbstractNavigableSet<E>
NavigableSet
implementation optimized for read efficiency.bounds
Constructor and Description |
---|
ImmutableNavigableSet(E[] elems,
Comparator<? super E> comparator)
Convenience constructor.
|
ImmutableNavigableSet(E[] elems,
int minIndex,
int maxIndex,
Comparator<? super E> comparator)
Primary constructor.
|
ImmutableNavigableSet(NavigableSet<E> source)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
binarySearch(E elem)
Search for the given element in the underlying array.
|
E |
ceiling(E elem) |
Comparator<? super E> |
comparator() |
boolean |
contains(Object obj) |
protected ImmutableNavigableSet<E> |
createSubSet(boolean reverse,
Bounds<E> newBounds)
Create a (possibly reversed) view of this instance with (possibly) tighter lower and/or upper bounds.
|
Iterator<E> |
descendingIterator() |
E |
first() |
E |
floor(E elem) |
E |
higher(E elem) |
boolean |
isEmpty()
Overridden in
AbstractIterationSet to minimize the use of AbstractIterationSet.size() . |
Iterator<E> |
iterator() |
E |
last() |
E |
lower(E elem) |
E |
pollFirst() |
E |
pollLast() |
int |
size()
Calculate size.
|
Spliterator<E> |
spliterator()
Overridden in
AbstractIterationSet to avoid the use of AbstractIterationSet.size() . |
descendingSet, getComparator, headSet, headSet, isWithinLowerBound, isWithinUpperBound, remove, searchAbove, searchBelow, subSet, subSet, tailSet, tailSet
equals, hashCode, toArray, toArray
removeAll
add, addAll, clear, containsAll, retainAll, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
add, addAll, clear, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArray
parallelStream, removeIf, stream
public ImmutableNavigableSet(NavigableSet<E> source)
source
- data sourceIllegalArgumentException
- if source
is nullpublic ImmutableNavigableSet(E[] elems, Comparator<? super E> comparator)
Equivalent to: ImmutableNavigableSet(elems, 0, elems.length, comparator)
.
elems
- sorted element array; this array is not copied and must be already sortedcomparator
- element comparator, or null for natural orderingIllegalArgumentException
- if elems
is nullpublic ImmutableNavigableSet(E[] elems, int minIndex, int maxIndex, Comparator<? super E> comparator)
elems
- sorted element array; this array is not copied and must be already sortedminIndex
- minimum index into array (inclusive)maxIndex
- maximum index into array (exclusive)comparator
- element comparator, or null for natural orderingIllegalArgumentException
- if elems
is nullIllegalArgumentException
- if elems
has length less than maxIndex
IllegalArgumentException
- if minIndex > maxIndex
public int binarySearch(E elem)
This method works like Arrays.binarySearch()
, returning
either the index of elem
in the underlying array given to the constructor if found, or else
the one's complement of elem
's insertion point.
The array searched is the array given to the constructor, or if ImmutableNavigableSet(NavigableSet)
was used, an array containing all of the elements in this set.
elem
- element to search forelem
, or -(insertion point) - 1
if not foundpublic Comparator<? super E> comparator()
public boolean isEmpty()
AbstractIterationSet
AbstractIterationSet
to minimize the use of AbstractIterationSet.size()
.isEmpty
in interface Collection<E>
isEmpty
in interface Set<E>
isEmpty
in class AbstractIterationSet<E>
public int size()
AbstractIterationSet
The implementation in AbstractIterationSet
iterates through all of the elements.
size
in interface Collection<E>
size
in interface Set<E>
size
in class AbstractIterationSet<E>
public boolean contains(Object obj)
contains
in interface Collection<E>
contains
in interface Set<E>
contains
in class AbstractCollection<E>
public E first()
public E last()
public E pollFirst()
pollFirst
in interface NavigableSet<E>
pollFirst
in class AbstractNavigableSet<E>
public E pollLast()
pollLast
in interface NavigableSet<E>
pollLast
in class AbstractNavigableSet<E>
public E lower(E elem)
lower
in interface NavigableSet<E>
lower
in class AbstractNavigableSet<E>
public E floor(E elem)
floor
in interface NavigableSet<E>
floor
in class AbstractNavigableSet<E>
public E higher(E elem)
higher
in interface NavigableSet<E>
higher
in class AbstractNavigableSet<E>
public E ceiling(E elem)
ceiling
in interface NavigableSet<E>
ceiling
in class AbstractNavigableSet<E>
public Iterator<E> iterator()
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in interface NavigableSet<E>
iterator
in interface Set<E>
iterator
in class AbstractCollection<E>
public Iterator<E> descendingIterator()
descendingIterator
in interface NavigableSet<E>
descendingIterator
in class AbstractNavigableSet<E>
public Spliterator<E> spliterator()
AbstractIterationSet
AbstractIterationSet
to avoid the use of AbstractIterationSet.size()
.spliterator
in interface Iterable<E>
spliterator
in interface Collection<E>
spliterator
in interface Set<E>
spliterator
in interface SortedSet<E>
spliterator
in class AbstractNavigableSet<E>
protected ImmutableNavigableSet<E> createSubSet(boolean reverse, Bounds<E> newBounds)
AbstractNavigableSet
newBounds
are consistent with the new ordering (i.e., reversed relative to this instance's ordering if
reverse
is true) and have already been range-checked against this instance's current bounds.createSubSet
in class AbstractNavigableSet<E>
reverse
- whether the new set's ordering should be reversed relative to this instance's orderingnewBounds
- new boundsCopyright © 2022. All rights reserved.