Package org.eclipse.handly.util

# Class TextRange

java.lang.Object
org.eclipse.handly.util.TextRange

public final class TextRange extends Object
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

  Constructors
  Constructor
  Description
  `TextRange(int offset, int length)`
  Constructs a text range with the given offset and the given length.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `covers(int position)`
  Returns whether this text range covers the given position, including the `end` offset of the range.
  `boolean`
  `equals(Object obj)`
  `int`
  `getEndOffset()`
  Returns the 0-based index of the next character of this text range.
  `int`
  `getLength()`
  Returns the number of characters in this text range.
  `int`
  `getOffset()`
  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 the `end` offset of the range.
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## 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. Returns `0` for an `empty` 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 its `length` is `0`.
    Returns:
      `true` if this text range is empty, and `false` otherwise

  - ### strictlyCovers

    public boolean strictlyCovers(int position)
    Returns whether this text range covers the given position, excluding the `end` offset of the range.
    Parameters:
      `position` - a text position (0-based)
    Returns:
      `true` if this text range strictly covers the given position, and `false` otherwise
    See Also:
      - `covers(int)`

  - ### covers

    public boolean covers(int position)
    Returns whether this text range covers the given position, including the `end` offset of the range.
    Parameters:
      `position` - a text position (0-based)
    Returns:
      `true` if this text range covers the given position, and `false` otherwise
    See Also:
      - `strictlyCovers(int)`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### equals

    public boolean equals(Object obj)
    Overrides:
      `equals` in class `Object`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`