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-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
  • Method Summary

    Modifier and Type
    Method
    Description
    Comparator<? super 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.
    boolean
    Force to redefine equals for the implementations of immutable collection classes.
    Returns the first (lowest) element currently in this immutable set.
    int
    Force to redefine hashCode for the implementations of immutable collection classes.
    headSet(E toElement)
    Returns a view of the portion of this immutable set whose elements are strictly less than toElement.
    Returns the last (highest) element currently in this immutable set.
    static <E> ImmutableSortedSet<E>
    of()
    Return an empty ImmutableSortedSet, backed by a TreeSet.
    static <E> ImmutableSortedSet<E>
    of(E v1)
    Return an ImmutableSortedSet with 1 entry, backed by a TreeSet.
    static <E> ImmutableSortedSet<E>
    of(E v1, E v2)
    Return an ImmutableSortedSet with 2 entries, backed by a TreeSet.
    static <E> ImmutableSortedSet<E>
    of(E v1, E v2, E v3)
    Return an ImmutableSortedSet with 3 entries, backed by a TreeSet.
    static <E> ImmutableSortedSet<E>
    of(E v1, E v2, E v3, E v4)
    Return an ImmutableSortedSet with 4 entries, backed by a TreeSet.
    static <E> ImmutableSortedSet<E>
    of(E v1, E v2, E v3, E v4, E v5, E... vn)
    Return an ImmutableSortedSet with 5 or more entries, backed by a TreeSet.
    subSet(E fromElement, E toElement)
    Returns a view of the portion of this immutable set whose elements range from fromElement, inclusive, to toElement, exclusive.
    tailSet(E fromElement)
    Returns a view of the portion of this immutable set whose elements are greater than or equal to fromElement.
    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

    Methods inherited from interface org.djutils.immutablecollections.ImmutableSet

    toString

    Methods inherited from interface java.lang.Iterable

    forEach
  • Method Details

    • toSet

      SortedSet<E> toSet()
      Returns a modifiable copy of this immutable set.
      Specified by:
      toSet in interface ImmutableSet<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, or null 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

      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.

      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
      Throws:
      ClassCastException - if fromElement and toElement 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 if fromElement or toElement cannot be compared to elements currently in the immutable set.
      NullPointerException - if fromElement or toElement is null and this immutable set does not permit null elements
      IllegalArgumentException - if fromElement is greater than toElement; or if this immutable set itself has a restricted range, and fromElement or toElement lies outside the bounds of the range
    • headSet

      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.

      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 - if toElement is not compatible with this immutable set's comparator (or, if the immutable set has no comparator, if toElement does not implement Comparable). Implementations may, but are not required to, throw this exception if toElement cannot be compared to elements currently in the immutable set.
      NullPointerException - if toElement is null and this immutable set does not permit null elements
      IllegalArgumentException - if this immutable set itself has a restricted range, and toElement lies outside the bounds of the range
    • tailSet

      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.

      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 - if fromElement is not compatible with this immutable set's comparator (or, if the immutable set has no comparator, if fromElement does not implement Comparable). Implementations may, but are not required to, throw this exception if fromElement cannot be compared to elements currently in the immutable set.
      NullPointerException - if fromElement is null and this immutable set does not permit null elements
      IllegalArgumentException - if this immutable set itself has a restricted range, and fromElement 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

      boolean equals(Object obj)
      Force to redefine equals for the implementations of immutable collection classes.
      Specified by:
      equals in interface ImmutableCollection<E>
      Specified by:
      equals in interface ImmutableSet<E>
      Overrides:
      equals in class Object
      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 interface ImmutableCollection<E>
      Specified by:
      hashCode in interface ImmutableSet<E>
      Overrides:
      hashCode in class Object
      Returns:
      the calculated hashCode
    • of

      static <E> ImmutableSortedSet<E> of()
      Return an empty ImmutableSortedSet, backed by a TreeSet.
      Type Parameters:
      E - the value type
      Returns:
      ImmutableSortedSet<K, V>; an empty ImmutableSortedSet
    • of

      static <E> ImmutableSortedSet<E> of(E v1)
      Return an ImmutableSortedSet with 1 entry, backed by a TreeSet.
      Type Parameters:
      E - the value type
      Parameters:
      v1 - E; value 1
      Returns:
      ImmutableSortedSet<K, V>; an ImmutableSortedSet with 1 entry, backed by a TreeSet
    • of

      static <E> ImmutableSortedSet<E> of(E v1, E v2)
      Return an ImmutableSortedSet with 2 entries, backed by a TreeSet.
      Type Parameters:
      E - the value type
      Parameters:
      v1 - E; value 1
      v2 - E; value 2
      Returns:
      ImmutableSortedSet<K, V>; an ImmutableSortedSet with 2 entries, backed by a TreeSet
    • of

      static <E> ImmutableSortedSet<E> of(E v1, E v2, E v3)
      Return an ImmutableSortedSet with 3 entries, backed by a TreeSet.
      Type Parameters:
      E - the value type
      Parameters:
      v1 - E; value 1
      v2 - E; value 2
      v3 - E; value 3
      Returns:
      ImmutableSortedSet<K, V>; an ImmutableSortedSet with 3 entries, backed by a TreeSet
    • of

      static <E> ImmutableSortedSet<E> of(E v1, E v2, E v3, E v4)
      Return an ImmutableSortedSet with 4 entries, backed by a TreeSet.
      Type Parameters:
      E - the value type
      Parameters:
      v1 - E; value 1
      v2 - E; value 2
      v3 - E; value 3
      v4 - E; value 4
      Returns:
      ImmutableSortedSet<K, V>; an ImmutableSortedSet with 4 entries, backed by a TreeSet
    • of

      static <E> ImmutableSortedSet<E> of(E v1, E v2, E v3, E v4, E v5, E... vn)
      Return an ImmutableSortedSet with 5 or more entries, backed by a TreeSet.
      Type Parameters:
      E - the value type
      Parameters:
      v1 - E; value 1
      v2 - E; value 2
      v3 - E; value 3
      v4 - E; value 4
      v5 - E; value 5
      vn - E...; values 6 and beyond
      Returns:
      ImmutableSortedSet<K, V>; an ImmutableSortedSet with 5 or more entries, backed by a TreeSet