PIRL.Utilities

## Class Real_Range

- java.lang.Object
- - PIRL.Utilities.Real_Range

All Implemented Interfaces:
  Cloneable

    public class Real_Range
    extends Object
    implements Cloneable

A Real_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 double` `Maximum` The range maximum value.
`protected double` `Minimum` The range minimum value.

### Constructor Summary

Constructors
Constructor and Description
`Real_Range()` Constructs a default Real_Range.
`Real_Range(double value)` Constructs a single-valued Real_Range.
`Real_Range(double minimum, double maximum)` Constructs a Real_Range from limiting values.
`Real_Range(Integer_Range range)` Constructs a Real_Range from an Integer_Range.
`Real_Range(Real_Range range)` Constructs a Real_Range as a copy of another Real_Range.

### Method Summary

Methods
`Object` `clone()` Clones this Real_Range.
`double` `Distance()` Gets the distance between the range limits.
`boolean` `equals(Real_Range range)` Compares two Real_Ranges for equality.
`int` `hashCode()` Gets a hash code for this Real_Range.
`boolean` `Is_Open_Ended()` Tests if the Real_Range is open-ended.
`boolean` `Is_Single_Valued()` Tests if the range is for a single value.
`double` `Maximum()` Gets the maximum limit value.
`Real_Range` `Maximum(double maximum)` Sets the maximum range value.
`double` `Minimum()` Gets the minimum range value.
`Real_Range` `Minimum(double minimum)` Sets the minimum range value.
`Real_Range` `Range(double minimum, double maximum)` Sets the Range minimum and maximum.
`Real_Range` `Range(Integer_Range range)` Sets the range from an Integer_Range.
`Real_Range` `Range(Real_Range range)` Sets the range from another Real_Range.
`String` `toString()` Provides a String representation of the Real_Range.
`Real_Range` `Value(double 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 double Minimum

The range minimum value.

#### Maximum

    protected double Maximum

The range maximum value.

### Constructor Detail

#### Real_Range

    public Real_Range()

Constructs a default Real_Range.

The range values are initialized to zero.

#### Real_Range

    public Real_Range(double minimum,
              double maximum)

Constructs a Real_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.

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

#### Real_Range

    public Real_Range(double value)

Constructs a single-valued Real_Range.

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

#### Real_Range

    public Real_Range(Real_Range range)

Constructs a Real_Range as a copy of another Real_Range.

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

#### Real_Range

    public Real_Range(Integer_Range range)

Constructs a Real_Range from an Integer_Range.

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

### Method Detail

#### clone

    public Object clone()

Clones this Real_Range.

Overrides:
  `clone` in class `Object`
Returns:
  A Real_Range constructed as a copy of this Real_Range.

#### Range

    public Real_Range Range(double minimum,
                   double 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 Real_Range.
See Also:
  `Minimum(double)`, `Maximum(double)`

#### Range

    public Real_Range Range(Real_Range range)

Sets the range from another Real_Range.

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

Parameters:
  `range` - The Real_Range to be copied. If null nothing is done.
Returns:
  This Real_Range.

#### Range

    public Real_Range Range(Integer_Range range)

Sets the range from an Integer_Range.

Long.MIN_VALUE and Long.MAX_VALUE from the Integer_Range are reset to Double.MIN_VALUE and Double.MAX_VALUE respectively.

Parameters:
  `range` - The Integer_Range limits.
Returns:
  This Real_Range.
See Also:
  `Minimum(double)`, `Maximum(double)`

#### Minimum

    public double Minimum()

Gets the minimum range value.

Returns:
  The minimum range value.

#### Minimum

    public Real_Range Minimum(double 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 Real_Range.

#### Maximum

    public double Maximum()

Gets the maximum limit value.

Returns:
  The maximum limit value.

#### Maximum

    public Real_Range Maximum(double maximum)

Sets the maximum range value.

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

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

#### Is_Open_Ended

    public boolean Is_Open_Ended()

Tests if the Real_Range is open-ended.

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

#### Distance

    public double Distance()

Gets the distance between the range limits.

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

#### 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 Real_Range Value(double 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 Real_Range.
See Also:
  `Minimum(double)`, `Maximum(double)`

#### equals

    public boolean equals(Real_Range range)

Compares two Real_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 Real_Range.

The result is the upper 16 bits of the hash code of the range minimum as a Double concatenated with the upper 16 bits of the hash code of the range maximum as a Double. That is, the hash code is the value of the expression:

> (new Double (Minimum ()).hashCode () & 0xFFFF0000) | (new Double (Maximum ()).hashCode () >>> 16)

Overrides:
  `hashCode` in class `Object`

#### toString

    public String toString()

Provides a String representation of the Real_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 `Double.MIN_VALUE` or the maximum is `Double.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 `Double.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 if both both limits are open-ended.

Overrides:
  `toString` in class `Object`
Returns:
  A String representation of the Real_Range.