T - Java type of range boundspublic class Bounds<T> extends Object
AbstractNavigableSet and AbstractNavigableMap to define
the (optional) upper and lower bounds of a restricted range.| Constructor and Description |
|---|
Bounds()
Convenience constructor to create a new instance with no upper or lower bounds.
|
Bounds(T bound,
BoundType boundType,
boolean upper)
Create a one-sided bound.
|
Bounds(T lowerBound,
BoundType lowerBoundType,
T upperBound,
BoundType upperBoundType)
Primary constructor.
|
Bounds(T lowerBound,
T upperBound)
Create two-sided bounds with inclusive lower bound and exclusive upper bound.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
T |
getLowerBound()
Get the Java value corresponding to the lower bound restriction, if any.
|
BoundType |
getLowerBoundType()
Get the type of the lower bound that corresponds to
getLowerBound(). |
T |
getUpperBound()
Get the Java value corresponding to the upper bound restriction, if any.
|
BoundType |
getUpperBoundType()
Get the type of the upper bound that corresponds to
getUpperBound(). |
int |
hashCode() |
boolean |
isWithinBounds(Comparator<? super T> comparator,
Bounds<? extends T> newBounds)
Determine whether the given new
Bounds is within of the bounds of this instance. |
boolean |
isWithinBounds(Comparator<? super T> comparator,
T value)
Check whether the given value is within the bounds of this instance.
|
boolean |
isWithinLowerBound(Comparator<? super T> comparator,
T value)
Check whether the given value is within the lower bound of this instance.
|
boolean |
isWithinUpperBound(Comparator<? super T> comparator,
T value)
Check whether the given value is within the upper bound of this instance.
|
Bounds<T> |
reverse()
Create an instance like this instance but with the upper and lower bounds reversed.
|
String |
toString() |
Bounds<T> |
withLowerBound(T newLowerBound,
BoundType newLowerBoundType)
Create an instance like this instance but with a different lower bound.
|
Bounds<T> |
withoutLowerBound()
Create an instance like this instance but with the lower bound removed.
|
Bounds<T> |
withoutUpperBound()
Create an instance like this instance but with the upper bound removed.
|
Bounds<T> |
withUpperBound(T newUpperBound,
BoundType newUpperBoundType)
Create an instance like this instance but with a different upper bound.
|
public Bounds()
public Bounds(T bound, BoundType boundType, boolean upper)
bound - bound restriction value; ignored if boundType is BoundType.NONEboundType - type of bound for bound, or BoundType.NONE if there is no lower boundupper - true to create an upper bound, false to create a lower boundIllegalArgumentException - if boundType is nullpublic Bounds(T lowerBound, T upperBound)
lowerBound - lower bound restriction value (inclusive)upperBound - upper bound restriction value (exclusive)public Bounds(T lowerBound, BoundType lowerBoundType, T upperBound, BoundType upperBoundType)
lowerBound - lower bound restriction value; ignored if lowerBoundType is BoundType.NONElowerBoundType - type of bound for lowerBound, or BoundType.NONE if there is no lower boundupperBound - upper bound restriction value; ignored if upperBoundType is BoundType.NONEupperBoundType - type of bound for upperBound, or BoundType.NONE if there is no upper boundIllegalArgumentException - if lowerBoundType or upperBoundType is nullpublic T getLowerBound()
getLowerBoundType() returns BoundType.NONE.public T getUpperBound()
getUpperBoundType() returns BoundType.NONE.public BoundType getLowerBoundType()
getLowerBound().public BoundType getUpperBoundType()
getUpperBound().public Bounds<T> reverse()
Comparator is also used.public Bounds<T> withLowerBound(T newLowerBound, BoundType newLowerBoundType)
newLowerBound - new lower bound restriction value; ignored if newLowerBoundType is BoundType.NONEnewLowerBoundType - type of bound for newLowerBound, or BoundType.NONE if there is no lower boundIllegalArgumentException - if newLowerBoundType is nullpublic Bounds<T> withUpperBound(T newUpperBound, BoundType newUpperBoundType)
newUpperBound - new upper bound restriction value; ignored if newUpperBoundType is BoundType.NONEnewUpperBoundType - type of bound for newUpperBound, or BoundType.NONE if there is no upper boundIllegalArgumentException - if newUpperBoundType is nullpublic Bounds<T> withoutLowerBound()
public Bounds<T> withoutUpperBound()
public boolean isWithinLowerBound(Comparator<? super T> comparator, T value)
comparator - comparator used to compare values, or null for natural orderingvalue - value to checkvalue is within bounds, false otherwisepublic boolean isWithinUpperBound(Comparator<? super T> comparator, T value)
comparator - comparator used to compare values, or null for natural orderingvalue - value to checkvalue is within bounds, false otherwisepublic boolean isWithinBounds(Comparator<? super T> comparator, T value)
Equivalent to:
isWithinLowerBound(comparator, value) && isWithinUpperBound(comparator, value)
comparator - comparator used to compare values, or null for natural orderingvalue - value to checkvalue is within bounds, false otherwisepublic boolean isWithinBounds(Comparator<? super T> comparator, Bounds<? extends T> newBounds)
Bounds is within of the bounds of this instance.comparator - comparator used to compare values, or null for natural orderingnewBounds - new boundsnewBounds is in range, false otherwiseIllegalArgumentException - if newBounds is nullCopyright © 2016. All rights reserved.