com.rubecula.util
Class Range

java.lang.Object
  extended bycom.rubecula.util.Range

public class Range
extends java.lang.Object

Class for handling ranges of integers.

Version:
$Revision: 1.2 $
Author:
Robin Hillyard

Field Summary
protected  int _End
          The end of the range.
protected  int _Start
          The start of the range.
static Range $ALL
           
static Range $NEG
           
static Range $NONNEG
           
static Range $NONPOS
           
static Range $POS
           
static Range $ZERO
           
 
Constructor Summary
Range(int start)
          Construct a single-valued range from start to start.
Range(int start, int end)
          Construct a range from start to end.
 
Method Summary
 int getEnd()
          Method to get the end of this Range.
 int getStart()
          Method to get the start of this Range.
 boolean includes(int value)
          Determine whether this range includes the value given.
 Range intersection(Range that)
          Yield the intersection of this range and that range.
 boolean isValid()
          Method to determine if this range is valid, i.e. non-empty.
 int length()
          Get the length of this Range.
 java.lang.String substring(java.lang.String source)
          Yield a substring of the source by including only those characters whose positions in the string correspond to valid values in this range.
 Range union(Range that)
          Yield the union of this range and that range.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

$POS

public static final Range $POS

$NEG

public static final Range $NEG

$ZERO

public static final Range $ZERO

$NONNEG

public static final Range $NONNEG

$NONPOS

public static final Range $NONPOS

$ALL

public static final Range $ALL

_Start

protected final int _Start
The start of the range.


_End

protected final int _End
The end of the range.

Constructor Detail

Range

public Range(int start,
             int end)
Construct a range from start to end.

Parameters:
start - the first valid integer in the range.
end - the last valid integer in the range.

Range

public Range(int start)
Construct a single-valued range from start to start.

Parameters:
start - the only valid integer in the range.
Method Detail

includes

public boolean includes(int value)
Determine whether this range includes the value given.

Parameters:
value - the integer to be tested against the range.
Returns:
true if value falls between the start and end of the range (inclusive).

substring

public java.lang.String substring(java.lang.String source)
Yield a substring of the source by including only those characters whose positions in the string correspond to valid values in this range.

Parameters:
source - the string to be substringed.
Returns:
a substring whose length equals end range - start range + 1.

isValid

public boolean isValid()
Method to determine if this range is valid, i.e. non-empty.

Returns:
true if this range is not empty.

intersection

public Range intersection(Range that)
Yield the intersection of this range and that range.

Parameters:
that - a range which is to be intersected with this.
Returns:
a range which runs from the maximum of the two start values through the minimum of the two end values.

union

public Range union(Range that)
Yield the union of this range and that range.

Parameters:
that - a range which is to be unioned with this.
Returns:
a range which runs from the minimum of the two start values through the maximum of the two end values.

length

public int length()
Get the length of this Range.

Returns:
if isValid, then _End - _Start + 1; else 0.

getStart

public int getStart()
Method to get the start of this Range.

Returns:
_Start.

getEnd

public int getEnd()
Method to get the end of this Range.

Returns:
_End.