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
ConstructorDescriptionTextRange
(int offset, int length) Constructs a text range with the given offset and the given length. -
Method Summary
Modifier and TypeMethodDescriptionboolean
covers
(int position) Returns whether this text range covers the given position, including theend
offset of the range.boolean
int
Returns the 0-based index of the next character of this text range.int
Returns the number of characters in this text range.int
Returns the 0-based index of the first character of this text range.int
hashCode()
boolean
isEmpty()
Returns whether this text range is empty.boolean
strictlyCovers
(int position) Returns whether this text range covers the given position, excluding theend
offset 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. Returns0
for anempty
range.- 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 itslength
is0
.- Returns:
true
if this text range is empty, andfalse
otherwise
-
strictlyCovers
public boolean strictlyCovers(int position) Returns whether this text range covers the given position, excluding theend
offset of the range.- Parameters:
position
- a text position (0-based)- Returns:
true
if this text range strictly covers the given position, andfalse
otherwise- See Also:
-
covers
public boolean covers(int position) Returns whether this text range covers the given position, including theend
offset of the range.- Parameters:
position
- a text position (0-based)- Returns:
true
if this text range covers the given position, andfalse
otherwise- See Also:
-
hashCode
public int hashCode() -
equals
-
toString
-