wt.util.range
Class Range

java.lang.Object
  extended bywt.util.range.Range
All Implemented Interfaces:
Serializable

public class Range
extends Object
implements Serializable

A Range is defined by its end-points (this is effectively a one-dimensional range). A value falls "in the range" if it is "above" the lower bound and "below" the upper bound. Determination of above/below is done using the boundary point values' int compareTo(Object value) method. Whether or not a boundary point is inclusive or exclusive depends upon the choice of BoundaryPoint. Ranges need not be bounded of both ends.

Design Note

To achieve genericism, the boundary point values and values you are checking to see if they're in the range must all be Comparable. Additionally, you should be careful to make sure that the Comparables you use are compatible with eachother. In general, you should use Comparables that share a common [inheritance] ancestor, so that the method int compareTo(Object value) can return something useful.

See Also:
InclusiveBelowBoundaryPoint, InclusiveAboveBoundaryPoint, InfiniteBoundaryPoint, Serialized Form

Field Summary
private static String CLASSNAME
           
private  BoundaryPoint lowerBound_
           
(package private)  Range range_
           
private static String RESOURCE
           
private  BoundaryPoint upperBound_
           
 
Constructor Summary
Range(BoundaryPoint lower_bound, BoundaryPoint upper_bound)
          Create an instance of a range from two boundary points.
 
Method Summary
private  void checkBoundaryPointOrdering()
          Confirms that the lower bound is indeed below the upper bound.
 boolean contains(Comparable comparable)
          Determines if the the supplied value is "in the range." What this means depends upon the boundary points that are supplied as the end points.
 boolean equals(Object other)
           
 Comparable getLowerBoundValue()
          Gets the Comparable value that is used as the lower boundary point of the range.
 Comparable getUpperBoundValue()
          Gets the Comparable value that is used as the upper boundary point of the range.
 boolean hasLowerBound()
          Determine if the range is bounded "below."
 boolean hasUpperBound()
          Determine if the range is bounded "above."
 boolean isLowerBoundExclusive()
          return lowerBound_ instanceof InclusiveBelowBoundaryPoint;
 boolean isLowerBoundInclusive()
          Determine if the lower bound is an instance of InclusiveAboveBoundaryPoint.
 boolean isUpperBoundExclusive()
          Determine if the upper bound is an instance of InclusiveBelowBoundaryPoint.
 boolean isUpperBoundInclusive()
          Determine if the upper bound is an instance of InclusiveBelowBoundaryPoint.
static Range newExcludeLowExcludeHigh(Comparable low, Comparable high)
          Create an instance that operates conceptually as: (low, high)
static Range newExcludeLowIncludeHigh(Comparable low, Comparable high)
          Create an instance that operates conceptually as: (low, high]
static Range newExcludeLowUnboundedHigh(Comparable low)
          Create an instance that operates conceptually as: (low, infinity)
static Range newIncludeLowExcludeHigh(Comparable low, Comparable high)
          Create an instance that operates conceptually as: [low, high)
static Range newIncludeLowIncludeHigh(Comparable low, Comparable high)
          Create an instance that operates conceptually as: [low, high]
static Range newIncludeLowUnboundedHigh(Comparable low)
          Create an instance that operates conceptually as: [low, infinity)
static Range newParameterized(Comparable low, boolean low_inclusive, Comparable high, boolean high_inclusive)
           
static Range newUnboundedLowExcludeHigh(Comparable high)
          Create an instance that operates conceptually as: (-infinity, high)
static Range newUnboundedLowIncludeHigh(Comparable high)
          Create an instance that operates conceptually as: (-infinity, high]
 String toString()
          Produces a string that compactly describes the range.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

CLASSNAME

private static final String CLASSNAME

lowerBound_

private BoundaryPoint lowerBound_

upperBound_

private BoundaryPoint upperBound_

range_

Range range_
Constructor Detail

Range

public Range(BoundaryPoint lower_bound,
             BoundaryPoint upper_bound)
      throws RangeException
Create an instance of a range from two boundary points.

Parameters:
lower_bound -
upper_bound -
Throws:
RangeException
See Also:
BoundaryPoint
Method Detail

checkBoundaryPointOrdering

private void checkBoundaryPointOrdering()
                                 throws RangeException
Confirms that the lower bound is indeed below the upper bound.

Throws:
RangeException - if the check fails

contains

