Package generic

Interface End<T>

Type Parameters:
T - the type of values
All Known Implementing Classes:
End.Point, End.Unbound

public interface End<T>
An endpoint for spans for specifying open endpoints

This is achieved by considering a value +/- an optional epsilon, where epsilon is "the smallest non-zero value". Closed endpoints do not have an epsilon. Open endpoint have an epsilon added or subtracted, depending on whether it is a lower or upper endpoint, respectively. For example, the interval (2, +inf) has the lower endpoint 2 + epsilon so that 2 is excluded, but any number greater than 2 is included. There are some wrinkles, since the domain for values necessitating open intervals is no longer discreet, but we can abuse dec() and inc() to compute endpoints of connected intervals. We cannot allow negative epsilon to be used on lower bounds and vice versa, though. This is a natural restriction, because such intervals wouldn't make sense, but it also overcomes the situation where dec() or inc() would need to change the value. Instead, they need only adjust the use of epsilon.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    The domain for spans of End
    static interface 
    An interface of intervals with open, closed, or unbounded endpoints
    static enum 
    An enum for the three allowed coefficients of epsilon
    static final record 
    An endpoint representing a bound
    static enum 
    An enum for the two values of infinity
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compareTo(End<T> that, Comparator<T> comparator)
    Compare two endpoints
    dec()
    Decrement this endpoint, only by changing the coefficient of epsilon
    inc()
    Increment this endpoint, only by changing the coefficient of epsilon
    boolean
    Check if this endpoint includes its value
    boolean
    Check if this endpoint is allowed as an upper endpoint
    boolean
    Check if this endpoint is allowed as a lower endpoint
    static <T> End<T>
    lower(T value, boolean inclusive)
    Construct a lower endpoint
    static <T> End<T>
    Get the endpoint representing no lower bound
    static <T> End<T>
    Get the endpoint representing no upper bound
    toMaxString(Function<? super End<T>,String> nToString)
     
    toMinString(Function<? super End<T>,String> nToString)
     
    static <T> End<T>
    upper(T value, boolean inclusive)
    Construct an upper endpoint
  • Method Details

    • negativeInfinity

      static <T> End<T> negativeInfinity()
      Get the endpoint representing no lower bound

      This always returns the same instance of negative infinity. Clients can rely on identity when checking for equality.

      Type Parameters:
      T - the type of values
      Returns:
      negative "infinity"
    • positiveInfinity

      static <T> End<T> positiveInfinity()
      Get the endpoint representing no upper bound

      This always returns the same instance of positive infinity. Clients can rely on identity when checking for equality.

      Type Parameters:
      T - the type of values
      Returns:
      positive "infinity"
    • lower

      static <T> End<T> lower(T value, boolean inclusive)
      Construct a lower endpoint
      Type Parameters:
      T - the type of value
      Parameters:
      value - the value
      inclusive - whether the endpoint includes the given value
      Returns:
      the endpoint
    • upper

      static <T> End<T> upper(T value, boolean inclusive)
      Construct an upper endpoint
      Type Parameters:
      T - the type of value
      Parameters:
      value - the value
      inclusive - whether the endpoint includes the given value
      Returns:
      the endpoint
    • toMinString

      String toMinString(Function<? super End<T>,String> nToString)
      Parameters:
      nToString - the endpoint-to-string function
      Returns:
      the string
      See Also:
    • toMaxString

      String toMaxString(Function<? super End<T>,String> nToString)
      Parameters:
      nToString - the endpoint-to-string function
      Returns:
      the string
      See Also:
    • inc

      End<T> inc()
      Increment this endpoint, only by changing the coefficient of epsilon
      Returns:
      the resulting endpoint
    • dec

      End<T> dec()
      Decrement this endpoint, only by changing the coefficient of epsilon
      Returns:
      the resulting endpoint
    • compareTo

      int compareTo(End<T> that, Comparator<T> comparator)
      Compare two endpoints

      First, the values of infinity are considered. Then, the values of the endpoints are considered. Finally, the coefficients of epsilon are considered.

      Parameters:
      that - the other endpoint
      comparator - the value comparator
      Returns:
      the result as in Comparator.compare(Object, Object)
    • isValidMin

      boolean isValidMin()
      Check if this endpoint is allowed as a lower endpoint
      Returns:
      true if allowed
    • isValidMax

      boolean isValidMax()
      Check if this endpoint is allowed as an upper endpoint
      Returns:
      true if allowed
    • isInclusive

      boolean isInclusive()
      Check if this endpoint includes its value
      Returns:
      true if included