Class TextStore
stores a text and parts of it in a (hopefully) efficient
manner. A TextStore maintains a string as well as
possibly overlapping substrings thereof which are called
parts. The string can be enlarged with append() and shortened by calling setLength(). The parts, defined by start and end index, are
created with addPart() and setPart().
Furthermore, a small nonnegative integer may be associated with
each part. This is a hack which was
introduced so that a TextStore is exactly what is
needed to represent a match, its submatches as well as the small
identifying integers which can be associated with them.
The parts can be accessed with two getPart methods
(getPart(), getPart()), which append the
requested part, or a piece thereof to a given
StringBuilder.
Note: Many applications define part 0 to refer to the whole stored string, but this is not mandatory.
Part IndexingAll methods which have a part index as parameter accept negative values to address parts relative to the end of the part list. In particular -1 refers to the last part.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPart(int start, int end) voidaddPart(int start, int end, byte id) likesetPart()except that the given part is appended to the list of parts.voidappend(char ch) voidappends the given text to thethis.voidappend(StringBuilder s, int start, int end) appends the given text to thethis.voidappendPart(StringBuilder s, int start, int end) voidappendPart(StringBuilder s, int start, int end, byte id) combines operationsappend(java.lang.String)andaddPart()such that the whole appended text will also define a new part.voidclear()resetsthisto contain neither text nor any parts.voiddeleteParts(int first, int last) deletes all parts in the inclusive range referenced byfirstandlast.intgetEnd(int part) bytegetId(int part) retrieves the small integer value which can be associated with a part.intreturns the number of currently stored parts.getPart(int part) returns the requested part.getPart(int part, int from, int to) returns a substring of the requested part.voidgetPart(StringBuilder sb, int part) appends the requested part to the givenStringBuilder.voidgetPart(StringBuilder sb, int part, int from, int to) appends a substring of the requested part to the givenStringBuilder.intgetPartLen(int part) returns the length of the requested part.intgetStart(int part) intlength()returns the size of the currently stored text.voidsetLength(int l) voidsetPart(int part, int start, int end) calls the 4 parametersetPart()withid==-1.voidsetPart(int part, int start, int end, byte id) defines the given part as the stretch of characters in the stored text starting at positionstartand reaching to the character just beforeend.toString()
-
Constructor Details
-
TextStore
public TextStore()
-
-
Method Details
-
getNumParts
public int getNumParts()returns the number of currently stored parts. -
length
public int length()returns the size of the currently stored text. -
clear
public void clear()resets
thisto contain neither text nor any parts. -
setLength
public void setLength(int l) -
append
-
append
public void append(char ch) -
append
-
setPart
public void setPart(int part, int start, int end, byte id) defines the given part as the stretch of characters in the stored text starting at position
startand reaching to the character just beforeend.- Parameters:
part- see part indexingid- is a small id to be assigned to new part- Throws:
ArrayIndexOutOfBoundsException- ifpartis out of rangeIllegalArgumentException- ifstartandenddo not satisfy the relation0<=start<=end<=textSize().
-
setPart
public void setPart(int part, int start, int end) calls the 4 parameter
setPart()withid==-1. -
deleteParts
public void deleteParts(int first, int last) deletes all parts in the inclusive range referenced by
firstandlast. This does not change the underlying string. Negative part indexes are allowed, but the parts referenced byfirstandlastmust be in order. -
addPart
public void addPart(int start, int end, byte id) like
setPart()except that the given part is appended to the list of parts. -
addPart
public void addPart(int start, int end) -
appendPart
combines operations
append(java.lang.String)andaddPart()such that the whole appended text will also define a new part. -
appendPart
-
getPart
appends the requested part to the given
StringBuilder. Ifpartis out of range, this is silently ignored andsbis not changed.- Parameters:
part- see part indexing.
-
getPart
returns the requested part.
- See Also:
-
getId
public byte getId(int part) retrieves the small integer value which can be associated with a part.
- Throws:
ArrayIndexOutOfBoundsException- ifpartis out of range
-
getPart
appends a substring of the requested part to the given
StringBuilder. The substring is indicated byfromandto, wheretorefers to the character just after the last one requested. Both indices are relative to the part, not the whole internally stored text. Both indices can be negative in order to be taken relative togetPartLen(part). In addition,to==0is also taken relative to the end of the part.If
partis out of range, this is silently ignored andsbis not changed.If
startorendare out of range, they are truncated to the nearest fitting value.Examples
from=0, to=0refers to the whole partfrom=-2, to=-1returns the 2nd to last character
- Parameters:
part- see part indexing
-
getPart
returns a substring of the requested part.- See Also:
-
getPartLen
public int getPartLen(int part) returns the length of the requested part. If
partis out of range, 0 is returned.- Parameters:
part- see part indexing
-
getStart
public int getStart(int part) -
getEnd
public int getEnd(int part) -
toString
-