edu.cmu.sun.folds
Class IndexRange

java.lang.Object
  extended by edu.cmu.sun.folds.IndexRange

public class IndexRange
extends java.lang.Object

This represents a range of indexes. The range can have a size of 0, which means that it is empty. The range also return the type of overlap and distance that exists between index ranges. Note, the IndexRange object is mutable.

Author:
Braden Kowitz

Nested Class Summary
static class IndexRange.Overlap
          An overlap describes the type and distance of overlap between two ranges.
 
Field Summary
protected  int position
          Position of the start of the range.
protected  int size
          The size of the range, in number of items.
 
Constructor Summary
IndexRange(IndexRange range)
           
IndexRange(int position, int size)
          Create a new IndexRange
 
Method Summary
 boolean encompassesIndex(int p)
           
 int getEnd()
           
 IndexRange.Overlap getOverlap(IndexRange r)
          Get the overlap between this range and another.
static IndexRange.Overlap getOverlap(IndexRange r1, IndexRange r2)
          Determines the overlap between two ranges.
 int getStart()
           
 void merge(IndexRange ir)
          Merges this range with the other range this function takes the lowest start, and the highest end, and sets this index range to encompas both
 int position()
          position is the place where this range starts.
 void setPosition(int position)
          Set the position for this range
 void setSize(int size)
          set the size for this range.
 int size()
           
 java.lang.String toString()
          For debugging only.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

position

protected int position
Position of the start of the range.


size

protected int size
The size of the range, in number of items.

Constructor Detail

IndexRange

public IndexRange(int position,
                  int size)
Create a new IndexRange

Parameters:
position - position of the start of the range
size - size of the range in number of items

IndexRange

public IndexRange(IndexRange range)
Method Detail

merge

public void merge(IndexRange ir)
Merges this range with the other range this function takes the lowest start, and the highest end, and sets this index range to encompas both

Parameters:
ir - index range to merge with.

size

public int size()
Returns:
the number of elements in this range

position

public int position()
position is the place where this range starts. for the list: 0,2,3,4,5,6
a position of 1 and a length of 2 includes:
the elements: 2,3


getStart

public int getStart()
Returns:
the first index in the range, or -1 if the size = 0

getEnd

public int getEnd()
Returns:
the last index in the range, or -1 if the size = 0

getOverlap

public static IndexRange.Overlap getOverlap(IndexRange r1,
                                            IndexRange r2)
Determines the overlap between two ranges.

Parameters:
r1 - One range to use.
r2 - Another range to use.
Returns:
the overlap that exists between the two ranges.

getOverlap

public IndexRange.Overlap getOverlap(IndexRange r)
Get the overlap between this range and another.

Parameters:
r - a range to compare with this range.
Returns:
The overlap that exists between this range and the one provided.

encompassesIndex

public boolean encompassesIndex(int p)
Parameters:
p - index to check
Returns:
True if P is within the range, False otherwise.

toString

public java.lang.String toString()
For debugging only.

Overrides:
toString in class java.lang.Object

setPosition

public void setPosition(int position)
Set the position for this range

Parameters:
position - new position.

setSize

public void setSize(int size)
set the size for this range.

Parameters:
size - new size.