Range Class

com.bea.ide.util
Range Class

public class Range

    extends Object

An instance of this class represents a half-open range of text, in symbols, a range of the form [start, end). Half-open ranges are the standard simply because the arithmetic works out to be easier. Two examples of this are (1) the length of a half open range is simply end - start and (2) if we are generating a list of ranges that completely cover a larger range, then the start of each range will be the end of the previous one, which means that as we move through, we need to maintain only a single pointer into the text, which is conceptually simpler.


Hierarchy
Object
  Range

Constructor Summary

Range(Range r)

Construct a range from an existing range
Range(int start, int end)

Construct a range from a start and end index
 

Method Summary

public boolean
equals(Object r)
Returns true if both ranges start and end at the same positions.
public int
getEnd()
Returns the exclusive end of the range.
public int
getLength()
Returns the length of this range.
public int
getStart()
Returns the inclusive beginning of the range.
public Range
intersection(Range r)
Returns the maximum range that is within both components (this and r).
public void
normalize()
In case start ever gets placed after end, reverts them to a normal orientation.
public boolean
overlaps(Range r)
Returns true if there is any position that is within both ranges (inclusive).
public boolean
posInRange(int pos)
Returns true if the position is between start and end (inclusive).
public boolean
rangeInRange(Range r)
Returns true if this range entirely contains r.
public void
reverse()
In case start ever gets placed after end, reverts them to a normal orientation.
public void
setEnd(int end)
Sets the exclusive end of this range.
public void
setStart(int start)
Sets the inclusive beginning of this range.
public void
shift(int offset)
Move the range by a set amount
public String
toString()
Returns a string representation of this half-open range.
public Range
union(Range r)
Returns the minimum range that includes both components (this and r).
 
Methods from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
   

Constructor Detail

Range

public Range(Range r)
Construct a range from an existing range

Range

public Range(int start, 
             int end)
Construct a range from a start and end index
 

Method Detail

equals(Object) Method

public boolean equals(Object r)
Returns true if both ranges start and end at the same positions.

Overrides
Object.equals(Object)

getEnd() Method

public int getEnd()
Returns the exclusive end of the range.


getLength() Method

public int getLength()
Returns the length of this range.


getStart() Method

public int getStart()
Returns the inclusive beginning of the range.


intersection(Range) Method

public Range intersection(Range r)
Returns the maximum range that is within both components (this and r). Note that this only works if both ranges are normalized.


normalize() Method

public void normalize()
In case start ever gets placed after end, reverts them to a normal orientation. If code ever wants to ask if a Range.isNormal(), they can test Range.getLength() >= 0


overlaps(Range) Method

public boolean overlaps(Range r)
Returns true if there is any position that is within both ranges (inclusive). Note that this only works if both ranges are normalized.


posInRange(int) Method

public boolean posInRange(int pos)
Returns true if the position is between start and end (inclusive). Note that this only works if this range is normalized.


rangeInRange(Range) Method

public boolean rangeInRange(Range r)
Returns true if this range entirely contains r. Note that this only works if both ranges are normalized.


reverse() Method

public void reverse()
In case start ever gets placed after end, reverts them to a normal orientation.


setEnd(int) Method

public void setEnd(int end)
Sets the exclusive end of this range.


setStart(int) Method

public void setStart(int start)
Sets the inclusive beginning of this range.


shift(int) Method

public void shift(int offset)
Move the range by a set amount


toString() Method

public String toString()
Returns a string representation of this half-open range.

Overrides
Object.toString()

union(Range) Method

public Range union(Range r)
Returns the minimum range that includes both components (this and r). Note that this only works if both ranges are normalized.