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
public interface ImmutableSortedSet<E> extends ImmutableSet<E>
A SortedSet interface without the methods that can change it. The return values of subSet, tailSet and headSet are all
ImmutableSortedSets.
Copyright (c) 2016-2020 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, Wouter Schakel
-
Method Summary
Modifier and Type Method Description 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.boolean
equals(Object obj)
Force to redefine equals for the implementations of immutable collection classes.E
first()
Returns the first (lowest) element currently in this immutable set.int
hashCode()
Force to redefine hashCode for the implementations of immutable collection classes.ImmutableSortedSet<E>
headSet(E toElement)
Returns a view of the portion of this immutable set whose elements are strictly less thantoElement
.E
last()
Returns the last (highest) element currently in this immutable set.ImmutableSortedSet<E>
subSet(E fromElement, E toElement)
Returns a view of the portion of this immutable set whose elements range fromfromElement
, inclusive, totoElement
, exclusive.ImmutableSortedSet<E>
tailSet(E fromElement)
Returns a view of the portion of this immutable set whose elements are greater than or equal tofromElement
.SortedSet<E>
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
-
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
-