javax.media.jai.util
Class Range

java.lang.Object
  extended byjavax.media.jai.util.Range
All Implemented Interfaces:
Serializable

public class Range
extends Object
implements 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 Integers 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.

Since:
JAI 1.1
See Also:
Serialized Form

Constructor Summary
Range(Class elementClass, Comparable minValue, boolean isMinIncluded, 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(Class elementClass, Comparable minValue, 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(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(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.
 Class getElementClass()
          Returns the Class of the elements of this Range.
 Comparable getMaxValue()
          Returns the maximum value of this Range.
 Comparable getMinValue()
          Returns the minimum value of this Range.
 int hashCode()
          Compute a hash code value for this Range object.
 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.
 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, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Range

public Range(Class elementClass,
             Comparable minValue,
             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:
IllegalArgumentException - if minValue and maxValue are both null, and elementClass is not one of the subclasses of Comparable.
IllegalArgumentException - if minValue is not the same Class as elementClass.
IllegalArgumentException - if maxValue is not the same Class as elementClass.

Range

public Range(Class elementClass,
             Comparable minValue,
             boolean isMinIncluded,
             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:
IllegalArgumentException - if minValue and maxValue are both null, and elementClass is not one of the subclasses of Comparable.
IllegalArgumentException - if minValue is not the same Class as elementClass.
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 Class getElementClass()
Returns the Class of the elements of this Range.


getMinValue

public Comparable getMinValue()
Returns the minimum value of this Range. Returns null if the Range is unbounded at this end.


getMaxValue

public Comparable getMaxValue()
Returns the maximum value of this Range. Returns null if the Range is unbounded at this end.


contains

public boolean contains(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:
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:
IllegalArgumentException - if the Class of the elements of the given Range is not the same as the Class of the elements of this Range.
IllegalArgumentException - if the given Range is null

intersects

public boolean intersects(Range range)
Returns true if this Range intersects the given Range.

Throws:
IllegalArgumentException - if the Class of the elements of the given Range is not the same as the Class of the elements of this Range.
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:
IllegalArgumentException - if the Class of the elements of the given Range is not the same as the Class of the elements of this Range.
IllegalArgumentException - if the given Range is null

intersect

public Range intersect(Range range)
Returns the intersection of this Range with the given Range.

Throws:
IllegalArgumentException - if the Class of the elements of the given Range is not the same as the Class of the elements of this Range.
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 Ranges, 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 Ranges 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:
IllegalArgumentException - if the Class of the elements of the given Range is not the same as the Class of the elements of this Range.

hashCode

public int hashCode()
Compute a hash code value for this Range object.

Returns:
a hash code value for this Range object.

equals

public boolean equals(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.


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 String toString()
Returns a String representation of this Range.