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-2021 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:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.djutils.immutablecollections.ImmutableAbstractCollection
copyOrWrap
-
-
Constructor Summary
Constructors Constructor Description ImmutableTreeSet(Collection<? extends E> sortedSet)
ImmutableTreeSet(NavigableSet<E> treeSet, Immutable copyOrWrap)
ImmutableTreeSet(ImmutableAbstractSet<E> immutableSortedSet)
ImmutableTreeSet(ImmutableTreeSet<E> immutableTreeSet, Immutable copyOrWrap)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description E
ceiling(E e)
Returns the least element in this immutable set greater than or equal to the given element, ornull
if there is no such element.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.ImmutableIterator<E>
descendingIterator()
Returns an immutable iterator over the elements in this immutable set, in descending order.ImmutableNavigableSet<E>
descendingSet()
Returns a reverse order view of the elements contained in this immutable set.E
first()
Returns the first (lowest) element currently in this immutable set.E
floor(E 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>
getUnderlyingCollection()
Returns the underlying collection of this immutable collection.ImmutableSortedSet<E>
headSet(E toElement)
Returns a view of the portion of this immutable set whose elements are strictly less thantoElement
.ImmutableNavigableSet<E>
headSet(E toElement, boolean inclusive)
Returns a view of the portion of this immutable set whose elements are less than (or equal to, ifinclusive
is true)toElement
.E
higher(E e)
Returns the least element in this immutable set strictly greater than the given element, ornull
if there is no such element.E
last()
Returns the last (highest) element currently in this immutable set.E
lower(E e)
Returns the greatest element in this immutable set strictly less than the given element, ornull
if there is no such element.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
.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
.ImmutableNavigableSet<E>
tailSet(E fromElement, boolean inclusive)
Returns a view of the portion of this immutable set whose elements are greater than (or equal to, ifinclusive
is true)fromElement
.NavigableSet<E>
toSet()
Returns a modifiable copy of this immutable set.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 Detail
-
ImmutableTreeSet
public ImmutableTreeSet(Collection<? extends E> sortedSet)
- Parameters:
sortedSet
- Collection<? extends E>; the collection to use for the immutable set.
-
ImmutableTreeSet
public ImmutableTreeSet(NavigableSet<E> treeSet, Immutable copyOrWrap)
- Parameters:
treeSet
- NavigableSet<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
-
ImmutableTreeSet
public ImmutableTreeSet(ImmutableAbstractSet<E> immutableSortedSet)
- Parameters:
immutableSortedSet
- ImmutableAbstractSet<E>; the collection to use for the immutable set.
-
ImmutableTreeSet
public ImmutableTreeSet(ImmutableTreeSet<E> immutableTreeSet, Immutable copyOrWrap)
- 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 Detail
-
toSet
public final NavigableSet<E> toSet()
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
protected NavigableSet<E> getUnderlyingCollection()
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
public final 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.- 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
public final ImmutableSortedSet<E> subSet(E fromElement, E toElement)
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
public final ImmutableSortedSet<E> headSet(E toElement)
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
public final ImmutableSortedSet<E> tailSet(E fromElement)
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
public final E first()
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
public final E last()
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
public final E lower(E e)
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
public final E floor(E e)
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
public final E ceiling(E e)
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
public final E higher(E e)
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
public final 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
.- Specified by:
descendingSet
in interfaceImmutableNavigableSet<E>
- Returns:
- a reverse order view of this immutable set
-
descendingIterator
public final ImmutableIterator<E> descendingIterator()
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)
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
public final ImmutableNavigableSet<E> headSet(E toElement, boolean inclusive)
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
public final ImmutableNavigableSet<E> tailSet(E fromElement, boolean inclusive)
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
-
-