public class Integer_Range extends Object implements Cloneable
The range of values is characterized by minimum and maximum values that identify the inclusive limits of the range. Single-valued and open-ended ranges are defined. An appropriate String representation is provided.
Modifier and Type | Field and Description |
---|---|
static String |
ID |
protected long |
Maximum
The range maximum value.
|
protected long |
Minimum
The range minimum value.
|
Constructor and Description |
---|
Integer_Range()
Constructs a default Integer_Range.
|
Integer_Range(Integer_Range range)
Constructs an Integer_Range as a copy of another Integer_Range.
|
Integer_Range(long value)
Constructs a single-valued Integer_Range.
|
Integer_Range(long minimum,
long maximum)
Constructs an Integer_Range from limiting values.
|
Integer_Range(Real_Range range)
Constructs an Integer_Range from a Real_Range.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Clones this Integer_Range.
|
long |
Distance()
Gets the distance between the range values.
|
boolean |
equals(Integer_Range range)
Compares two Integer_Ranges for equality.
|
int |
hashCode()
Gets a hash code for this Integer_Range.
|
boolean |
Is_Open_Ended()
Tests if the range is open-ended.
|
boolean |
Is_Single_Valued()
Tests if the range is for a single value.
|
long |
Maximum()
Gets the maximum range value.
|
Integer_Range |
Maximum(long maximum)
Sets the maximum range value.
|
long |
Minimum()
Gets the minimum range value.
|
Integer_Range |
Minimum(long minimum)
Sets the minimum range value.
|
Integer_Range |
Range(Integer_Range range)
Sets the range from another Integer_Range.
|
Integer_Range |
Range(long minimum,
long maximum)
Sets the range minimum and maximum.
|
Integer_Range |
Range(Real_Range range)
Sets the range from a Real_Range.
|
String |
toString()
Provides a String representation of the Integer_Range.
|
Integer_Range |
Value(long value)
Sets the range to a single value.
|
public static final String ID
protected long Minimum
protected long Maximum
public Integer_Range()
The range values are initialized to zero.
public Integer_Range(long minimum, long maximum)
Note: If the minimum is greater than the maximum then it is used as the maximum and the maximum used as the minimum.
A range is open ended
if either the minimum
is Long.MIN_VALUE
or the maximum is Long.MAX_VALUE
.
minimum
- The minimum inclusive limit value of the range.maximum
- The maximum inclusive limit value of the range.Range(long, long)
public Integer_Range(long value)
value
- The value of the range.Value(long)
public Integer_Range(Integer_Range range)
range
- The Integer_Range to be copied. If null a default
Integer_Range is constructed.Range(Integer_Range)
public Integer_Range(Real_Range range)
The values of the specified range are truncated and clipped to the Long.MIN_VALUE and Long.MAX_VALUE values.
range
- The Real_Range to be copied. If null a default
Integer_Range is constructed.Range(Real_Range)
public Object clone()
public Integer_Range Range(long minimum, long maximum)
Note: If the minimum is greater than the maximum then it is used as the maximum and the maximum used as the minimum.
minimum
- The minimum inclusive value of the range.maximum
- The maximum inclusive value of the range.Minimum(long)
,
Maximum(long)
public Integer_Range Range(Integer_Range range)
N.B.: The values of the source range are copied without checking.
range
- The Integer_Range to copy. If null, nothing is done.public Integer_Range Range(Real_Range range)
The values of the Real_Range are truncated (not rounded) and clipped to the Long.MIN_VALUE and Long.MAX_VALUE values.
range
- The Real_Range to be copied. If null nothing is done.Minimum(long)
,
Maximum(long)
public long Minimum()
public Integer_Range Minimum(long minimum)
If the new minimum value is greater than the current maximum
value, the maximum is reset to the new minimum.
minimum
- The minimum range value.public long Maximum()
public Integer_Range Maximum(long maximum)
If the new maximum range value is less than the current minimum
value, the minimum is reset to the new maximum.
maximum
- The maximum range value.public long Distance()
open-ended
.public boolean Is_Open_Ended()
minimum
is
Long.MIN_VALUE
or the maximum
is
Long.MAX_VALUE
.public boolean Is_Single_Valued()
For a single valued range the minimum
and
maximum
values are identical.
public Integer_Range Value(long value)
Both the minimum and maximum are set to the value.
value
- The single value for the range.Minimum(long)
,
Maximum(long)
public boolean equals(Integer_Range range)
public int hashCode()
The result is the upper 16 bits of the hash code of the range minimum as a Long concatenated with the upper 16 bits of the hash code of the range maximum as a Long. That is, the hash code is the value of the expression:
(new Long (Minimum ()).hashCode () & 0xFFFF0000) | (new Long (Maximum ()).hashCode () >>> 16)
public String toString()
The format of the Integer_Range representation is:
minimum-maximum
If the minimum and maximum are identical then only a single value is represented.
If the minimum is not Long.MIN_VALUE
or the maximum is Long.MAX_VALUE
then the minimum value is represented. Then a dash
('-') delimiter is provided regardless of whether the minimum is
represented or not. If the maximum is not Long.MAX_VALUE
then it is included in the representation after the '-' delimiter.
Note that a range may be open-ended at its minimum or maximum, but
in all cases at least one limit value will be represented with the
minimum value being used ifthe range is double open-ended.