Interface ImmutableNavigableSet<E>

Type Parameters:
E - the type of content of this Set
All Superinterfaces:
ImmutableCollection<E>, ImmutableSet<E>, ImmutableSortedSet<E>, Iterable<E>, Serializable
All Known Implementing Classes:
ImmutableTreeSet

public interface ImmutableNavigableSet<E> extends ImmutableSortedSet<E>
A ImmutableSortedSet extended with navigation methods reporting closest matches for given search targets. Methods lower, floor, ceiling, and higher return elements respectively less than, less than or equal, greater than or equal, and greater than a given element, returning null if there is no such element. All methods from java.util.NavigableSet that can change the set have been left out.

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
    Returns the least element in this immutable set greater than or equal to the given element, or null if there is no such element.
    Returns an immutable iterator over the elements in this immutable set, in descending order.
    Returns a reverse order view of the elements contained in this immutable set.
    boolean
    Force to redefine equals for the implementations of immutable collection classes.
    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.
    int
    Force to redefine hashCode for the implementations of immutable collection classes.
    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.
    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.
    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.
    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.
    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.
    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 org.djutils.immutablecollections.ImmutableSortedSet

    comparator, first, headSet, last, subSet, tailSet

    Methods inherited from interface java.lang.Iterable

    forEach
  • Method Details

    • toSet

      NavigableSet<E> toSet()
      Returns a modifiable copy of this immutable set.
      Specified by:
      toSet in interface ImmutableSet<E>
      Specified by:
      toSet in interface ImmutableSortedSet<E>
      Returns:
      a modifiable copy of this immutable set.
    • lower

      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.
      Parameters:
      e - E; the value to match
      Returns:
      the greatest element less than e, or null if there is no such element
      Throws:
      ClassCastException - if the specified element cannot be compared with the elements currently in the immutable set
      NullPointerException - if the specified element is null and this immutable set does not permit null elements
    • floor

      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.
      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
      Throws:
      ClassCastException - if the specified element cannot be compared with the elements currently in the immutable set
      NullPointerException - if the specified element is null and this immutable set does not permit null elements
    • ceiling

      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.
      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
      Throws:
      ClassCastException - if the specified element cannot be compared with the elements currently in the immutable set
      NullPointerException - if the specified element is null and this immutable set does not permit null elements
    • higher

      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.
      Parameters:
      e - E; the value to match
      Returns:
      the least element greater than e, or null if there is no such element
      Throws:
      ClassCastException - if the specified element cannot be compared with the elements currently in the immutable set
      NullPointerException - if the specified element is null and this immutable set does not permit null elements
    • descendingSet

      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.

      Returns:
      a reverse order view of this immutable set
    • descendingIterator

      ImmutableIterator<E> descendingIterator()
      Returns an immutable iterator over the elements in this immutable set, in descending order. Equivalent in effect to descendingSet().iterator().
      Returns:
      an immutable iterator over the elements in this immutable set, in descending order
    • subSet

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

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

      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.
      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
      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
    • 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>
      Specified by:
      equals in interface ImmutableSortedSet<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>
      Specified by:
      hashCode in interface ImmutableSortedSet<E>
      Overrides:
      hashCode in class Object
      Returns:
      the calculated hashCode