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-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
- See Also:
- Serialized Form
-
Field Summary
-
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
Modifier and Type Method Description Eceiling(E e)Returns the least element in this immutable set greater than or equal to the given element, ornullif there is no such element.Comparator<? super E>comparator()Returns the comparator used to order the elements in this immutable set, ornullif 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.Efirst()Returns the first (lowest) element currently in this immutable set.Efloor(E e)Returns the greatest element in this immutable set less than or equal to the given element, ornullif 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, ifinclusiveis true)toElement.Ehigher(E e)Returns the least element in this immutable set strictly greater than the given element, ornullif there is no such element.Elast()Returns the last (highest) element currently in this immutable set.Elower(E e)Returns the greatest element in this immutable set strictly less than the given element, ornullif 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 fromfromElementtotoElement.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, ifinclusiveis true)fromElement.NavigableSet<E>toSet()Returns a modifiable copy of this immutable set.StringtoString()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, toCollectionMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djutils.immutablecollections.ImmutableCollection
contains, containsAll, containsAll, isCopy, isEmpty, isWrap, iterator, parallelStream, size, spliterator, stream, toArray, toArray, toCollectionMethods 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:
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
- 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
Returns a modifiable copy of this immutable set.- Specified by:
toSetin interfaceImmutableNavigableSet<E>- Specified by:
toSetin interfaceImmutableSet<E>- Specified by:
toSetin interfaceImmutableSortedSet<E>- Returns:
- a modifiable copy of this immutable set.
-
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:
getUnderlyingCollectionin classImmutableAbstractSet<E>- Returns:
- the underlying collection of this immutable collection.
-
comparator
Returns the comparator used to order the elements in this immutable set, ornullif this immutable set uses the natural ordering of its elements.- Specified by:
comparatorin interfaceImmutableSortedSet<E>- Returns:
- the comparator used to order the elements in this immutable set, or
nullif 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. (IffromElementandtoElementare equal, the returned immutable set is empty.)The result of this method is a new, immutable sorted set.
- Specified by:
subSetin 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
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:
headSetin 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
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:
tailSetin 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
Returns the first (lowest) element currently in this immutable set.- Specified by:
firstin interfaceImmutableSortedSet<E>- Returns:
- the first (lowest) element currently in this immutable set
-
last
Returns the last (highest) element currently in this immutable set.- Specified by:
lastin interfaceImmutableSortedSet<E>- Returns:
- the last (highest) element currently in this immutable set
-
lower
Returns the greatest element in this immutable set strictly less than the given element, ornullif there is no such element.- Specified by:
lowerin interfaceImmutableNavigableSet<E>- Parameters:
e- E; the value to match- Returns:
- the greatest element less than
e, ornullif there is no such element
-
floor
Returns the greatest element in this immutable set less than or equal to the given element, ornullif there is no such element.- Specified by:
floorin interfaceImmutableNavigableSet<E>- Parameters:
e- E; the value to match- Returns:
- the greatest element less than or equal to
e, ornullif there is no such element
-
ceiling
Returns the least element in this immutable set greater than or equal to the given element, ornullif there is no such element.- Specified by:
ceilingin interfaceImmutableNavigableSet<E>- Parameters:
e- E; the value to match- Returns:
- the least element greater than or equal to
e, ornullif there is no such element
-
higher
Returns the least element in this immutable set strictly greater than the given element, ornullif there is no such element.- Specified by:
higherin interfaceImmutableNavigableSet<E>- Parameters:
e- E; the value to match- Returns:
- the least element greater than
e, ornullif there is no such element
-
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 ofsessentially equivalent tos.- Specified by:
descendingSetin interfaceImmutableNavigableSet<E>- Returns:
- a reverse order view of this immutable set
-
descendingIterator
Returns an immutable iterator over the elements in this immutable set, in descending order. Equivalent in effect todescendingSet().iterator().- Specified by:
descendingIteratorin 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 fromfromElementtotoElement. IffromElementandtoElementare equal, the returned immutable set is empty unlessfromInclusiveandtoInclusiveare both true.- Specified by:
subSetin interfaceImmutableNavigableSet<E>- Parameters:
fromElement- E; low endpoint of the returned immutable setfromInclusive- boolean;trueif the low endpoint is to be included in the returned viewtoElement- E; high endpoint of the returned immutable settoInclusive- boolean;trueif 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
Returns a view of the portion of this immutable set whose elements are less than (or equal to, ifinclusiveis true)toElement.- Specified by:
headSetin interfaceImmutableNavigableSet<E>- Parameters:
toElement- E; high endpoint of the returned immutable setinclusive- boolean;trueif 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
inclusiveis true)toElement
-
tailSet
Returns a view of the portion of this immutable set whose elements are greater than (or equal to, ifinclusiveis true)fromElement.- Specified by:
tailSetin interfaceImmutableNavigableSet<E>- Parameters:
fromElement- E; low endpoint of the returned immutable setinclusive- boolean;trueif 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
Force to redefine toString.- Specified by:
toStringin interfaceImmutableSet<E>- Overrides:
toStringin classObject- Returns:
- String; a description of this immutable set
-