Package generic

Interface Span<N,S extends Span<N,S>>

Type Parameters:
N - the type of endpoints
S - the type of spans (recursive)
All Superinterfaces:
Comparable<S>
All Known Subinterfaces:
Span.Empty<N,S>, ULongSpan
All Known Implementing Classes:
ULongSpan.Empty, ULongSpan.Impl

public interface Span<N,S extends Span<N,S>> extends Comparable<S>
A (closed) interval

An interval-like type may implement this interface in order to obtain a near out-of-box implementation of a map and/or set of spans. Common operations, such as computing intersections and bounds, are provided. Similarly, spans are automatically coalesced when present in sets and maps. The main requirement is that the span define the domain of its endpoints. The domain can impose behaviors and properties that aren't otherwise present on the type of endpoints. For example, the domain may be Longs, but using unsigned attributes. The domain also provides a factory for new spans. While nominally, this only supports closed intervals, the domain can define a custom endpoint type to obtain mixed intervals.

  • Method Details

    • doToString

      default String doToString()
      Provides a default Object.toString() implementation
      Returns:
      the string
    • domain

      Span.Domain<N,S> domain()
      Get the domain of this span's endpoints
      Returns:
      the domain
    • min

      N min()
      Get the lower enpdoint
      Returns:
      the lower endpoint
      Throws:
      NoSuchElementException - if the span is empty
      See Also:
    • max

      N max()
      Get the upper endpoint
      Returns:
      the upper endpoint
      Throws:
      NoSuchElementException - if the span is empty
      See Also:
    • minIsFinite

      default boolean minIsFinite()
      Check if the lower endpoint excludes the domain minimum
      Returns:
      true if min is not the domain min
    • maxIsFinite

      default boolean maxIsFinite()
      Check if the upper endpoint excludes the domain maximum
      Returns:
      true if max is not the domain max
    • isEmpty

      default boolean isEmpty()
      Check if this span is empty
      Returns:
      true if empty
    • contains

      default boolean contains(N n)
      Check if this span contains the given value
      Parameters:
      n - the value
      Returns:
      true if n is contained in this span
    • intersect

      default S intersect(S s)
      Compute the intersection of this span and another
      Parameters:
      s - another span
      Returns:
      the intersection, possibly empty
      See Also:
    • intersects

      default boolean intersects(S s)
      Check if this span intersects a given span
      Parameters:
      s - another span
      Returns:
      true if they intersect
      See Also:
    • encloses

      default boolean encloses(S s)
      Check if this span encloses a given span
      Parameters:
      s - another span
      Returns:
      true if this encloses the given span
    • bound

      default S bound(S s)
      Compute the bound of this span and another
      Parameters:
      s - another span
      Returns:
      the bound
      See Also:
    • subtract

      default List<S> subtract(S s)
      Subtract a span from this span
      Parameters:
      s - the span to subtract
      Returns:
      0, 1, or 2 spans resulting from the subtraction
    • compareTo

      default int compareTo(S that)
      Specified by:
      compareTo in interface Comparable<N>