public final class Scope<T extends Comparable<? super T>> extends Object
The lower bound of a range must be less than or equal to the upper bound of the range.
This requires that the objects in a Scope must be comparable.
| 构造器 | 说明 |
|---|---|
Scope(T lowerObj,
T upperObj) |
A constructor used to create a
Scope instance with the lower and upper bounds specified. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
T |
clamp(T value) |
Clamps a given
value to the current range. |
boolean |
contains(Scope<T> range) |
Checks whether a given
range is within the current range. |
boolean |
contains(T value) |
Checks whether a given
value is within the current range. |
static <T extends Comparable<? super T>> |
create(T lowerObj,
T upperObj) |
Creates a range whose data type is the same as the input parameters.
|
boolean |
equals(Object obj) |
Checks whether a given object is equal to the current range.
|
Scope<T> |
expand(Scope<T> range) |
Creates the smallest range that includes the current range and a given range.
|
Scope<T> |
expand(T value) |
Creates the smallest range that includes the current range and a given value.
|
Scope<T> |
expand(T lowerObj,
T upperObj) |
Creates the smallest range that includes the current range and the given lower and upper bounds.
|
T |
getLower() |
Obtains the lower bound of the current range.
|
T |
getUpper() |
Obtains the upper bound of the current range.
|
int |
hashCode() |
Obtains the hash code value of the current range.
|
Scope<T> |
intersect(Scope<T> range) |
Returns the intersection of a given range and the current range.
|
Scope<T> |
intersect(T lowerObj,
T upperObj) |
Returns the intersection of the current range and the range specified by the given lower and upper bounds.
|
String |
toString() |
Obtains a string representation of the current range.
|
public Scope(T lowerObj, T upperObj)
Scope instance with the lower and upper bounds specified.lowerObj - Indicates the lower bound of the Scope instance.upperObj - Indicates the upper bound of the Scope instance.NullPointerException - Throws this exception if lowerObj or upperObj is null.IllegalArgumentException - Throws this exception if lowerObj is bigger than upperObj.public static <T extends Comparable<? super T>> Scope<T> create(T lowerObj, T upperObj)
The data type of input parameters must be comparable.
lowerObj - Indicates the lower bound of the Scope instance.upperObj - Indicates the upper bound of the Scope instance.NullPointerException - Throws this exception if lowerObj or upperObj is null.IllegalArgumentException - Throws this exception if lowerObj is bigger than upperObj.public T getLower()
public T getUpper()
public T clamp(T value)
value to the current range.
The given value is returned if it is within the range. The lower bound is
returned if the given value is less than the lower bound; and the upper bound is
returned if the given value is greater than the upper bound.
value - Indicates the value to clamp.NullPointerException - Throws this exception if value is null.public boolean contains(T value)
value is within the current range.
A value is within a range if it is greater than or equal to the lower bound and less than or equal to the upper bound of the range.
value - Indicates the value to check.true if the given value is within the range; returns false otherwise.NullPointerException - Throws this exception if value is null.public boolean contains(Scope<T> range)
range is within the current range.
The given range is within the current range if its lower bound is greater than or equal to the lower bound of the current range and its upper bound is less than or equal to the upper bound of the current range.
range - Indicates the range to check.true if the given range is within the current range; returns false otherwise.NullPointerException - Throws this exception if range is null.public Scope<T> expand(Scope<T> range)
The lower bound of the range to create is the smaller value between the lower bound of the current range and that of the given range. The upper bound of the range to create is the larger value between the upper bound of the current range and that of the given range.
range - Indicates the range used together with the current range to create their extension.NullPointerException - Throws this exception if range is null.IllegalArgumentException - Throws this exception if lowerObj is bigger than upperObj.public Scope<T> expand(T lowerObj, T upperObj)
The lower bound of the range to create is the smaller value between the lower bound of the current range and the given lower bound. The upper bound of the range to create is the larger value between the upper bound of the current range and the given upper bound.
lowerObj - Indicates the lower bound.upperObj - Indicates the upper bound.NullPointerException - Throws this exception if lowerObj or upperObj is null.IllegalArgumentException - Throws this exception if lowerObj is bigger than upperObj.public Scope<T> expand(T value)
The lower bound of the range to create is the smaller value between the lower bound of the current range and the given value. The upper bound of the range to create is the larger value between the upper bound of the current range and the given value.
value - Indicates the given value.NullPointerException - Throws this exception if value is null.IllegalArgumentException - Throws this exception if lowerObj is bigger than upperObj.public Scope<T> intersect(Scope<T> range)
range - Indicates the given range.NullPointerException - Throws this exception if range is null.IllegalArgumentException - Throws this exception if the two ranges have no intersection.public Scope<T> intersect(T lowerObj, T upperObj)
lowerObj - Indicates the lower bound.upperObj - Indicates the upper bound.NullPointerException - Throws this exception if lowerObj or upperObj is null.IllegalArgumentException - Throws this exception if the two ranges have no intersection.public boolean equals(Object obj)
equals 在类中 Objectobj - Indicates the range object to compare.true if the given object is equal to the current range; returns false otherwise.Object.hashCode(),
HashMappublic int hashCode()
hashCode 在类中 ObjectObject.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)