net.sf.saxon.tinytree
Class LargeStringBuffer

java.lang.Object
  extended by net.sf.saxon.tinytree.LargeStringBuffer
All Implemented Interfaces:
Serializable, CharSequence

public final class LargeStringBuffer
extends 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). The segments have a fixed size of 65536 characters.

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, extraction of the string value of a node requires character copying only in the case where the value crosses segment boundaries.

See Also:
Serialized Form

Constructor Summary
LargeStringBuffer()
          Create an empty LargeStringBuffer with default space allocation
 
Method Summary
 void append(CharSequence s)
          Append a CharSequence to this LargeStringBuffer
 char charAt(int index)
          Returns the character at the specified index.
 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
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LargeStringBuffer

public LargeStringBuffer()
Create an empty LargeStringBuffer with default space allocation

Method Detail

append

public void append(CharSequence s)
Append a CharSequence to this LargeStringBuffer

Parameters:
s - the data to be appended

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:
length in interface 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:
charAt in interface CharSequence
Parameters:
index - the index of the character to be returned
Returns:
the specified character
Throws:
IndexOutOfBoundsException - if the index argument is negative or not less than length()

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.

Specified by:
subSequence in interface CharSequence
Parameters:
start - the start index, inclusive
end - the end index, exclusive
Returns:
the specified subsequence
Throws:
IndexOutOfBoundsException - if start or end are negative, if end is greater than length(), or if start is greater than end

toString

public String toString()
Convert to a string

Specified by:
toString in interface CharSequence
Overrides:
toString in class Object

equals

public boolean equals(Object other)
Compare equality

Overrides:
equals in class Object

hashCode

public int hashCode()
Generate a hash code

Overrides:
hashCode in class Object

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.

Parameters:
start - index of the first character to be included
end - index of the character after the last one to be included
Returns:
the substring at the given position

write

public void write(Writer writer)
           throws IOException
Write the value to a writer

Parameters:
writer - the writer to which the value is to be written
Throws:
IOException


Copyright (c) Saxonica Limited. All rights reserved.