Class TextRange
java.lang.Object
com.iqser.red.service.redaction.v1.server.model.document.TextRange
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionTextRange
(int start, int end) Constructs a TextRange with specified start and end indexes. -
Method Summary
Modifier and TypeMethodDescriptionint
boolean
containedBy
(int start, int end) Checks if thisTextRange
is fully contained within another range specified by start and end indices.boolean
containedBy
(TextRange textRange) Checks if thisTextRange
is fully contained by another TextRange.boolean
contains
(int index) Determines if the specified index is within thisTextRange
.boolean
contains
(int start, int end) Checks if thisTextRange
contains another range specified by start and end indices.boolean
Checks if thisTextRange
fully contains another TextRange.int
end()
boolean
int
hashCode()
boolean
intersects
(TextRange textRange) int
length()
Returns the length of the text range.static TextRange
merge
(Collection<TextRange> boundaries) Merges a collection of TextRanges into a single Text range encompassing all.void
setEnd
(int end) void
setStart
(int start) Splits this TextRange into multiple ranges based on a list of indices.int
start()
toString()
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.
-
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
Checks if thisTextRange
fully contains another TextRange.- Parameters:
textRange
- TheTextRange
to check.- Returns:
- true if this range contains the specified range, false otherwise.
-
containedBy
Checks if thisTextRange
is fully contained by another TextRange.- Parameters:
textRange
- TheTextRange
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 thisTextRange
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 thisTextRange
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 thisTextRange
.- 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
- Parameters:
textRange
- TheTextRange
to check for intersection.- Returns:
- true if the ranges intersect, false otherwise.
-
split
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
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
-
compareTo
- Specified by:
compareTo
in interfaceComparable<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
-
hashCode
public int hashCode()
-