Package org.djutils.immutablecollections
Interface ImmutableNavigableSet<E>
- Type Parameters:
E- the type of content of this Set
- All Superinterfaces:
ImmutableCollection<E>,ImmutableSet<E>,ImmutableSortedSet<E>,Iterable<E>
- All Known Implementing Classes:
ImmutableTreeSet
A
ImmutableSortedSet extended with navigation methods reporting closest matches for given search targets. Methods
lower, floor, ceiling, and higher return elements respectively less than, less than or equal,
greater than or equal, and greater than a given element, returning null if there is no such element. All methods from
java.util.NavigableSet that can change the set have been left out.
Copyright (c) 2016-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.
- Author:
- Alexander Verbraeck, Peter Knoppers
-
Method Summary
Modifier and TypeMethodDescriptionReturns the least element in this immutable set greater than or equal to the given element, ornullif there is no such element.Returns an immutable iterator over the elements in this immutable set, in descending order.Returns a reverse order view of the elements contained in this immutable set.booleanForce to redefine equals for the implementations of immutable collection classes.Returns the greatest element in this immutable set less than or equal to the given element, ornullif there is no such element.inthashCode()Force to redefine hashCode for the implementations of immutable collection classes.Returns a view of the portion of this immutable set whose elements are less than (or equal to, ifinclusiveis true)toElement.Returns the least element in this immutable set strictly greater than the given element, ornullif there is no such element.Returns the greatest element in this immutable set strictly less than the given element, ornullif there is no such element.Returns a view of the portion of this immutable set whose elements range fromfromElementtotoElement.Returns a view of the portion of this immutable set whose elements are greater than (or equal to, ifinclusiveis true)fromElement.toSet()Returns a modifiable copy of this immutable set.Methods inherited from interface org.djutils.immutablecollections.ImmutableCollection
contains, containsAll, containsAll, isCopy, isEmpty, isWrap, iterator, parallelStream, size, spliterator, stream, toArray, toArray, toCollectionMethods inherited from interface org.djutils.immutablecollections.ImmutableSet
toStringMethods inherited from interface org.djutils.immutablecollections.ImmutableSortedSet
comparator, first, headSet, last, subSet, tailSet
-
Method Details
-
toSet
NavigableSet<E> toSet()Returns a modifiable copy of this immutable set.- Specified by:
toSetin interfaceImmutableSet<E>- Specified by:
toSetin interfaceImmutableSortedSet<E>- Returns:
- a modifiable copy of this immutable set.
-
lower
Returns the greatest element in this immutable set strictly less than the given element, ornullif there is no such element.- Parameters:
e- the value to match- Returns:
- the greatest element less than
e, ornullif there is no such element - Throws:
ClassCastException- if the specified element cannot be compared with the elements currently in the immutable setNullPointerException- if the specified element is null and this immutable set does not permit null elements
-
floor
Returns the greatest element in this immutable set less than or equal to the given element, ornullif there is no such element.- Parameters:
e- the value to match- Returns:
- the greatest element less than or equal to
e, ornullif there is no such element - Throws:
ClassCastException- if the specified element cannot be compared with the elements currently in the immutable setNullPointerException- if the specified element is null and this immutable set does not permit null elements
-
ceiling
Returns the least element in this immutable set greater than or equal to the given element, ornullif there is no such element.- Parameters:
e- the value to match- Returns:
- the least element greater than or equal to
e, ornullif there is no such element - Throws:
ClassCastException- if the specified element cannot be compared with the elements currently in the immutable setNullPointerException- if the specified element is null and this immutable set does not permit null elements
-
higher
Returns the least element in this immutable set strictly greater than the given element, ornullif there is no such element.- Parameters:
e- the value to match- Returns:
- the least element greater than
e, ornullif there is no such element - Throws:
ClassCastException- if the specified element cannot be compared with the elements currently in the immutable setNullPointerException- if the specified element is null and this immutable set does not permit null elements
-
descendingSet
ImmutableNavigableSet<E> descendingSet()Returns a reverse order view of the elements contained in this immutable set.The returned immutable set has an ordering equivalent to
. The expressionCollections.reverseOrder(comparator())s.descendingSet().descendingSet()returns a view ofsessentially equivalent tos.- Returns:
- a reverse order view of this immutable set
-
descendingIterator
ImmutableIterator<E> descendingIterator()Returns an immutable iterator over the elements in this immutable set, in descending order. Equivalent in effect todescendingSet().iterator().- Returns:
- an immutable iterator over the elements in this immutable set, in descending order
-
subSet
ImmutableNavigableSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) Returns a view of the portion of this immutable set whose elements range fromfromElementtotoElement. IffromElementandtoElementare equal, the returned immutable set is empty unlessfromInclusiveandtoInclusiveare both true.- Parameters:
fromElement- low endpoint of the returned immutable setfromInclusive-trueif the low endpoint is to be included in the returned viewtoElement- high endpoint of the returned immutable settoInclusive-trueif the high endpoint is to be included in the returned view- Returns:
- a view of the portion of this immutable set whose elements range from
fromElement, inclusive, totoElement, exclusive - Throws:
ClassCastException- iffromElementandtoElementcannot be compared to one another using this immutable set's comparator (or, if the immutable set has no comparator, using natural ordering). Implementations may, but are not required to, throw this exception iffromElementortoElementcannot be compared to elements currently in the immutable set.NullPointerException- iffromElementortoElementis null and this immutable set does not permit null elementsIllegalArgumentException- iffromElementis greater thantoElement; or if this immutable set itself has a restricted range, andfromElementortoElementlies outside the bounds of the range.
-
headSet
Returns a view of the portion of this immutable set whose elements are less than (or equal to, ifinclusiveis true)toElement.- Parameters:
toElement- high endpoint of the returned immutable setinclusive-trueif the high endpoint is to be included in the returned view- Returns:
- a view of the portion of this immutable set whose elements are less than (or equal to, if
inclusiveis true)toElement - Throws:
ClassCastException- iftoElementis not compatible with this immutable set's comparator (or, if the immutable set has no comparator, iftoElementdoes not implementComparable). Implementations may, but are not required to, throw this exception iftoElementcannot be compared to elements currently in the immutable set.NullPointerException- iftoElementis null and this immutable set does not permit null elementsIllegalArgumentException- if this immutable set itself has a restricted range, andtoElementlies outside the bounds of the range
-
tailSet
Returns a view of the portion of this immutable set whose elements are greater than (or equal to, ifinclusiveis true)fromElement.- Parameters:
fromElement- low endpoint of the returned immutable setinclusive-trueif the low endpoint is to be included in the returned view- Returns:
- a view of the portion of this immutable set whose elements are greater than or equal to
fromElement - Throws:
ClassCastException- iffromElementis not compatible with this immutable set's comparator (or, if the immutable set has no comparator, iffromElementdoes not implementComparable). Implementations may, but are not required to, throw this exception iffromElementcannot be compared to elements currently in the immutable set.NullPointerException- iffromElementis null and this immutable set does not permit null elementsIllegalArgumentException- if this immutable set itself has a restricted range, andfromElementlies outside the bounds of the range
-
equals
Force to redefine equals for the implementations of immutable collection classes.- Specified by:
equalsin interfaceImmutableCollection<E>- Specified by:
equalsin interfaceImmutableSet<E>- Specified by:
equalsin interfaceImmutableSortedSet<E>- Overrides:
equalsin classObject- Parameters:
obj- the object to compare this collection with- Returns:
- whether the objects are equal
-
hashCode
int hashCode()Force to redefine hashCode for the implementations of immutable collection classes.- Specified by:
hashCodein interfaceImmutableCollection<E>- Specified by:
hashCodein interfaceImmutableSet<E>- Specified by:
hashCodein interfaceImmutableSortedSet<E>- Overrides:
hashCodein classObject- Returns:
- the calculated hashCode
-