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>
,Serializable
- 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-2024 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, ornull
if 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.boolean
Force 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, ornull
if there is no such element.int
hashCode()
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, ifinclusive
is true)toElement
.Returns the least element in this immutable set strictly greater than the given element, ornull
if there is no such element.Returns the greatest element in this immutable set strictly less than the given element, ornull
if there is no such element.Returns a view of the portion of this immutable set whose elements range fromfromElement
totoElement
.Returns a view of the portion of this immutable set whose elements are greater than (or equal to, ifinclusive
is 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, toCollection
Methods inherited from interface org.djutils.immutablecollections.ImmutableSet
toString
Methods 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:
toSet
in interfaceImmutableSet<E>
- Specified by:
toSet
in 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, ornull
if there is no such element.- Parameters:
e
- E; the value to match- Returns:
- the greatest element less than
e
, ornull
if 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, ornull
if there is no such element.- Parameters:
e
- E; the value to match- Returns:
- the greatest element less than or equal to
e
, ornull
if 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, ornull
if there is no such element.- Parameters:
e
- E; the value to match- Returns:
- the least element greater than or equal to
e
, ornull
if 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, ornull
if there is no such element.- Parameters:
e
- E; the value to match- Returns:
- the least element greater than
e
, ornull
if 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 ofs
essentially 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 fromfromElement
totoElement
. IffromElement
andtoElement
are equal, the returned immutable set is empty unlessfromInclusive
andtoInclusive
are both true.- Parameters:
fromElement
- E; low endpoint of the returned immutable setfromInclusive
- boolean;true
if the low endpoint is to be included in the returned viewtoElement
- E; high endpoint of the returned immutable settoInclusive
- boolean;true
if 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
- iffromElement
andtoElement
cannot 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 iffromElement
ortoElement
cannot be compared to elements currently in the immutable set.NullPointerException
- iffromElement
ortoElement
is null and this immutable set does not permit null elementsIllegalArgumentException
- iffromElement
is greater thantoElement
; or if this immutable set itself has a restricted range, andfromElement
ortoElement
lies 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, ifinclusive
is true)toElement
.- Parameters:
toElement
- E; high endpoint of the returned immutable setinclusive
- boolean;true
if 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
inclusive
is true)toElement
- Throws:
ClassCastException
- iftoElement
is not compatible with this immutable set's comparator (or, if the immutable set has no comparator, iftoElement
does not implementComparable
). Implementations may, but are not required to, throw this exception iftoElement
cannot be compared to elements currently in the immutable set.NullPointerException
- iftoElement
is null and this immutable set does not permit null elementsIllegalArgumentException
- if this immutable set itself has a restricted range, andtoElement
lies 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, ifinclusive
is true)fromElement
.- Parameters:
fromElement
- E; low endpoint of the returned immutable setinclusive
- boolean;true
if 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
- iffromElement
is not compatible with this immutable set's comparator (or, if the immutable set has no comparator, iffromElement
does not implementComparable
). Implementations may, but are not required to, throw this exception iffromElement
cannot be compared to elements currently in the immutable set.NullPointerException
- iffromElement
is null and this immutable set does not permit null elementsIllegalArgumentException
- if this immutable set itself has a restricted range, andfromElement
lies outside the bounds of the range
-
equals
Force to redefine equals for the implementations of immutable collection classes.- Specified by:
equals
in interfaceImmutableCollection<E>
- Specified by:
equals
in interfaceImmutableSet<E>
- Specified by:
equals
in interfaceImmutableSortedSet<E>
- Overrides:
equals
in classObject
- Parameters:
obj
- Object; 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:
hashCode
in interfaceImmutableCollection<E>
- Specified by:
hashCode
in interfaceImmutableSet<E>
- Specified by:
hashCode
in interfaceImmutableSortedSet<E>
- Overrides:
hashCode
in classObject
- Returns:
- the calculated hashCode
-