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