Package com.blamejared.searchables.api
Class TokenRange
java.lang.Object
com.blamejared.searchables.api.TokenRange
- All Implemented Interfaces:
Comparable<TokenRange>,Iterable<TokenRange>
public final class TokenRange
extends Object
implements Comparable<TokenRange>, Iterable<TokenRange>
A range denoting the start and end of a Token, as well as any tokens inside that range.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRange(TokenRange range) Adds a range as a subrange to this range.voidaddRanges(Collection<TokenRange> ranges) Adds a collection of ranges as subranges to this range.static TokenRangeat(int position) Creates a newTokenRangeat the given positionstatic TokenRangebetween(int start, int end) Creates a newTokenRangewith the given start and end.intcompareTo(@NotNull TokenRange o) booleancontains(int position) Checks if this range contains the given position.booleancovers(TokenRange other) Checks if this range fully covers the other range.Deletes the content of the given string that this range covers.static TokenRangeencompassing(TokenRange first, TokenRange second) Creates a newTokenRangethat covers both the first and second token.intend()booleaninthashCode()Inserts thetoInsertinto the given string at this range's start position.booleanisEmpty()Checks if this range is empty.@NotNull Iterator<TokenRange> iterator()intlength()Gets the length of this range.range(int index) Gets the subrange at the given index.rangeAtPosition(int position) intrangeIndexAtPosition(int position) Gets the index of the range at the given position.Creates a new range that fully covers the subranges starts and ends.Replaces the contents of the string at this range's positions with the giventoInsertsimplify()Creates a newTokenRangeat this range's start and end, without any subranges.intstart()Performs a substring on the given string using this range's start and end.Performs a substring on the given string using this range's start and the given end.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
EMPTY
-
-
Method Details
-
at
Creates a newTokenRangeat the given position- Parameters:
position- The position of the token.- Returns:
- a new
TokenRangeat the given position
-
between
Creates a newTokenRangewith the given start and end.- Parameters:
start- The start of the range.end- The end of the range.- Returns:
- A new
TokenRangeat the given start and end.
-
encompassing
Creates a newTokenRangethat covers both the first and second token.- Parameters:
first- The first token to cover.second- The second token to cover.- Returns:
- A new
TokenRangethat covers both the first and second token.
-
addRange
Adds a range as a subrange to this range.- Parameters:
range- The range to add.
-
addRanges
Adds a collection of ranges as subranges to this range.- Parameters:
ranges- The ranges to add.
-
subRanges
-
range
Gets the subrange at the given index.- Parameters:
index- The index to get.- Returns:
- The range at the given index
- Throws:
IndexOutOfBoundsException- if index is outside the bounds of subranges.
-
rangeIndexAtPosition
public int rangeIndexAtPosition(int position) Gets the index of the range at the given position. If there are no sub ranges, this will return0- Parameters:
position- The position to get.- Returns:
- The index of the range at the given position, or 0 if
- Throws:
IndexOutOfBoundsException- if the position is not within this range's bounds.
-
rangeAtPosition
-
simplify
Creates a newTokenRangeat this range's start and end, without any subranges.- Returns:
-
covers
Checks if this range fully covers the other range.- Parameters:
other- The range to see if this range covers.- Returns:
- true if this range covers the other range, false otherwise.
-
contains
public boolean contains(int position) Checks if this range contains the given position.- Parameters:
position- The position to check.- Returns:
- true if it contains, false otherwise.
-
substring
Performs a substring on the given string using this range's start and end.- Parameters:
of- The string to substring.- Returns:
- The substring of the given string using this range's start and end.
-
substring
Performs a substring on the given string using this range's start and the given end.- Parameters:
of- The string to substring.end- The end position.- Returns:
- The substring of the given string using this range's start and the given end.
-
delete
Deletes the content of the given string that this range covers.- Parameters:
from- The string to delete from.- Returns:
- The string with the contents inside this range's position removed.
-
insert
Inserts thetoInsertinto the given string at this range's start position.- Parameters:
to- The string to insert into.toInsert- The string to insert.- Returns:
- The given string with the insertion added at this range's start position.
-
replace
Replaces the contents of the string at this range's positions with the giventoInsert- Parameters:
into- The string to insert intotoInsert- The string to insert.- Returns:
- The given string with the insertion added at this range's position.
-
isEmpty
public boolean isEmpty()Checks if this range is empty.- Returns:
- true if empty, false otherwise.
-
length
public int length()Gets the length of this range.- Returns:
- the length of the range.
-
start
public int start() -
end
public int end() -
recalculate
Creates a new range that fully covers the subranges starts and ends.- Returns:
- a new range that fully covers the subranges starts and ends.
-
equals
-
hashCode
public int hashCode() -
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<TokenRange>
-
iterator
- Specified by:
iteratorin interfaceIterable<TokenRange>
-