Class LineAndColumn

java.lang.Object
org.dellroad.javabox.LineAndColumn

public final class LineAndColumn extends Object
Represents a character offset into a String, along with associated line and column offsets.

This class does not store the string itself, just the offset information within it.

The character, line, and column offsets are zero-based. Columns are measured in codepoints rather than characters.

Instances are immutable.

  • Method Details

    • initial

      public static LineAndColumn initial()
      Obtain an initial instance with all offsets set to zero.
    • offset

      public int offset()
      Get the overall character offset.
      Returns:
      character offset (zero based)
    • lineOffset

      public int lineOffset()
      Get the line offset.
      Returns:
      line offset (zero based)
    • columnOffset

      public int columnOffset()
      Get the column offset.
      Returns:
      column offset (zero based)
    • advance

      public LineAndColumn advance(String text)
      Update the offsets by advancing through the given string.
      Parameters:
      text - string content
      Returns:
      updated instance
      Throws:
      IllegalArgumentException - if text is null
      IllegalArgumentException - if the offsets would overflow
    • 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