Package net.sf.saxon.tinytree
Class LargeStringBuffer
- java.lang.Object
-
- net.sf.saxon.tinytree.LargeStringBuffer
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.CharSequence
public final class LargeStringBuffer extends java.lang.Object implements java.lang.CharSequence, java.io.SerializableThis 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.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LargeStringBuffer()Create an empty LargeStringBuffer with default space allocationLargeStringBuffer(int minAllocation, int maxAllocation)Create an empty LargeStringBuffer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(java.lang.CharSequence data)Append a CharSequence to this LargeStringBuffercharcharAt(int index)Returns the character at the specified index.booleanequals(java.lang.Object other)Compare equalityinthashCode()Generate a hash codeintlength()Returns the length of this character sequence.java.lang.CharSequencesubSequence(int start, int end)Returns a new character sequence that is a subsequence of this sequence.java.lang.Stringsubstring(int start, int end)Returns a new character sequence that is a subsequence of this sequence.java.lang.StringtoString()Convert to a stringvoidwrite(java.io.Writer writer)Write the value to a writer
-
-
-
Constructor Detail
-
LargeStringBuffer
public LargeStringBuffer()
Create an empty LargeStringBuffer with default space allocation
-
LargeStringBuffer
public LargeStringBuffer(int minAllocation, int maxAllocation)Create an empty LargeStringBuffer- Parameters:
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.
-
-
Method Detail
-
append
public void append(java.lang.CharSequence data)
Append a CharSequence to this LargeStringBuffer
-
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.- Specified by:
lengthin interfacejava.lang.CharSequence- Returns:
- the number of characters in this sequence
-
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.- Specified by:
charAtin interfacejava.lang.CharSequence- Parameters:
index- the index of the character to be returned- Returns:
- the specified character
- Throws:
java.lang.IndexOutOfBoundsException- if the index argument is negative or not less than length()
-
subSequence
public java.lang.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.- Specified by:
subSequencein interfacejava.lang.CharSequence- Parameters:
start- the start index, inclusiveend- the end index, exclusive- Returns:
- the specified subsequence
- Throws:
java.lang.IndexOutOfBoundsException- if start or end are negative, if end is greater than length(), or if start is greater than end
-
toString
public java.lang.String toString()
Convert to a string- Specified by:
toStringin interfacejava.lang.CharSequence- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
Compare equality- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Generate a hash code- Overrides:
hashCodein classjava.lang.Object
-
substring
public java.lang.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.
-
write
public void write(java.io.Writer writer) throws java.io.IOExceptionWrite the value to a writer- Throws:
java.io.IOException
-
-