- Type Parameters:
N- the type of endpointsS- the type of spans
- All Known Implementing Classes:
ULongSpan.Domain
This defines the domain, which may introduce behaviors different than those naturally acquired from the type. For example, a domain may impose unsigned comparison on a (boxed) primitive type.
- Implementation Notes:
- each domain should be a singleton class
-
Method Summary
Modifier and TypeMethodDescriptionall()Get the span containing all values in the domaindefault SConstruct a new span with the given lower endpoint, inclusive.default SConstruct a new span with the given upper endpoint, inclusive.default SCompute the smallest span which contains two spansdefault SCreate a new span with the given endpoints, inclusive.intCompare two valuesGet a given value, decremented by 1empty()Get the span that contains no value, nor has any endpointsdefault booleanCheck if one span encloses anotherGet a given value, incremented by 1default SCompute the intersection of two spansdefault booleanintersects(S s1, S s2) Check if two spans intersectmax()Get the maximum value in the domaindefault NGet the greater of two valuesmin()Get the minimum value in the domaindefault NGet the lesser of two valuesFactory method for a new span after arguments are validatedSubtract two spansdefault StringtoMaxString(N max, Function<? super N, String> nToString) Render the upper bound of a spandefault StringtoMinString(N min, Function<? super N, String> nToString) Render the lower bound of a spandefault StringRender the given value as a stringdefault StringRender the given span as a stringdefault StringRender the given span as a stringdefault SConstruct a span containing only the given value
-
Method Details
-
closed
Create a new span with the given endpoints, inclusive.- Parameters:
min- the lower endpointmax- the upper endpoint- Returns:
- the span
- Throws:
IllegalArgumentException- if max is less than min
-
newSpan
Factory method for a new span after arguments are validated- Parameters:
min- the lower endpointmax- the upper endpoint- Returns:
- the span
-
value
Construct a span containing only the given value- Parameters:
n- the value- Returns:
- the span
-
atMost
Construct a new span with the given upper endpoint, inclusive.The lower endpoint becomes the minimum value in the domain
- Parameters:
max- the upper endpoint- Returns:
- the span
-
atLeast
Construct a new span with the given lower endpoint, inclusive.The upper endpoint becomes the maximum value in the domain
- Parameters:
min- the lower endpoint- Returns:
- the span
-
all
S all()Get the span containing all values in the domain- Returns:
- the span
- Implementation Notes:
- It is recommended to return a static object
-
empty
S empty()Get the span that contains no value, nor has any endpointsThis span is returned when the result doesn't exist, e.g., when finding the intersection of spans which do not intersect.
- Returns:
- the empty span
- Implementation Notes:
- It is recommended to implement
Span.Emptyas a singleton class and return its instance
-
toString
Render the given value as a string- Parameters:
n- the value- Returns:
- the string
-
toString
Render the given span as a string- Parameters:
s- the span- Returns:
- the string
-
toString
Render the given span as a string- Parameters:
s- the spannToString- a function to convert n to a string- Returns:
- the string
-
toMinString
Render the lower bound of a span- Parameters:
min- the lower boundnToString- a function to convert n to a string- Returns:
- the string
-
toMaxString
Render the upper bound of a span- Parameters:
max- the upper boundnToString- a function to convert n to a string- Returns:
- the string
-
compare
Compare two values- Parameters:
n1- a valuen2- another value- Returns:
- the result, as in
Comparator.compare(Object, Object)
-
min
N min()Get the minimum value in the domainThis value can also represent negative infinity.
- Returns:
- the minimum value
-
max
N max()Get the maximum value in the domainThis value can also represent positive infinity.
- Returns:
- the maximum value
-
inc
Get a given value, incremented by 1If the resulting value would exceed
max(), this should wrap tomin().- Parameters:
n- the value- Returns:
- the value incremented
-
dec
Get a given value, decremented by 1If the resulting value would exceed
min(), this should wrap tomax().- Parameters:
n- the value- Returns:
- the value decremented
-
min
Get the lesser of two valuesIf the values are equal, then either may be chosen
- Parameters:
n1- a valuen2- another value- Returns:
- the lesser
-
max
Get the greater of two valuesIf the values are equal, then either may be chosen
- Parameters:
n1- a valuen2- another value- Returns:
- the greater
-
intersect
Compute the intersection of two spans- Parameters:
s1- a spans2- another span- Returns:
- the intersection, possibly empty
-
intersects
Check if two spans intersect- Parameters:
s1- a spans2- another span- Returns:
- true if they intersect
-
encloses
Check if one span encloses another- Parameters:
s1- a spans2- another span- Returns:
- true if s1 encloses s2
-
bound
Compute the smallest span which contains two spans- Parameters:
s1- a spans2- another span- Returns:
- the bounding span
-
subtract
Subtract two spansIf the first span is empty, this returns 0 spans.
- Parameters:
s1- a spans2- another span- Returns:
- 0, 1, or 2 spans
-