Package net.sf.saxon.tree.tiny
Class CompressedWhitespace
- java.lang.Object
-
- net.sf.saxon.tree.tiny.CompressedWhitespace
-
- All Implemented Interfaces:
java.lang.CharSequence
public class CompressedWhitespace extends java.lang.Object implements java.lang.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
Constructors Constructor Description CompressedWhitespace(long compressedValue)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description char
charAt(int index)
Returns thechar
value at the specified index.static java.lang.CharSequence
compress(java.lang.CharSequence in)
Attempt to compress a CharSequenceboolean
equals(java.lang.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()
java.lang.CharSequence
subSequence(int start, int end)
Returns a newCharSequence
that is a subsequence of this sequence.java.lang.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 FastStringBuffervoid
write(java.io.Writer writer)
Write the value to a Writervoid
writeEscape(boolean[] specialChars, java.io.Writer writer)
Write the value to a Writer with escaping of special characters
-
-
-
Method Detail
-
compress
public static java.lang.CharSequence compress(java.lang.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
-
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.
-
uncompress
public static void uncompress(long value, FastStringBuffer buffer)
-
getCompressedValue
public long getCompressedValue()
-
length
public int length()
- Specified by:
length
in interfacejava.lang.CharSequence
-
charAt
public char charAt(int index)
Returns thechar
value at the specified index. An index ranges from zero to length() - 1. The firstchar
value of the sequence is at index zero, the next at index one, and so on, as for array indexing.If the
char
value specified by the index is a surrogate, the surrogate value is returned.- Specified by:
charAt
in interfacejava.lang.CharSequence
- Parameters:
index
- the index of thechar
value to be returned- Returns:
- the specified
char
value - 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 newCharSequence
that is a subsequence of this sequence. The subsequence starts with thechar
value at the specified index and ends with thechar
value at index end - 1. The length (inchar
s) of the returned sequence is end - start, so if start == end then an empty sequence is returned.- Specified by:
subSequence
in 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
-
equals
public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
Returns a hash code value for the object.- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
Returns a string representation of the object.- Specified by:
toString
in interfacejava.lang.CharSequence
- Overrides:
toString
in classjava.lang.Object
-
write
public void write(java.io.Writer writer) throws java.io.IOException
Write the value to a Writer- Parameters:
writer
- the writer to write to- Throws:
java.io.IOException
- if an error occurs downstream
-
writeEscape
public void writeEscape(boolean[] specialChars, java.io.Writer writer) throws java.io.IOException
Write the value to a Writer with escaping of special characters- Parameters:
specialChars
- identifies which characters are considered specialwriter
- the writer to write to- Throws:
java.io.IOException
- if an error occurs downstream
-
-