net.sf.saxon.tinytree
Class LargeStringBuffer
java.lang.Object
net.sf.saxon.tinytree.LargeStringBuffer
- CharSequence, Serializable
public final class LargeStringBuffer
extends java.lang.Object
implements CharSequence, Serializable
This is an implementation of the JDK 1.4 CharSequence interface: it implements
a CharSequence as a list of arrays of characters (the individual arrays are known
as segments). When characters are appended, a new segment is started if the previous
array would otherwise overflow a threshold size (the maxAllocation size).
This is more efficient than a buffer backed by a contiguous array of characters
in cases where the size is likely to grow very large, and where substring operations
are rare. As used within the TinyTree, the value of each text node is contiguous within
one segment, so extraction of the value of a text node is efficient.
LargeStringBuffer() - Create an empty LargeStringBuffer with default space allocation
|
LargeStringBuffer(int minAllocation, int maxAllocation) - Create an empty LargeStringBuffer
|
void | append(CharSequence data) - Append a CharSequence to this LargeStringBuffer
|
char | charAt(int index) - Returns the character at the specified index.
|
void | dumpDataStructure() - Produce diagnostic dump
|
boolean | equals(Object other) - Compare equality
|
int | hashCode() - Generate a hash code
|
int | length() - Returns the length of this character sequence.
|
CharSequence | subSequence(int start, int end) - Returns a new character sequence that is a subsequence of this sequence.
|
String | substring(int start, int end) - Returns a new character sequence that is a subsequence of this sequence.
|
String | toString() - Convert to a string
|
void | write(Writer writer) - Write the value to a writer
|
LargeStringBuffer
public LargeStringBuffer()
Create an empty LargeStringBuffer with default space allocation
LargeStringBuffer
public LargeStringBuffer(int minAllocation,
int maxAllocation)
Create an empty LargeStringBuffer
minAllocation
- initial allocation size for each segment (including the first). If minAllocation
exceeds maxAllocation, it is rounded down to the value of maxAllocationmaxAllocation
- maximum allocation size for each segment. When a segment reaches this
size, a new segment is created rather than appending more characters to the existing segment.
However, a segment may have size greater than maxAllocation if the data is appended in a single chunk
of size maxAllocation.
append
public void append(CharSequence data)
Append a CharSequence to this LargeStringBuffer
data
- the data to be appended
charAt
public char charAt(int index)
Returns the character at the specified index. An index ranges from zero
to length() - 1. The first character of the sequence is at
index zero, the next at index one, and so on, as for array
indexing.
index
- the index of the character to be returned
dumpDataStructure
public void dumpDataStructure()
Produce diagnostic dump
equals
public boolean equals(Object other)
Compare equality
hashCode
public int hashCode()
Generate a hash code
length
public int length()
Returns the length of this character sequence. The length is the number
of 16-bit UTF-16 characters in the sequence.
- the number of characters in this sequence
subSequence
public CharSequence subSequence(int start,
int end)
Returns a new character sequence that is a subsequence of this sequence.
The subsequence starts with the character at the specified index and
ends with the character at index end - 1. The length of the
returned sequence is end - start, so if start == end
then an empty sequence is returned.
start
- the start index, inclusiveend
- the end index, exclusive
- the specified subsequence
substring
public String substring(int start,
int end)
Returns a new character sequence that is a subsequence of this sequence.
Unlike subSequence, this is guaranteed to return a String.
start
- index of the first character to be includedend
- index of the character after the last one to be included
- the substring at the given position
toString
public String toString()
Convert to a string
write
public void write(Writer writer)
throws java.io.IOException
Write the value to a writer
writer
- the writer to which the value is to be written