net.sf.saxon.tinytree

Class CompressedWhitespace

Implemented Interfaces:
CharSequence

public class CompressedWhitespace
extends java.lang.Object
implements CharSequence

This class provides a compressed representation of a sequence of whitespace characters. The representation is a sequence of bytes: in each byte the top two bits indicate which whitespace character is used (x9, xA, xD, or x20) and the bottom six bits indicate the number of such characters. A zero byte is a filler. We don't compress the sequence if it would occupy more than 8 bytes, because that's the space we've got available in the TinyTree arrays.

Constructor Summary

CompressedWhitespace(long compressedValue)

Method Summary

char
charAt(int index)
Returns the char value at the specified index.
static CharSequence
compress(CharSequence in)
Attempt to compress a CharSequence
boolean
equals(Object obj)
Indicates whether some other object is "equal to" this one.
long
getCompressedValue()
int
hashCode()
Returns a hash code value for the object.
int
length()
CharSequence
subSequence(int start, int end)
Returns a new CharSequence that is a subsequence of this sequence.
String
toString()
Returns a string representation of the object.
static void
uncompress(long value, FastStringBuffer buffer)
FastStringBuffer
uncompress(FastStringBuffer buffer)
Uncompress the whitespace to a FastStringBuffer
void
write(Writer writer)
Write the value to a Writer
void
writeEscape(boolean[] specialChars, Writer writer)
Write the value to a Writer with escaping of special characters

Constructor Details

CompressedWhitespace

public CompressedWhitespace(long compressedValue)

Method Details

charAt

public char charAt(int index)
Parameters:
index - the index of the char value to be returned
Returns:
the specified char value

compress

public static CharSequence compress(CharSequence in)
Attempt to compress a CharSequence
Parameters:
in - the CharSequence to be compressed
Returns:
the compressed sequence if it can be compressed; or the original CharSequence otherwise

equals

public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.

getCompressedValue

public long getCompressedValue()

hashCode

public int hashCode()
Returns a hash code value for the object.

length

public int length()

subSequence

public CharSequence subSequence(int start,
                                int end)
Returns a new CharSequence that is a subsequence of this sequence. The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in chars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.
Parameters:
start - the start index, inclusive
end - the end index, exclusive
Returns:
the specified subsequence

toString

public String toString()
Returns a string representation of the object.

uncompress

public static void uncompress(long value,
                              FastStringBuffer buffer)

uncompress

public FastStringBuffer uncompress(FastStringBuffer buffer)
Uncompress the whitespace to a FastStringBuffer
Parameters:
buffer - the buffer to which the whitespace is to be appended. The parameter may be null, in which case a new buffer is created.
Returns:
the FastStringBuffer to which the whitespace has been appended. If a buffer was supplied in the argument, this will be the same buffer.

write

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

writeEscape

public void writeEscape(boolean[] specialChars,
                        Writer writer)
            throws java.io.IOException
Write the value to a Writer with escaping of special characters