PIRL.Utilities

## Class Integer_Range

- java.lang.Object
- - PIRL.Utilities.Integer_Range

All Implemented Interfaces:
  Cloneable

    public class Integer_Range
    extends Object
    implements Cloneable

An Integer_Range specifies a range of integer values.

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.

### Field Summary

Fields
`static String` `ID`
`protected long` `Maximum` The range maximum value.
`protected long` `Minimum` The range minimum value.

### Constructor Summary

Constructors
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.

### Method Summary

Methods
`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.

### Methods inherited from class java.lang.Object

`equals, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### ID

    public static final String ID

See Also:
  Constant Field Values

#### Minimum

    protected long Minimum

The range minimum value.

#### Maximum

    protected long Maximum

The range maximum value.

### Constructor Detail

#### Integer_Range

    public Integer_Range()

Constructs a default Integer_Range.

The range values are initialized to zero.

#### Integer_Range

    public Integer_Range(long minimum,
                 long maximum)

Constructs an Integer_Range from limiting values.

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`.

Parameters:
  `minimum` - The minimum inclusive limit value of the range.
  `maximum` - The maximum inclusive limit value of the range.
See Also:
  `Range(long, long)`

#### Integer_Range

    public Integer_Range(long value)

Constructs a single-valued Integer_Range.

Parameters:
  `value` - The value of the range.
See Also:
  `Value(long)`

#### Integer_Range

    public Integer_Range(Integer_Range range)

Constructs an Integer_Range as a copy of another Integer_Range.

Parameters:
  `range` - The Integer_Range to be copied. If null a default Integer_Range is constructed.
See Also:
  `Range(Integer_Range)`

#### Integer_Range

    public Integer_Range(Real_Range range)

Constructs an Integer_Range from a Real_Range.

The values of the specified range are truncated and clipped to the Long.MIN_VALUE and Long.MAX_VALUE values.

Parameters:
  `range` - The Real_Range to be copied. If null a default Integer_Range is constructed.
See Also:
  `Range(Real_Range)`

### Method Detail

#### clone

    public Object clone()

Clones this Integer_Range.

Overrides:
  `clone` in class `Object`
Returns:
  An Integer_Range constructed as a copy of this Integer_Range.

#### Range

    public Integer_Range Range(long minimum,
                      long maximum)

Sets the range minimum and maximum.

Note: If the minimum is greater than the maximum then it is used as the maximum and the maximum used as the minimum.

Parameters:
  `minimum` - The minimum inclusive value of the range.
  `maximum` - The maximum inclusive value of the range.
Returns:
  This Integer_Range.
See Also:
  `Minimum(long)`, `Maximum(long)`

#### Range

    public Integer_Range Range(Integer_Range range)

Sets the range from another Integer_Range.

N.B.: The values of the source range are copied without checking.

Parameters:
  `range` - The Integer_Range to copy. If null, nothing is done.
Returns:
  This Integer_Range.

#### Range

    public Integer_Range Range(Real_Range range)

Sets the range from a Real_Range.

The values of the Real_Range are truncated (not rounded) and clipped to the Long.MIN_VALUE and Long.MAX_VALUE values.

Parameters:
  `range` - The Real_Range to be copied. If null nothing is done.
Returns:
  This Integer_Range.
See Also:
  `Minimum(long)`, `Maximum(long)`

#### Minimum

    public long Minimum()

Gets the minimum range value.

Returns:
  The minimum range value.

#### Minimum

    public Integer_Range Minimum(long minimum)

Sets the minimum range value.

If the new minimum value is greater than the current `maximum` value, the maximum is reset to the new minimum.

Parameters:
  `minimum` - The minimum range value.
Returns:
  This Integer_Range.

#### Maximum

    public long Maximum()

Gets the maximum range value.

Returns:
  The maximum range value.

#### Maximum

    public Integer_Range Maximum(long maximum)

Sets the maximum range value.

If the new maximum range value is less than the current `minimum` value, the minimum is reset to the new maximum.

Parameters:
  `maximum` - The maximum range value.
Returns:
  This Integer_Range.

#### Distance

    public long Distance()

Gets the distance between the range values.

Returns:
  The difference between the maximum and minimum limit values, or Long.MAX_VALUE if the range is `open-ended`.

#### Is_Open_Ended

    public boolean Is_Open_Ended()

Tests if the range is open-ended.

Returns:
  true If either the `minimum` is `Long.MIN_VALUE` or the `maximum` is `Long.MAX_VALUE`.

#### Is_Single_Valued

    public boolean Is_Single_Valued()

Tests if the range is for a single value.

For a single valued range the `minimum` and `maximum` values are identical.

Returns:
  true if the range only has a single value; false otherwise.

#### Value

    public Integer_Range Value(long value)

Sets the range to a single value.

Both the minimum and maximum are set to the value.

Parameters:
  `value` - The single value for the range.
Returns:
  This Integer_Range.
See Also:
  `Minimum(long)`, `Maximum(long)`

#### equals

    public boolean equals(Integer_Range range)

Compares two Integer_Ranges for equality.

The two ranges are equal if, and only if, the argument is not null and the `minimum` and `maximum` values of the ranges are equal.

#### hashCode

    public int hashCode()

Gets a hash code for this Integer_Range.

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)

Overrides:
  `hashCode` in class `Object`

#### toString

    public String toString()

Provides a String representation of the Integer_Range.

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.

Overrides:
  `toString` in class `Object`
Returns:
  A String representation of the Integer_Range.
See Also:
  `Minimum()`, `Maximum()`