Package org.djutils.immutablecollections
Interface ImmutableSortedSet<E>
- Type Parameters:
E
- the type of content of this Set
- All Superinterfaces:
ImmutableCollection<E>
,ImmutableSet<E>
,Iterable<E>
,Serializable
- All Known Subinterfaces:
ImmutableNavigableSet<E>
- All Known Implementing Classes:
ImmutableTreeSet
A SortedSet interface without the methods that can change it. The return values of subSet, tailSet and headSet are all
ImmutableSortedSets.
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 TypeMethodDescriptionComparator<? super E>
Returns the comparator used to order the elements in this immutable set, ornull
if this immutable set uses the natural ordering of its elements.boolean
Force to redefine equals for the implementations of immutable collection classes.first()
Returns the first (lowest) element currently in this immutable set.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 strictly less thantoElement
.last()
Returns the last (highest) element currently in this immutable set.static <E> ImmutableSortedSet<E>
of()
Return an empty ImmutableSortedSet, backed by a TreeSet.static <E> ImmutableSortedSet<E>
of
(E v1) Return an ImmutableSortedSet with 1 entry, backed by a TreeSet.static <E> ImmutableSortedSet<E>
of
(E v1, E v2) Return an ImmutableSortedSet with 2 entries, backed by a TreeSet.static <E> ImmutableSortedSet<E>
of
(E v1, E v2, E v3) Return an ImmutableSortedSet with 3 entries, backed by a TreeSet.static <E> ImmutableSortedSet<E>
of
(E v1, E v2, E v3, E v4) Return an ImmutableSortedSet with 4 entries, backed by a TreeSet.static <E> ImmutableSortedSet<E>
of
(E v1, E v2, E v3, E v4, E v5, E... vn) Return an ImmutableSortedSet with 5 or more entries, backed by a TreeSet.Returns a view of the portion of this immutable set whose elements range fromfromElement
, inclusive, totoElement
, exclusive.Returns a view of the portion of this immutable set whose elements are greater than or equal tofromElement
.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
-
Method Details
-
toSet
Returns a modifiable copy of this immutable set.- Specified by:
toSet
in interfaceImmutableSet<E>
- Returns:
- a modifiable copy of this immutable set.
-
comparator
Comparator<? super E> comparator()Returns the comparator used to order the elements in this immutable set, ornull
if this immutable set uses the natural ordering of its elements.- Returns:
- the comparator used to order the elements in this immutable set, or
null
if this immutable set uses the natural ordering of its elements
-
subSet
Returns a view of the portion of this immutable set whose elements range fromfromElement
, inclusive, totoElement
, exclusive. (IffromElement
andtoElement
are equal, the returned immutable set is empty.)The result of this method is a new, immutable sorted set.
- Parameters:
fromElement
- E; low endpoint (inclusive) of the returned immutable settoElement
- E; high endpoint (exclusive) of the returned immutable set- Returns:
- a new, immutable sorted set 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 strictly less thantoElement
. The returned immutable set is backed by this immutable set, so changes in the returned immutable set are reflected in this immutable set, and vice-versa. The returned immutable set supports all optional immutable set operations that this immutable set supports.The result of this method is a new, immutable sorted set.
- Parameters:
toElement
- E; high endpoint (exclusive) of the returned immutable set- Returns:
- a view of the portion of this immutable set whose elements are strictly less than
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 tofromElement
. The returned immutable set is backed by this immutable set, so changes in the returned immutable set are reflected in this immutable set, and vice-versa. The returned immutable set supports all optional immutable set operations that this immutable set supports.The result of this method is a new, immutable sorted set.
- Parameters:
fromElement
- E; low endpoint (inclusive) of the returned immutable set- 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
-
first
E first()Returns the first (lowest) element currently in this immutable set.- Returns:
- the first (lowest) element currently in this immutable set
- Throws:
NoSuchElementException
- if this immutable set is empty
-
last
E last()Returns the last (highest) element currently in this immutable set.- Returns:
- the last (highest) element currently in this immutable set
- Throws:
NoSuchElementException
- if this immutable set is empty
-
equals
Force to redefine equals for the implementations of immutable collection classes.- Specified by:
equals
in interfaceImmutableCollection<E>
- Specified by:
equals
in interfaceImmutableSet<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>
- Overrides:
hashCode
in classObject
- Returns:
- the calculated hashCode
-
of
Return an empty ImmutableSortedSet, backed by a TreeSet.- Type Parameters:
E
- the value type- Returns:
- ImmutableSortedSet<K, V>; an empty ImmutableSortedSet
-
of
Return an ImmutableSortedSet with 1 entry, backed by a TreeSet.- Type Parameters:
E
- the value type- Parameters:
v1
- E; value 1- Returns:
- ImmutableSortedSet<K, V>; an ImmutableSortedSet with 1 entry, backed by a TreeSet
-
of
Return an ImmutableSortedSet with 2 entries, backed by a TreeSet.- Type Parameters:
E
- the value type- Parameters:
v1
- E; value 1v2
- E; value 2- Returns:
- ImmutableSortedSet<K, V>; an ImmutableSortedSet with 2 entries, backed by a TreeSet
-
of
Return an ImmutableSortedSet with 3 entries, backed by a TreeSet.- Type Parameters:
E
- the value type- Parameters:
v1
- E; value 1v2
- E; value 2v3
- E; value 3- Returns:
- ImmutableSortedSet<K, V>; an ImmutableSortedSet with 3 entries, backed by a TreeSet
-
of
Return an ImmutableSortedSet with 4 entries, backed by a TreeSet.- Type Parameters:
E
- the value type- Parameters:
v1
- E; value 1v2
- E; value 2v3
- E; value 3v4
- E; value 4- Returns:
- ImmutableSortedSet<K, V>; an ImmutableSortedSet with 4 entries, backed by a TreeSet
-
of
Return an ImmutableSortedSet with 5 or more entries, backed by a TreeSet.- Type Parameters:
E
- the value type- Parameters:
v1
- E; value 1v2
- E; value 2v3
- E; value 3v4
- E; value 4v5
- E; value 5vn
- E...; values 6 and beyond- Returns:
- ImmutableSortedSet<K, V>; an ImmutableSortedSet with 5 or more entries, backed by a TreeSet
-