Package org.eclipse.handly.util
Class TextRange
- java.lang.Object
-
- org.eclipse.handly.util.TextRange
-
public final class TextRange extends java.lang.ObjectDescribes a certain range in an indexed text store. Text stores are, for example, documents or strings. A text range is defined by its offset into the text store and its length. A text range is a value object. Its offset and length do not change over time.
-
-
Constructor Summary
Constructors Constructor Description TextRange(int offset, int length)Constructs a text range with the given offset and the given length.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancovers(int position)Returns whether this text range covers the given position, including theendoffset of the range.booleanequals(java.lang.Object obj)intgetEndOffset()Returns the 0-based index of the next character of this text range.intgetLength()Returns the number of characters in this text range.intgetOffset()Returns the 0-based index of the first character of this text range.inthashCode()booleanisEmpty()Returns whether this text range is empty.booleanstrictlyCovers(int position)Returns whether this text range covers the given position, excluding theendoffset of the range.java.lang.StringtoString()
-
-
-
Method Detail
-
getOffset
public int getOffset()
Returns the 0-based index of the first character of this text range.- Returns:
- the index of the first character of this text range
-
getLength
public int getLength()
Returns the number of characters in this text range. Returns0for anemptyrange.- Returns:
- the number of characters in this text range
-
getEndOffset
public int getEndOffset()
Returns the 0-based index of the next character of this text range. The returned value is the result of the following calculation:getOffset() + getLength().- Returns:
- the index of the next character of this text range
-
isEmpty
public boolean isEmpty()
Returns whether this text range is empty. A text range is empty iff itslengthis0.- Returns:
trueif this text range is empty, andfalseotherwise
-
strictlyCovers
public boolean strictlyCovers(int position)
Returns whether this text range covers the given position, excluding theendoffset of the range.- Parameters:
position- a text position (0-based)- Returns:
trueif this text range strictly covers the given position, andfalseotherwise- See Also:
covers(int)
-
covers
public boolean covers(int position)
Returns whether this text range covers the given position, including theendoffset of the range.- Parameters:
position- a text position (0-based)- Returns:
trueif this text range covers the given position, andfalseotherwise- See Also:
strictlyCovers(int)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-