Package org.djutils.immutablecollections
Class ImmutableTreeSet<E>
java.lang.Object
org.djutils.immutablecollections.ImmutableAbstractCollection<E>
org.djutils.immutablecollections.ImmutableAbstractSet<E>
org.djutils.immutablecollections.ImmutableTreeSet<E>
- Type Parameters:
E
- the type of content of this Set
- All Implemented Interfaces:
Serializable
,Iterable<E>
,ImmutableCollection<E>
,ImmutableNavigableSet<E>
,ImmutableSet<E>
,ImmutableSortedSet<E>
public class ImmutableTreeSet<E>
extends ImmutableAbstractSet<E>
implements ImmutableNavigableSet<E>
An immutable wrapper for a TreeSet.
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
- See Also:
-
Field Summary
Fields inherited from class org.djutils.immutablecollections.ImmutableAbstractCollection
copyOrWrap
-
Constructor Summary
ConstructorDescriptionImmutableTreeSet
(Collection<? extends E> sortedSet) ImmutableTreeSet
(NavigableSet<E> treeSet, Immutable copyOrWrap) ImmutableTreeSet
(ImmutableAbstractSet<E> immutableSortedSet) ImmutableTreeSet
(ImmutableTreeSet<E> immutableTreeSet, Immutable copyOrWrap) -
Method Summary
Modifier and TypeMethodDescriptionfinal E
Returns the least element in this immutable set greater than or equal to the given element, ornull
if there is no such element.final Comparator<? 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.final ImmutableIterator<E>
Returns an immutable iterator over the elements in this immutable set, in descending order.final ImmutableNavigableSet<E>
Returns a reverse order view of the elements contained in this immutable set.final E
first()
Returns the first (lowest) element currently in this immutable set.final E
Returns the greatest element in this immutable set less than or equal to the given element, ornull
if there is no such element.protected NavigableSet<E>
Returns the underlying collection of this immutable collection.final ImmutableSortedSet<E>
Returns a view of the portion of this immutable set whose elements are strictly less thantoElement
.final ImmutableNavigableSet<E>
Returns a view of the portion of this immutable set whose elements are less than (or equal to, ifinclusive
is true)toElement
.final E
Returns the least element in this immutable set strictly greater than the given element, ornull
if there is no such element.final E
last()
Returns the last (highest) element currently in this immutable set.final E
Returns the greatest element in this immutable set strictly less than the given element, ornull
if there is no such element.final ImmutableNavigableSet<E>
Returns a view of the portion of this immutable set whose elements range fromfromElement
totoElement
.final ImmutableSortedSet<E>
Returns a view of the portion of this immutable set whose elements range fromfromElement
, inclusive, totoElement
, exclusive.final ImmutableSortedSet<E>
Returns a view of the portion of this immutable set whose elements are greater than or equal tofromElement
.final ImmutableNavigableSet<E>
Returns a view of the portion of this immutable set whose elements are greater than (or equal to, ifinclusive
is true)fromElement
.final NavigableSet<E>
toSet()
Returns a modifiable copy of this immutable set.final String
toString()
Force to redefine toString.Methods inherited from class org.djutils.immutablecollections.ImmutableAbstractSet
contains, containsAll, containsAll, equals, forEach, hashCode, isEmpty, isWrap, iterator, parallelStream, size, spliterator, stream, toArray, toArray, toCollection
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
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.ImmutableNavigableSet
equals, hashCode
-
Constructor Details
-
ImmutableTreeSet
- Parameters:
sortedSet
- Collection<? extends E>; the collection to use for the immutable set.
-
ImmutableTreeSet
- Parameters:
immutableSortedSet
- ImmutableAbstractSet<E>; the collection to use for the immutable set.
-
ImmutableTreeSet
- Parameters:
immutableTreeSet
- ImmutableTreeSet<E>; the collection to use for the immutable set.copyOrWrap
- COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection
-
-
Method Details
-
toSet
Description copied from interface:ImmutableNavigableSet
Returns a modifiable copy of this immutable set.- Specified by:
toSet
in interfaceImmutableNavigableSet<E>
- Specified by:
toSet
in interfaceImmutableSet<E>
- Specified by:
toSet
in interfaceImmutableSortedSet<E>
- Returns:
- a modifiable copy of this immutable set.
-
getUnderlyingCollection
Description copied from class:ImmutableAbstractCollection
Returns the underlying collection of this immutable collection. In case of Immutable.WRAP, this will be the original collection. In case of IMMUTABLE.COPY, this will be the internally stored (mutable) copy of the collection.- Overrides:
getUnderlyingCollection
in classImmutableAbstractSet<E>
- Returns:
- the underlying collection of this immutable collection.
-
comparator
Description copied from interface:ImmutableSortedSet
Returns the comparator used to order the elements in this immutable set, ornull
if this immutable set uses the natural ordering of its elements.- Specified by:
comparator
in interfaceImmutableSortedSet<E>
- 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
Description copied from interface:ImmutableSortedSet
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.
- Specified by:
subSet
in interfaceImmutableSortedSet<E>
- 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
-
headSet
Description copied from interface:ImmutableSortedSet
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.
- Specified by:
headSet
in interfaceImmutableSortedSet<E>
- 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
-
tailSet
Description copied from interface:ImmutableSortedSet
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.
- Specified by:
tailSet
in interfaceImmutableSortedSet<E>
- 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
-
first
Description copied from interface:ImmutableSortedSet
Returns the first (lowest) element currently in this immutable set.- Specified by:
first
in interfaceImmutableSortedSet<E>
- Returns:
- the first (lowest) element currently in this immutable set
-
last
Description copied from interface:ImmutableSortedSet
Returns the last (highest) element currently in this immutable set.- Specified by:
last
in interfaceImmutableSortedSet<E>
- Returns:
- the last (highest) element currently in this immutable set
-
lower
Description copied from interface:ImmutableNavigableSet
Returns the greatest element in this immutable set strictly less than the given element, ornull
if there is no such element.- Specified by:
lower
in interfaceImmutableNavigableSet<E>
- Parameters:
e
- E; the value to match- Returns:
- the greatest element less than
e
, ornull
if there is no such element
-
floor
Description copied from interface:ImmutableNavigableSet
Returns the greatest element in this immutable set less than or equal to the given element, ornull
if there is no such element.- Specified by:
floor
in interfaceImmutableNavigableSet<E>
- Parameters:
e
- E; the value to match- Returns:
- the greatest element less than or equal to
e
, ornull
if there is no such element
-
ceiling
Description copied from interface:ImmutableNavigableSet
Returns the least element in this immutable set greater than or equal to the given element, ornull
if there is no such element.- Specified by:
ceiling
in interfaceImmutableNavigableSet<E>
- Parameters:
e
- E; the value to match- Returns:
- the least element greater than or equal to
e
, ornull
if there is no such element
-
higher
Description copied from interface:ImmutableNavigableSet
Returns the least element in this immutable set strictly greater than the given element, ornull
if there is no such element.- Specified by:
higher
in interfaceImmutableNavigableSet<E>
- Parameters:
e
- E; the value to match- Returns:
- the least element greater than
e
, ornull
if there is no such element
-
descendingSet
Description copied from interface:ImmutableNavigableSet
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
.- Specified by:
descendingSet
in interfaceImmutableNavigableSet<E>
- Returns:
- a reverse order view of this immutable set
-
descendingIterator
Description copied from interface:ImmutableNavigableSet
Returns an immutable iterator over the elements in this immutable set, in descending order. Equivalent in effect todescendingSet().iterator()
.- Specified by:
descendingIterator
in interfaceImmutableNavigableSet<E>
- Returns:
- an immutable iterator over the elements in this immutable set, in descending order
-
subSet
public final ImmutableNavigableSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) Description copied from interface:ImmutableNavigableSet
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.- Specified by:
subSet
in interfaceImmutableNavigableSet<E>
- 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
-
headSet
Description copied from interface:ImmutableNavigableSet
Returns a view of the portion of this immutable set whose elements are less than (or equal to, ifinclusive
is true)toElement
.- Specified by:
headSet
in interfaceImmutableNavigableSet<E>
- 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
-
tailSet
Description copied from interface:ImmutableNavigableSet
Returns a view of the portion of this immutable set whose elements are greater than (or equal to, ifinclusive
is true)fromElement
.- Specified by:
tailSet
in interfaceImmutableNavigableSet<E>
- 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
-
toString
Description copied from interface:ImmutableSet
Force to redefine toString.- Specified by:
toString
in interfaceImmutableSet<E>
- Overrides:
toString
in classObject
- Returns:
- String; a description of this immutable set
-