org.jppf.utils
Class Range<T extends Comparable<T>>

java.lang.Object
  extended by org.jppf.utils.Range<T>
Type Parameters:
T - the type of values handled by this object.

public class Range<T extends Comparable<T>>
extends Object

Instances of this class represent a range of values.


Constructor Summary
Range(T value)
          Initialize this range with the specified single value used as both lower and upper bounds.
Range(T lower, T upper)
          Initialize this range with the specified lower and upper bounds.
 
Method Summary
 T getLower()
          Get the lower bound.
 T getUpper()
          Get the upper bound.
 boolean includes(Range<T> other)
          Determine whether this range is a superset of the specified other.
 Range<T> intersection(Range<T> other)
          Construct a Range that represents the intersection of this range and the other specified one.
 boolean intersects(Range<T> other)
          Determine whether this range and the specified one have at least one value in common.
 boolean isValueInRange(T value)
          Determine if the specified value is included in this range.
 Range<T> merge(Range<T> other)
          Construct a Range that is made of all values between the lowest lower bound and the highest upper bound of this range and the other specified range.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Range

public Range(T value)
Initialize this range with the specified single value used as both lower and upper bounds.

Parameters:
value - the value to use for the bounds.

Range

public Range(T lower,
             T upper)
Initialize this range with the specified lower and upper bounds.

Parameters:
lower - the lower bound.
upper - the upper bound.
Method Detail

isValueInRange

public boolean isValueInRange(T value)
Determine if the specified value is included in this range.

Parameters:
value - the value to check.
Returns:
true if the value is in range, false otherwise.

toString

public String toString()

Overrides:
toString in class Object

getLower

public T getLower()
Get the lower bound.

Returns:
the lower bound.

getUpper

public T getUpper()
Get the upper bound.

Returns:
the upper bound.

intersects

public boolean intersects(Range<T> other)
Determine whether this range and the specified one have at least one value in common.

Parameters:
other - the range to check against.
Returns:
true if and only if part of other overlaps this range.

includes

public boolean includes(Range<T> other)
Determine whether this range is a superset of the specified other.
More formally, this method returns true if other.lower >= this.lower and other.upper <= this.upper.

Parameters:
other - the range to check against.
Returns:
true if and only if this range includes all the values from other.

merge

public Range<T> merge(Range<T> other)
Construct a Range that is made of all values between the lowest lower bound and the highest upper bound of this range and the other specified range. This works even if the ranges are completely disjointed (i.e if this.intersects(other) == false)
This is equivalent to building a range object with its lower bound equal to min(this.lower, other.lower) and its upper bound equal to max(this.upper, other.upper)

Parameters:
other - the range to merge with.
Returns:
a new Range object that encompasses all values between the lowest lower bound and the highest upper bound, or a copy of this range if the other is null.

intersection

public Range<T> intersection(Range<T> other)
Construct a Range that represents the intersection of this range and the other specified one.
This is equivalent to building a range object with its lower bound equal to max(this.lower, other.lower) and its upper bound equal to min(this.upper, other.upper)

Parameters:
other - the range to check against.
Returns:
a Range object representing the intersection of 2 ranges, or null if other is null or the ranges are disjointed (i.e if this.intersects(other) == false).


Copyright © 2005-2010 JPPF Team.