Class 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
  • Constructor Details

    • 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 Details

    • toSet

      public final NavigableSet<E> toSet()
      Returns a modifiable copy of this immutable set.
      Specified by:
      toSet in interface ImmutableNavigableSet<E>
      Specified by:
      toSet in interface ImmutableSet<E>
      Specified by:
      toSet in interface ImmutableSortedSet<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 class ImmutableAbstractSet<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, or null if this immutable set uses the natural ordering of its elements.
      Specified by:
      comparator in interface ImmutableSortedSet<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 from fromElement, inclusive, to toElement, exclusive. (If fromElement and toElement are equal, the returned immutable set is empty.)

      The result of this method is a new, immutable sorted set.

      Specified by:
      subSet in interface ImmutableSortedSet<E>
      Parameters:
      fromElement - E; low endpoint (inclusive) of the returned immutable set
      toElement - 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, to toElement, exclusive
    • headSet

      public final ImmutableSortedSet<E> headSet​(E toElement)
      Returns a view of the portion of this immutable set whose elements are strictly less than toElement. 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 interface ImmutableSortedSet<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 to fromElement. 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 interface ImmutableSortedSet<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 interface ImmutableSortedSet<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 interface ImmutableSortedSet<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, or null if there is no such element.
      Specified by:
      lower in interface ImmutableNavigableSet<E>
      Parameters:
      e - E; the value to match
      Returns:
      the greatest element less than e, or null 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, or null if there is no such element.
      Specified by:
      floor in interface ImmutableNavigableSet<E>
      Parameters:
      e - E; the value to match
      Returns:
      the greatest element less than or equal to e, or null 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, or null if there is no such element.
      Specified by:
      ceiling in interface ImmutableNavigableSet<E>
      Parameters:
      e - E; the value to match
      Returns:
      the least element greater than or equal to e, or null 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, or null if there is no such element.
      Specified by:
      higher in interface ImmutableNavigableSet<E>
      Parameters:
      e - E; the value to match
      Returns:
      the least element greater than e, or null 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 Collections.reverseOrder(comparator()). The expression s.descendingSet().descendingSet() returns a view of s essentially equivalent to s.

      Specified by:
      descendingSet in interface ImmutableNavigableSet<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 to descendingSet().iterator().
      Specified by:
      descendingIterator in interface ImmutableNavigableSet<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 from fromElement to toElement. If fromElement and toElement are equal, the returned immutable set is empty unless fromInclusive and toInclusive are both true.
      Specified by:
      subSet in interface ImmutableNavigableSet<E>
      Parameters:
      fromElement - E; low endpoint of the returned immutable set
      fromInclusive - boolean; true if the low endpoint is to be included in the returned view
      toElement - E; high endpoint of the returned immutable set
      toInclusive - 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, to toElement, 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, if inclusive is true) toElement.
      Specified by:
      headSet in interface ImmutableNavigableSet<E>
      Parameters:
      toElement - E; high endpoint of the returned immutable set
      inclusive - 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, if inclusive is true) fromElement.
      Specified by:
      tailSet in interface ImmutableNavigableSet<E>
      Parameters:
      fromElement - E; low endpoint of the returned immutable set
      inclusive - 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

      public final String toString()
      Force to redefine toString.
      Specified by:
      toString in interface ImmutableSet<E>
      Overrides:
      toString in class Object
      Returns:
      String; a description of this immutable set