## javax.media.jai.util
Class Range

    java.lang.Object
      |
      +--javax.media.jai.util.Range

All Implemented Interfaces:
  java.io.Serializable

public class Range
extends java.lang.Object
implements java.io.Serializable

A class to represent ranges of values. A range is defined to contain all the values between the minimum and maximum values, where the minimum/maximum value can be considered either included or excluded from the range.

This example creates a range of `Integer`s whose minimum value is 1 and the maximum value is 5. The range is inclusive at both ends:

`Range intRange = new Range(Integer.class, new Integer(1), new Integer(5));`

A `Range` can be unbounded at either or both of its ends. An unbounded end is specified by passing null for the value of that end. A `Range` unbounded at both of its ends represents a range of all possible values for the `Class` of elements in that `Range`. The `isMinIncluded()` method will always return true for a `Range` unbounded on the minimum side and correspondingly the `isMaxIncluded()` method will always return true for a `Range` unbounded on the maximum side.

An empty range is defined as a `Range` whose minimum value is greater than it's maximum value if the ends are included, or as a `Range` whose minimum value is greater than or equal to it's maximum value, if the minimum or the maximum value is excluded.

See Also:
  Serialized Form

Constructor Summary
`Range(java.lang.Class elementClass, java.lang.Comparable minValue, boolean isMinIncluded, java.lang.Comparable maxValue, boolean isMaxIncluded)` Constructs a `Range` object given the `Class` of the elements in the `Range`, the minimum value and the maximum value.
`Range(java.lang.Class elementClass, java.lang.Comparable minValue, java.lang.Comparable maxValue)` Constructs a `Range` object given the `Class` of the elements in the `Range`, the minimum value and the maximum value.

Method Summary
`boolean` `contains(java.lang.Comparable value)` Returns true if the specified value is within this `Range`, i.e.
`boolean` `contains(Range range)` Returns true if the supplied `Range` is fully contained within this `Range`.
`boolean` `equals(java.lang.Object other)` Returns true if this `Range` and the given `Range` both have elements of the same `Class`, their minimum and maximum values are the same, and their isMinIncluded() and isMaxIncluded() methods return the same values.
`java.lang.Class` `getElementClass()` Returns the `Class` of the elements of this `Range`.
`java.lang.Comparable` `getMaxValue()` Returns the maximum value of this `Range`.
`java.lang.Comparable` `getMinValue()` Returns the minimum value of this `Range`.
`Range` `intersect(Range range)` Returns the intersection of this `Range` with the given `Range`.
`boolean` `intersects(Range range)` Returns true if this `Range` intersects the given `Range`.
`boolean` `isEmpty()` Returns true if this `Range` is empty, i.e.
`boolean` `isMaxIncluded()` Returns true if the maximum value is included within this `Range`.
`boolean` `isMinIncluded()` Returns true if the minimum value is included within this `Range`.
`Range[]` `subtract(Range range)` Returns the `Range` of values that are in this `Range` but not in the given `Range`.
`java.lang.String` `toString()` Returns a `String` representation of this `Range`.
`Range` `union(Range range)` Returns the union of this `Range` with the given `Range`.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### Range

    public Range(java.lang.Class elementClass,
                 java.lang.Comparable minValue,
                 java.lang.Comparable maxValue)

  Constructs a `Range` object given the `Class` of the elements in the `Range`, the minimum value and the maximum value. The minimum and the maximum value are considered inclusive.

  An unbounded range can be specified by passing in a null for either of the two values, in which case the `Range` is unbounded on one side, or for both, in which case the `Range` represents an all inclusive set.

  Parameters:
    `elementClass` - The `Class` of the `Range` elements.
    `minValue` - The lowest value included in the `Range`.
    `maxValue` - The highest value included in the `Range`.
  Throws:
    `java.lang.IllegalArgumentException` - if minValue and maxValue are both null, and elementClass is not one of the subclasses of `Comparable`.
    `java.lang.IllegalArgumentException` - if minValue is not the same `Class` as elementClass.
    `java.lang.IllegalArgumentException` - if maxValue is not the same `Class` as elementClass.

### Range

    public Range(java.lang.Class elementClass,
                 java.lang.Comparable minValue,
                 boolean isMinIncluded,
                 java.lang.Comparable maxValue,
                 boolean isMaxIncluded)

  Constructs a `Range` object given the `Class` of the elements in the `Range`, the minimum value and the maximum value. Whether the minimum value and the maximum value are considered inclusive is specified via the `isMinIncluded` and `isMaxIncluded` variables.

  An unbounded range can be specified by passing in a null for either of the two values, in which case the `Range` is unbounded at one end, or for both, in which case the `Range` represents an all inclusive set. If null is passed in for either variable, the `boolean` variables have no effect.

  Parameters:
    `elementClass` - The `Class` of the `Range` elements.
    `minValue` - The lowest value for the `Range`.
    `isMinIncluded` - A boolean that defines whether the minimum value is included in the `Range`.
    `maxValue` - The highest value for the `Range`.
    `isMaxIncluded` - A boolean that defines whether the maximum value is included in the `Range`.
  Throws:
    `java.lang.IllegalArgumentException` - if minValue and maxValue are both null, and elementClass is not one of the subclasses of `Comparable`.
    `java.lang.IllegalArgumentException` - if minValue is not the same `Class` as elementClass.
    `java.lang.IllegalArgumentException` - if maxValue is not the same `Class` as elementClass.

