public class Range extends Object
Modifier and Type | Field and Description |
---|---|
static Range |
BYTE_EVERYTHING
A range containing all possible 8-bit values.
|
static Range |
EVERYTHING
A range containing all possible 64-bit values.
|
long |
from
The lower bound of the interval, inclusive.
|
static Range |
INT_EVERYTHING
A range containing all possible 32-bit values.
|
static Range |
NOTHING
The empty range.
|
static Range |
SHORT_EVERYTHING
A range containing all possible 16-bit values.
|
long |
to
The upper bound of the interval, inclusive.
|
Constructor and Description |
---|
Range(long from,
long to)
Constructs a range with its bounds specified by two parameters,
from and to . |
Modifier and Type | Method and Description |
---|---|
Range |
bitwiseAnd(Range right)
We give up the analysis for bitwise AND operation
|
Range |
bitwiseComplement()
Returns the range of a variable that falls within this range after applying the bitwise
complement operation.
|
Range |
bitwiseOr(Range right)
We give up the analysis for bitwise OR operation
|
Range |
bitwiseXor(Range right)
We give up the analysis for bitwise XOR operation
|
Range |
byteRange()
Converts a this range to a 8-bit byte range.
|
boolean |
contains(long element)
Returns true if the element is contained in this range.
|
boolean |
contains(Range other)
Returns true if the element is contained in this range.
|
Range |
divide(Range right)
Returns the smallest range that includes all possible values resulting from dividing (integer
division) an arbitrary value in this range by an arbitrary value in the specified range.
|
boolean |
equals(Object obj) |
int |
hashCode() |
Range |
intersect(Range right)
Returns the smallest range that includes all values contained in both of the two ranges.
|
Range |
intRange()
Converts a this range to a 32-bit integral range.
|
boolean |
isEverything()
Return true if this range contains every
long value. |
boolean |
isNothing()
Return true if this range contains no values.
|
boolean |
isWiderThan(long value)
Determines if the range is wider than a given value, i.e., if the number of possible values
enclosed by this range is more than the given value.
|
boolean |
isWithin(long lb,
long ub)
Determines if this range is completely contained in the range specified by the given lower
bound and upper bound.
|
Range |
minus(Range right)
Returns the smallest range that includes all possible values resulting from subtracting an
arbitrary value in the specified range from an arbitrary value in this range.
|
Range |
plus(Range right)
Returns the smallest range that includes all possible values resulting from adding an
arbitrary value in the specified range to an arbitrary value in this range.
|
Range |
refineEqualTo(Range right)
Refines this range to reflect that some value in it can be equal to a value in the given
range.
|
Range |
refineGreaterThan(Range right)
Refines this range to reflect that some value in it can be greater than a value in the given
range.
|
Range |
refineGreaterThanEq(Range right)
Refines this range to reflect that some value in it can be greater than or equal to a value
in the given range.
|
Range |
refineLessThan(Range right)
Refines this range to reflect that some value in it can be less than a value in the given
range.
|
Range |
refineLessThanEq(Range right)
Refines this range to reflect that some value in it can be less than or equal to a value in
the given range.
|
Range |
remainder(Range right)
Returns a range that includes all possible values of the remainder of dividing an arbitrary
value in this range by an arbitrary value in the specified range.
|
Range |
shiftLeft(Range right)
Returns a range that includes all possible values resulting from left shifting an arbitrary
value in this range by an arbitrary number of bits in the specified range.
|
Range |
shortRange()
Converts a this range to a 16-bit short range.
|
Range |
signedShiftRight(Range right)
Returns a range that includes all possible values resulting from signed right shifting an
arbitrary value in this range by an arbitrary number of bits in the specified range.
|
Range |
times(Range right)
Returns the smallest range that includes all possible values resulting from multiplying an
arbitrary value in the specified range by an arbitrary value in this range.
|
String |
toString() |
Range |
unaryMinus()
Returns the range of a variable that falls within this range after applying the unary minus
operation.
|
Range |
unaryPlus()
Returns the range of a variable that falls within this range after applying the unary plus
operation (which is a no-op).
|
Range |
union(Range right)
Returns the smallest range that includes all values contained in either of the two ranges.
|
Range |
unsignedShiftRight(Range right)
We give up the analysis for unsigned shift right operation
|
public final long from
public final long to
public static final Range EVERYTHING
public static final Range INT_EVERYTHING
public static final Range SHORT_EVERYTHING
public static final Range BYTE_EVERYTHING
public static final Range NOTHING
public Range(long from, long to)
from
and to
.from
- the lower bound (inclusive)to
- the upper bound (inclusive)public boolean isEverything()
long
value.public boolean isNothing()
public Range intRange()
If this range is too wide, i.e., wider than the full range of the Integer class, return INT_EVERYTHING.
If the bounds of this range are not representable as 32-bit integers, convert the bounds to Integer type in accordance with Java overflow rules, e.g., Integer.MAX_VALUE + 1 is converted to Integer.MIN_VALUE.
public Range shortRange()
If this range is too wide, i.e., wider than the full range of the Short class, return SHORT_EVERYTHING.
If the bounds of this range are not representable as 16-bit integers, convert the bounds to Integer type in accordance with Java overflow rules, e.g., Short.MAX_VALUE + 1 is converted to Short.MIN_VALUE.
public Range byteRange()
If this range is too wide, i.e., wider than the full range of the Byte class, return BYTE_EVERYTHING.
If the bounds of this range are not representable as 8-bit integers, convert the bounds to Integer type in accordance with Java overflow rules, e.g., Byte.MAX_VALUE + 1 is converted to Byte.MIN_VALUE.
public boolean contains(long element)
public boolean contains(Range other)
public Range union(Range right)
right
- a range to union with this rangepublic Range intersect(Range right)
right
- the range to intersect with this rangepublic Range plus(Range right)
right
- a range to be added to this rangepublic Range minus(Range right)
right
- the range to be subtracted from this rangepublic Range times(Range right)
right
- the specified range to be multiplied by this rangepublic Range divide(Range right)
right
- the specified range by which this range is dividedpublic Range remainder(Range right)
In the current implementtation, the result might not be the smallest range that includes all the possible values.
right
- the specified range by which this range is dividedpublic Range shiftLeft(Range right)
right
- the range of bits by which this range is left shiftedpublic Range signedShiftRight(Range right)
right
- the range of bits by which this range is signed right shiftedpublic Range unsignedShiftRight(Range right)
public Range unaryPlus()
public Range unaryMinus()
public Range bitwiseComplement()
public Range refineLessThan(Range right)
@IntRange(from = 0, to = 10) int a;
@IntRange(from = 3, to = 7) int b;
...
if (a < b) {
// range of a is now refined to [0, 6] because a value in range [7, 10]
// cannot be smaller than variable b with range [3, 7].
...
}
Use the refineGreaterThanEq(Range)
method if you are also interested in refining the
range of b
in the code above.right
- the specified Range
to compare withRange
public Range refineLessThanEq(Range right)
@IntRange(from = 0, to = 10) int a;
@IntRange(from = 3, to = 7) int b;
...
if (a <= b) {
// range of a is now refined to [0, 7] because a value in range [8, 10]
// cannot be less than or equal to variable b with range [3, 7].
...
}
Use the refineGreaterThan(Range)
method if you are also interested in refining the
range of b
in the code above.right
- the specified Range
to compare withRange
public Range refineGreaterThan(Range right)
@IntRange(from = 0, to = 10) int a;
@IntRange(from = 3, to = 7) int b;
...
if (a > b) {
// range of a is now refined to [4, 10] because a value in range [0, 3]
// cannot be greater than variable b with range [3, 7].
...
}
Use the refineLessThanEq(Range)
method if you are also interested in refining the
range of b
in the code above.right
- the specified Range
to compare withRange
public Range refineGreaterThanEq(Range right)
@IntRange(from = 0, to = 10) int a;
@IntRange(from = 3, to = 7) int b;
...
if (a >= b) {
// range of a is now refined to [3, 10] because a value in range [0, 2]
// cannot be greater than or equal to variable b with range [3, 7].
...
}
Use the refineLessThan(Range)
method if you are also interested in refining the
range of b
in the code above.right
- the specified Range
to compare withRange
public Range refineEqualTo(Range right)
@IntRange(from = 0, to = 10) int a;
@IntRange(from = 3, to = 15) int b;
...
if (a == b) {
// range of a is now refined to [3, 10] because a value in range [0, 2]
// cannot be equal to variable b with range [3, 15].
...
}
right
- the specified Range
to compare withRange
public boolean isWiderThan(long value)
value
- the value to compare withpublic boolean isWithin(long lb, long ub)