Package org.eclipse.handly.util
Class TextRange
java.lang.Object
org.eclipse.handly.util.TextRange
Describes 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
ConstructorsConstructorDescriptionTextRange(int offset, int length) Constructs a text range with the given offset and the given length. -
Method Summary
Modifier and TypeMethodDescriptionbooleancovers(int position) Returns whether this text range covers the given position, including theendoffset of the range.booleanintReturns the 0-based index of the next character of this text range.intReturns the number of characters in this text range.intReturns 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.toString()
-
Constructor Details
-
TextRange
public TextRange(int offset, int length) Constructs a text range with the given offset and the given length.- Parameters:
offset- the given offset (0-based)length- the given length (non-negative)
-
-
Method Details
-
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
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:
-
hashCode
public int hashCode() -
equals
-
toString
-