Method Detail

### isMinIncluded

    public boolean isMinIncluded()

  Returns true if the minimum value is included within this `Range`. If the range is unbounded at this end, this method will return true.

### isMaxIncluded

    public boolean isMaxIncluded()

  Returns true if the maximum value is included within this `Range`. If the range is unbounded at this end, this method will return true.

### getElementClass

    public java.lang.Class getElementClass()

  Returns the `Class` of the elements of this `Range`.

### getMinValue

    public java.lang.Comparable getMinValue()

  Returns the minimum value of this `Range`. Returns null if the `Range` is unbounded at this end.

### getMaxValue

    public java.lang.Comparable getMaxValue()

  Returns the maximum value of this `Range`. Returns null if the `Range` is unbounded at this end.

### contains

    public boolean contains(java.lang.Comparable value)

  Returns true if the specified value is within this `Range`, i.e. is either equal to or greater than the minimum value of this `Range` and is either lesser than or equal to the maximum value of this `Range`.
  Parameters:
    `value` - The value to be checked for being within this `Range`.
  Throws:
    `java.lang.IllegalArgumentException` - if the `Class` of the value parameter is not the same as the elementClass of this `Range`.

### contains

    public boolean contains(Range range)

  Returns true if the supplied `Range` is fully contained within this `Range`. Fully contained is defined as having the minimum and maximum values of the fully contained range lie within the range of values of the containing `Range`.
  Throws:
    `java.lang.IllegalArgumentException` - if the `Class` of the elements of the given `Range` is not the same as the `Class` of the elements of this `Range`.
    `java.lang.IllegalArgumentException` - if the given `Range` is null

### intersects

    public boolean intersects(Range range)

  Returns true if this `Range` intersects the given `Range`.
  Throws:
    `java.lang.IllegalArgumentException` - if the `Class` of the elements of the given `Range` is not the same as the `Class` of the elements of this `Range`.
    `java.lang.IllegalArgumentException` - if the given `Range` is null

### union

    public Range union(Range range)

  Returns the union of this `Range` with the given `Range`. If this `Range` and the given `Range` are disjoint, the `Range` returned as a result of the union will have a minimum value set to the minimum of the two disjoint range's minimum values, and the maximum set to the maximum of the two disjoint range's maximum values, thus including the disjoint range within it.
  Throws:
    `java.lang.IllegalArgumentException` - if the `Class` of the elements of the given `Range` is not the same as the `Class` of the elements of this `Range`.
    `java.lang.IllegalArgumentException` - if the given `Range` is null

### intersect

    public Range intersect(Range range)

  Returns the intersection of this `Range` with the given `Range`.
  Throws:
    `java.lang.IllegalArgumentException` - if the `Class` of the elements of the given `Range` is not the same as the `Class` of the elements of this `Range`.
    `java.lang.IllegalArgumentException` - if the given `Range` is null

### subtract

    public Range[] subtract(Range range)

  Returns the `Range` of values that are in this `Range` but not in the given `Range`. If the subtraction results in two disjoint `Range`s, they will be returned as two elements of a `Range` array, otherwise the resultant `Range` will be returned as the first element of a one element array. When this `Range` and the given `Range` are both unbounded at both the ends (i.e both the `Range`s are all inclusive), this method will return null as the first element of one element array, as a result of the subtraction. When this `Range` is completely contained in the given `Range`, an empty `Range` is returned.
  Throws:
    `java.lang.IllegalArgumentException` - if the `Class` of the elements of the given `Range` is not the same as the `Class` of the elements of this `Range`.

### equals

    public boolean equals(java.lang.Object other)

  Returns true if this `Range` and the given `Range` both have elements of the same `Class`, their minimum and maximum values are the same, and their isMinIncluded() and isMaxIncluded() methods return the same values. If this `Range` and the given `Range` are both empty and the `Class` of their elements is the same, they will be found to be equal and true will be returned.
  Overrides:
    `equals` in class `java.lang.Object`

### isEmpty

    public boolean isEmpty()

  Returns true if this `Range` is empty, i.e. if the minimum value is greater than the maximum value, if both are included, or if the minimum value is greater than equal to the maximum value if either the minimum or maximum value is excluded.

### toString

    public java.lang.String toString()

  Returns a `String` representation of this `Range`.
  Overrides:
    `toString` in class `java.lang.Object`