public final boolean contains(Comparable comparable)
Determines if the the supplied value is "in the range." What this means depends upon the boundary points that are supplied as the end points. The value will be in the range if lower bound answers true that it is below the value and the upper bound answers true that is is above the value.

Parameters:
comparable -
Returns:
boolean
Throws:
RangeException - If either of the boundary points is null

hasLowerBound

public final boolean hasLowerBound()
Determine if the range is bounded "below."

Returns:
boolean

hasUpperBound

public final boolean hasUpperBound()
Determine if the range is bounded "above."

Returns:
boolean

isLowerBoundInclusive

public final boolean isLowerBoundInclusive()
Determine if the lower bound is an instance of InclusiveAboveBoundaryPoint.

Returns:
boolean

isLowerBoundExclusive

public final boolean isLowerBoundExclusive()
return lowerBound_ instanceof InclusiveBelowBoundaryPoint;

Returns:
boolean

isUpperBoundInclusive

public final boolean isUpperBoundInclusive()
Determine if the upper bound is an instance of InclusiveBelowBoundaryPoint.

Returns:
boolean

isUpperBoundExclusive

public final boolean isUpperBoundExclusive()
Determine if the upper bound is an instance of InclusiveBelowBoundaryPoint.

Returns:
boolean

getLowerBoundValue

public final Comparable getLowerBoundValue()
Gets the Comparable value that is used as the lower boundary point of the range.

Returns:
Comparable returns null if there is no upper bound. Use hasLowerBound() before invoking
See Also:
hasLowerBound()

getUpperBoundValue

public final Comparable getUpperBoundValue()
Gets the Comparable value that is used as the upper boundary point of the range.

Returns:
Comparable returns null if there is no upper bound. Use hasUpperBound() before invoking
See Also:
hasUpperBound()

toString

public String toString()
Produces a string that compactly describes the range. The endpoint comparable values are rendered via their toString() methods. Mathematic range notation is used. Possible ranges are:

If the inclusive-ness of boundary point cannot be determined (most likely because it is a custom subclass of BoundaryPoint), then a question mark will replace the parenthesis or square-bracket.

Returns:
String

newIncludeLowIncludeHigh

public static Range newIncludeLowIncludeHigh(Comparable low,
                                             Comparable high)
                                      throws RangeException
Create an instance that operates conceptually as: [low, high]

Parameters:
low -
high -
Returns:
Range
Throws:
RangeException

newIncludeLowExcludeHigh

public static Range newIncludeLowExcludeHigh(Comparable low,
                                             Comparable high)
                                      throws RangeException
Create an instance that operates conceptually as: [low, high)

Parameters:
low -
high -
Returns:
Range
Throws:
RangeException

newExcludeLowIncludeHigh

public static Range newExcludeLowIncludeHigh(Comparable low,
                                             Comparable high)
                                      throws RangeException
Create an instance that operates conceptually as: (low, high]

Parameters:
low -
high -
Returns:
Range
Throws:
RangeException

newExcludeLowExcludeHigh

public static Range newExcludeLowExcludeHigh(Comparable low,
                                             Comparable high)
                                      throws RangeException
Create an instance that operates conceptually as: (low, high)

Parameters:
low -
high -
Returns:
Range
Throws:
RangeException

newIncludeLowUnboundedHigh

public static Range newIncludeLowUnboundedHigh(Comparable low)
                                        throws RangeException
Create an instance that operates conceptually as: [low, infinity)

Parameters:
low -
Returns:
Range
Throws:
RangeException

newExcludeLowUnboundedHigh

public static Range newExcludeLowUnboundedHigh(Comparable low)
                                        throws RangeException
Create an instance that operates conceptually as: (low, infinity)

Parameters:
low -
Returns:
Range
Throws:
RangeException

newUnboundedLowIncludeHigh

public static Range newUnboundedLowIncludeHigh(Comparable high)
                                        throws RangeException
Create an instance that operates conceptually as: (-infinity, high]

Parameters:
high -
Returns:
Range
Throws:
RangeException

newUnboundedLowExcludeHigh

public static Range newUnboundedLowExcludeHigh(Comparable high)
                                        throws RangeException
Create an instance that operates conceptually as: (-infinity, high)

Parameters:
high -
Returns:
Range
Throws:
RangeException

newParameterized

public static Range newParameterized(Comparable low,
                                     boolean low_inclusive,
                                     Comparable high,
                                     boolean high_inclusive)
                              throws RangeException
Throws:
RangeException

equals

public boolean equals(Object other)