Interface End<T>
- Type Parameters:
T- the type of values
- All Known Implementing Classes:
End.Point,End.Unbound
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 ClassesModifier and TypeInterfaceDescriptionstatic classEnd.EndDomain<N,S extends End.EndSpan<N, S>> The domain for spans ofEndstatic interfaceEnd.EndSpan<N,S extends End.EndSpan<N, S>> An interface of intervals with open, closed, or unbounded endpointsstatic enumAn enum for the three allowed coefficients of epsilonstatic final recordAn endpoint representing a boundstatic enumAn enum for the two values of infinity -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(End<T> that, Comparator<T> comparator) Compare two endpointsdec()Decrement this endpoint, only by changing the coefficient of epsiloninc()Increment this endpoint, only by changing the coefficient of epsilonbooleanCheck if this endpoint includes its valuebooleanCheck if this endpoint is allowed as an upper endpointbooleanCheck if this endpoint is allowed as a lower endpointstatic <T> End<T> lower(T value, boolean inclusive) Construct a lower endpointstatic <T> End<T> Get the endpoint representing no lower boundstatic <T> End<T> Get the endpoint representing no upper boundtoMaxString(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
Get the endpoint representing no lower boundThis 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
Get the endpoint representing no upper boundThis 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
Construct a lower endpoint- Type Parameters:
T- the type of value- Parameters:
value- the valueinclusive- whether the endpoint includes the given value- Returns:
- the endpoint
-
upper
Construct an upper endpoint- Type Parameters:
T- the type of value- Parameters:
value- the valueinclusive- whether the endpoint includes the given value- Returns:
- the endpoint
-
toMinString
- Parameters:
nToString- the endpoint-to-string function- Returns:
- the string
- See Also:
-
toMaxString
- Parameters:
nToString- the endpoint-to-string function- Returns:
- the string
- See Also:
-
inc
Increment this endpoint, only by changing the coefficient of epsilon- Returns:
- the resulting endpoint
-
dec
Decrement this endpoint, only by changing the coefficient of epsilon- Returns:
- the resulting endpoint
-
compareTo
Compare two endpointsFirst, 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 endpointcomparator- 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
-