java.lang.Object
com.iqser.red.service.redaction.v1.server.model.document.TextRange
All Implemented Interfaces:
Comparable<TextRange>

public class TextRange extends Object implements Comparable<TextRange>
Represents a range of text defined by a start and end index. Provides functionality to check containment, intersection, and to adjust ranges based on specified conditions.
  • Constructor Details

    • TextRange

      public TextRange(int start, int end)
      Constructs a TextRange with specified start and end indexes.
      Parameters:
      start - The starting index of the range.
      end - The ending index of the range.
      Throws:
      IllegalArgumentException - If start is greater than end.
  • Method Details

    • length

      public int length()
      Returns the length of the text range.
      Returns:
      The length of the range.
    • start

      public int start()
    • end

      public int end()
    • contains

      public boolean contains(TextRange textRange)
      Checks if this TextRange fully contains another TextRange.
      Parameters:
      textRange - The TextRange to check.
      Returns:
      true if this range contains the specified range, false otherwise.
    • containedBy

      public boolean containedBy(TextRange textRange)
      Checks if this TextRange is fully contained by another TextRange.
      Parameters:
      textRange - The TextRange to check against.
      Returns:
      true if this range is contained by the specified range, false otherwise.
    • contains

      public boolean contains(int start, int end)
      Checks if this TextRange contains another range specified by start and end indices.
      Parameters:
      start - The starting index of the range to check.
      end - The ending index of the range to check.
      Returns:
      true if this range fully contains the specified range, false otherwise.
      Throws:
      IllegalArgumentException - If the start index is greater than the end index.
    • containedBy

      public boolean containedBy(int start, int end)
      Checks if this TextRange is fully contained within another range specified by start and end indices.
      Parameters:
      start - The starting index of the outer range.
      end - The ending index of the outer range.
      Returns:
      true if this range is fully contained within the specified range, false otherwise.
      Throws:
      IllegalArgumentException - If the start index is greater than the end index.
    • contains

      public boolean contains(int index)
      Determines if the specified index is within this TextRange.
      Parameters:
      index - The index to check.
      Returns:
      true if the index is within the range (inclusive of the start and exclusive of the end), false otherwise.
    • intersects

      public boolean intersects(TextRange textRange)
      Checks if this TextRange intersects with another TextRange.
      Parameters:
      textRange - The TextRange to check for intersection.
      Returns:
      true if the ranges intersect, false otherwise.
    • split

      public List<TextRange> split(List<Integer> splitIndices)
      Splits this TextRange into multiple ranges based on a list of indices.
      Parameters:
      splitIndices - The indices at which to split the range.
      Returns:
      A list of TextRanges resulting from the split.
      Throws:
      IndexOutOfBoundsException - If any split index is outside this TextRange.
    • merge

      public static TextRange merge(Collection<TextRange> boundaries)
      Merges a collection of TextRanges into a single Text range encompassing all.
      Parameters:
      boundaries - The collection of TextRanges to merge.
      Returns:
      A new TextRange covering the entire span of the given ranges.
      Throws:
      IllegalArgumentException - If boundaries are empty.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(TextRange textRange)
      Specified by:
      compareTo in interface Comparable<TextRange>
    • trim

      public TextRange trim(com.iqser.red.service.redaction.v1.server.model.document.textblock.TextBlock textBlock)
      Shrinks the boundary, such that textBlock.subSequence(boundary) returns a string without trailing or preceding whitespaces.
      Parameters:
      textBlock - TextBlock to check whitespaces against
      Returns:
      Trimmed boundary
    • setStart

      public void setStart(int start)
    • setEnd

      public void setEnd(int end)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object