gnu.lists

Class TreeList

public class TreeList extends AbstractSequence implements XConsumer, PositionConsumer, Consumable

A compact representation of a tree, that is a nested list structure. The data structure can store anything that can be emitted to a Consumer. This data structure is optimized for efficient forwards traversal through the data structure, not random access. It does have an "insertion point"; insertions and deletions are efficient through the use of a buffer gap. It is a reasonable choice for a "DOM" for XML data.
Field Summary
intattrStart
If non-zero, gap is in an attribute starting (1 less than) here.
protected static intBEGIN_ATTRIBUTE_LONG
The beginning of an attribute.
static intBEGIN_ATTRIBUTE_LONG_SIZE
protected static intBEGIN_DOCUMENT
Beginning of a document (or top-level value).
protected static intBEGIN_ELEMENT_LONG
Begin of an element, non-compact form.
protected static intBEGIN_ELEMENT_SHORT
Beginning of an element, compact form.
protected static intBEGIN_ELEMENT_SHORT_INDEX_MAX
static intBEGIN_ENTITY
End of an entity (typically a file, possibly included). [base_uri], 2 short, given an index of a base-uri object [parent_offset], in 2 shorts, encoded as for BEGIN_DOCUMENT.
static intBEGIN_ENTITY_SIZE
char[]data
intdocStart
If non-zero, gap is in an document starting (1 less than) here.
protected static intDOCUMENT_URI
The document-uri property of a node.
static intEND_ATTRIBUTE_SIZE
protected static intEND_DOCUMENT
End of a document.
protected static intEND_ELEMENT_LONG
End of n element, non-compact form.
protected static intEND_ELEMENT_SHORT
End of an element, compact form.
protected static intEND_ENTITY
intgapEnd
intgapStart
static intINT_FOLLOWS
A 32-bit integer, non-compact form.
static intMAX_CHAR_SHORT
The largest Unicode character that can be encoded in one char.
Object[]objects
intoindex
protected static charPOSITION_PAIR_FOLLOWS
A position triple referenceing some other "nodes".
protected static intPROCESSING_INSTRUCTION
A processing-instruction node follows.
Constructor Summary
TreeList()
TreeList(TreeList list, int startPosition, int endPosition)
Make a copy of a sub-range of a TreeList.
TreeList(TreeList list)
Method Summary
Consumerappend(char c)
Consumerappend(CharSequence csq)
Consumerappend(CharSequence csq, int start, int end)
voidbeginEntity(Object base)
voidclear()
intcompare(int ipos1, int ipos2)
Compare two positions, and indicate their relative order.
voidconsume(SeqPosition position)
voidconsume(Consumer out)
intconsumeIRange(int startPosition, int endPosition, Consumer out)
booleanconsumeNext(int ipos, Consumer out)
voidconsumePosRange(int startPos, int endPos, Consumer out)
intcreatePos(int index, boolean isAfter)
intcreateRelativePos(int istart, int offset, boolean isAfter)
ObjectdocumentUriOfPos(int pos)
voiddump()
voiddump(PrintWriter out)
voiddump(PrintWriter out, int start, int limit)
voidendAttribute()
voidendDocument()
voidendElement()
voidendEntity()
voidensureSpace(int needed)
intfind(Object arg1)
intfirstAttributePos(int ipos)
intfirstChildPos(int ipos)
Objectget(int index)
intgetAttributeCount(int parent)
protected intgetIndexDifference(int ipos1, int ipos0)
protected intgetIntN(int index)
Get a 32-bit int from the data array.
protected longgetLongN(int index)
Get a 64-bit long from the data array.
intgetNextKind(int ipos)
intgetNextKindI(int index)
StringgetNextTypeName(int ipos)
ObjectgetNextTypeObject(int ipos)
ObjectgetPosNext(int ipos)
intgetPosNextInt(int ipos)
Return following value (like getPosNext), as an integer.
ObjectgetPosPrevious(int ipos)
booleangotoAttributesStart(TreePosition pos)
intgotoAttributesStart(int index)
intgotoChildrenStart(int index)
inthashCode()
booleanhasNext(int ipos)
booleanignoring()
booleanisEmpty()
intnextDataIndex(int pos)
intnextMatching(int startPos, ItemPredicate predicate, int endPos, boolean descend)
intnextNodeIndex(int pos, int limit)
Skip all primitive content nodes.
intnextPos(int position)
intparentOrEntityI(int index)
intparentOrEntityPos(int ipos)
intparentPos(int ipos)
intposToDataIndex(int ipos)
voidresizeObjects()
voidsetAttributeName(int attrIndex, int nameIndex)
voidsetElementName(int elementIndex, int nameIndex)
voidsetIntN(int index, int i)
intsize()
voidstartAttribute(Object attrType)
voidstartAttribute(int index)
voidstartDocument()
voidstartElement(Object type)
voidstartElement(int index)
voidstatistics()
voidstatistics(PrintWriter out)
voidstringValue(int startIndex, int endIndex, StringBuffer sbuf)
intstringValue(int index, StringBuffer sbuf)
intstringValue(boolean inElement, int index, StringBuffer sbuf)
voidtoString(String sep, StringBuffer sbuf)
voidwrite(int c)
voidwrite(char[] buf, int off, int len)
voidwrite(String str)
voidwrite(CharSequence str, int start, int length)
voidwriteBoolean(boolean v)
voidwriteByte(int v)
voidwriteCDATA(char[] chars, int offset, int length)
voidwriteComment(char[] chars, int offset, int length)
voidwriteComment(String comment, int offset, int length)
voidwriteDocumentUri(Object uri)
Write/set the document-uri property of the current document.
voidwriteDouble(double v)
voidwriteFloat(float v)
voidwriteInt(int v)
voidwriteJoiner()
voidwriteLong(long v)
voidwriteObject(Object v)
voidwritePosition(AbstractSequence seq, int ipos)
voidwriteProcessingInstruction(String target, char[] content, int offset, int length)
voidwriteProcessingInstruction(String target, String content, int offset, int length)

Field Detail

attrStart

public int attrStart
If non-zero, gap is in an attribute starting (1 less than) here.

BEGIN_ATTRIBUTE_LONG

protected static final int BEGIN_ATTRIBUTE_LONG
The beginning of an attribute. [BEGIN_ATTRIBUTE_LONG] [index], 2 shorts, where objects[index] is the attribute type name and objects[index+1] is the attribute type object. [end_offset], 2 shorts, giving the location of the following END_ATTRIBUTE. If the attribute straddles the gap, then end_offset is a negative offset relative to data.length. (Therefore allocating more space for the gap does not require adjusting end_offset.) Otherwise, the end_offset is relative to the BEGIN_ATTRIBUTE_LONG word.

BEGIN_ATTRIBUTE_LONG_SIZE

public static final int BEGIN_ATTRIBUTE_LONG_SIZE

BEGIN_DOCUMENT

protected static final int BEGIN_DOCUMENT
Beginning of a document (or top-level value). Used to distinguish a document from its element node. [end_offset], 2 shorts, giving the location of the following END_DOCUMENT. If the attribute straddles the gap, then end_offset is a negative offset relative to data.length. (Therefore allocating more space for the gap does not require adjusting end_offset.) Otherwise, the end_offset is relative to the BEGIN_DOCUMENT word. [parent_offset], in 2 shorts. The parent node, or -1 if no parent. Otherwise, a negative value is a relative offset, while a non-negative value is absolute. (Use the latter when gap is between this node and its parent. The parent would normally be a BEGIN_ENTITY.

BEGIN_ELEMENT_LONG

protected static final int BEGIN_ELEMENT_LONG
Begin of an element, non-compact form. [BEGIN_ELEMENT_LONG] [end_offset], in 2 shorts. The position of the matching END_ELEMENT_LONG. If the element straddles the gap, then end_offset is a negative offset relative to data.length. (Therefore allocating more space for the gap does not require adjusting any end_offset.) If the element and and its children are all on the same side of the gap, then end_offset is a positive offset relative to the BEGIN_ELEMENT_LONG word. (Hence shifting an entire element when the gap is moved does not require changing its end_offset.) Note that the space taken by a BEGIN_ELEMENT_LONG is the same that needed for a BEGIN_ELEMENT_SHORT (but a END_ELEMENT_LONG takes much more space than a END_ELEMENT_SHORT). This is to make it easier to convert a BEGIN_ELEMENT_LONG to a BEGIN_ELEMENT_SHORT or vice versa, as needed.

BEGIN_ELEMENT_SHORT

protected static final int BEGIN_ELEMENT_SHORT
Beginning of an element, compact form. [BEGIN_ELEMENT_SHORT + index], where objects[index] is the element's type name and objects[index+1] is the type object. [end_offset], the unsigned offset (from the initial word) to the corresponding END_ELEMENT_SHORT. [parent_offset], the (unsigned absolute value of the) offset to the outer BEGIN_ELEMENT_SHORT/BEGIN_ELEMENT_LONG/BEGIN_DOCUMENT. . (If these is no parent, then parent_offset==0.) This should is used when index < BEGIN_ELEMENT_SHORT_INDEX_MAX, both end_offset and parent_offset fit in 16 bits, and the element does not straddle the gap.

BEGIN_ELEMENT_SHORT_INDEX_MAX

protected static final int BEGIN_ELEMENT_SHORT_INDEX_MAX

BEGIN_ENTITY

public static final int BEGIN_ENTITY
End of an entity (typically a file, possibly included). [base_uri], 2 short, given an index of a base-uri object [parent_offset], in 2 shorts, encoded as for BEGIN_DOCUMENT.

BEGIN_ENTITY_SIZE

public static final int BEGIN_ENTITY_SIZE

data

public char[] data

docStart

public int docStart
If non-zero, gap is in an document starting (1 less than) here.

DOCUMENT_URI

protected static final int DOCUMENT_URI
The document-uri property of a node. This is not an actual value, but it is a property of the previous document node, or the surrounding node just after a BEGIN_XXX entry. [DOCUMENT_URI] [index]. 2 shorts, where objects[index] is the document-uri value.

END_ATTRIBUTE_SIZE

public static final int END_ATTRIBUTE_SIZE

END_DOCUMENT

protected static final int END_DOCUMENT
End of a document.

END_ELEMENT_LONG

protected static final int END_ELEMENT_LONG
End of n element, non-compact form. [END_ELEMENT_LONG] [index], 2 shorts where objects[index] is the element's type name and objects[index+1] is the type object. [begin_offset], in 2 shorts. The position of the matching BEGIN_ELEMENT_LONG. If the element straddles the gap, then begin_offset is the actual index (i.e. relative to the start of data) of the matching BEGIN_ELEMENT_LONG. (Therefore allocating more space for the gap does not require adjusting begin_offset.) If the element does not straddle the gap, then begin_offset is a negative offset relative to the END_ELEMENT_LONG word. (Hence shifting an entire element when the gap is moved does not require changing its begin_offset.) relative to data.length. [parent_offset], in 2 shorts. The position of the outer BEGIN_ELEMENT_LONG, BEGIN_ELEMENT_SHORT or BEGIN_DOCUMENT. If the difference straddles the gap (i.e. either this element straddles the gap or the parent element does and the gap precedes this element), then parent_offset is the actual index of the parent element. Otherwise, then parent_offset is a negative offset relative to the END_ELEMENT_LONG word.

END_ELEMENT_SHORT

protected static final int END_ELEMENT_SHORT
End of an element, compact form. [END_ELEMENT_SHORT] [begin_offset], the unsigned absolute value of the offset to the matching BEGIN. (This is the same as the matching end_offset.)

END_ENTITY

protected static final int END_ENTITY

gapEnd

public int gapEnd

gapStart

public int gapStart

INT_FOLLOWS

public static final int INT_FOLLOWS
A 32-bit integer, non-compact form. [INT_FOLLOWS] [word1], [word2]: The big-endian bits of the integer.

MAX_CHAR_SHORT

public static final int MAX_CHAR_SHORT
The largest Unicode character that can be encoded in one char.

objects

public Object[] objects

oindex

public int oindex

POSITION_PAIR_FOLLOWS

protected static final char POSITION_PAIR_FOLLOWS
A position triple referenceing some other "nodes". Followed by index of sequence (2 chars), and ipos (2 chars).

PROCESSING_INSTRUCTION

protected static final int PROCESSING_INSTRUCTION
A processing-instruction node follows. [PROCESSING_INSTRUCTION] [target] 2 shorts, where objects[target] is the target as a String. [length] 2 shorts. [comment text], (length) number of characters.

Constructor Detail

TreeList

public TreeList()

TreeList

public TreeList(TreeList list, int startPosition, int endPosition)
Make a copy of a sub-range of a TreeList.

Parameters: list the TreeList to copy startPosition start of range, as a raw index in data endPosition end of range, as a raw index in data

TreeList

public TreeList(TreeList list)

Method Detail

append

public Consumer append(char c)

append

public Consumer append(CharSequence csq)

append

public Consumer append(CharSequence csq, int start, int end)

beginEntity

public void beginEntity(Object base)

clear

public void clear()

compare

public int compare(int ipos1, int ipos2)
Compare two positions, and indicate their relative order.

consume

public void consume(SeqPosition position)

consume

public void consume(Consumer out)

consumeIRange

public int consumeIRange(int startPosition, int endPosition, Consumer out)

consumeNext

public boolean consumeNext(int ipos, Consumer out)

consumePosRange

public void consumePosRange(int startPos, int endPos, Consumer out)

createPos

public int createPos(int index, boolean isAfter)

createRelativePos

public int createRelativePos(int istart, int offset, boolean isAfter)

documentUriOfPos

public Object documentUriOfPos(int pos)

dump

public void dump()

dump

public void dump(PrintWriter out)

dump

public void dump(PrintWriter out, int start, int limit)

endAttribute

public void endAttribute()

endDocument

public void endDocument()

endElement

public void endElement()

endEntity

public void endEntity()

ensureSpace

public void ensureSpace(int needed)

find

public int find(Object arg1)

firstAttributePos

public int firstAttributePos(int ipos)

firstChildPos

public int firstChildPos(int ipos)

get

public Object get(int index)

getAttributeCount

public int getAttributeCount(int parent)

getIndexDifference

protected int getIndexDifference(int ipos1, int ipos0)

getIntN

protected final int getIntN(int index)
Get a 32-bit int from the data array.

getLongN

protected final long getLongN(int index)
Get a 64-bit long from the data array.

getNextKind

public int getNextKind(int ipos)

getNextKindI

public int getNextKindI(int index)

getNextTypeName

public String getNextTypeName(int ipos)

getNextTypeObject

public Object getNextTypeObject(int ipos)

getPosNext

public Object getPosNext(int ipos)

getPosNextInt

public int getPosNextInt(int ipos)
Return following value (like getPosNext), as an integer.

getPosPrevious

public Object getPosPrevious(int ipos)

gotoAttributesStart

public boolean gotoAttributesStart(TreePosition pos)

gotoAttributesStart

public int gotoAttributesStart(int index)

gotoChildrenStart

public final int gotoChildrenStart(int index)

hashCode

public int hashCode()

hasNext

public boolean hasNext(int ipos)

ignoring

public boolean ignoring()

isEmpty

public boolean isEmpty()

nextDataIndex

public final int nextDataIndex(int pos)

nextMatching

public int nextMatching(int startPos, ItemPredicate predicate, int endPos, boolean descend)

nextNodeIndex

public final int nextNodeIndex(int pos, int limit)
Skip all primitive content nodes.

nextPos

public int nextPos(int position)

parentOrEntityI

public int parentOrEntityI(int index)

parentOrEntityPos

public int parentOrEntityPos(int ipos)

parentPos

public int parentPos(int ipos)

posToDataIndex

public final int posToDataIndex(int ipos)

resizeObjects

public final void resizeObjects()

setAttributeName

public void setAttributeName(int attrIndex, int nameIndex)

setElementName

public void setElementName(int elementIndex, int nameIndex)

setIntN

public final void setIntN(int index, int i)

size

public int size()

startAttribute

public void startAttribute(Object attrType)

startAttribute

public void startAttribute(int index)

startDocument

public void startDocument()

startElement

public void startElement(Object type)

startElement

public void startElement(int index)

statistics

public void statistics()

statistics

public void statistics(PrintWriter out)

stringValue

public void stringValue(int startIndex, int endIndex, StringBuffer sbuf)

stringValue

public int stringValue(int index, StringBuffer sbuf)

stringValue

public int stringValue(boolean inElement, int index, StringBuffer sbuf)

toString

public void toString(String sep, StringBuffer sbuf)

write

public void write(int c)

write

public void write(char[] buf, int off, int len)

write

public void write(String str)

write

public void write(CharSequence str, int start, int length)

writeBoolean

public void writeBoolean(boolean v)

writeByte

public void writeByte(int v)

writeCDATA

public void writeCDATA(char[] chars, int offset, int length)

writeComment

public void writeComment(char[] chars, int offset, int length)

writeComment

public void writeComment(String comment, int offset, int length)

writeDocumentUri

public void writeDocumentUri(Object uri)
Write/set the document-uri property of the current document. Only allowed immediately following startDocument.

writeDouble

public void writeDouble(double v)

writeFloat

public void writeFloat(float v)

writeInt

public void writeInt(int v)

writeJoiner

public void writeJoiner()

writeLong

public void writeLong(long v)

writeObject

public void writeObject(Object v)

writePosition

public void writePosition(AbstractSequence seq, int ipos)

writeProcessingInstruction

public void writeProcessingInstruction(String target, char[] content, int offset, int length)

writeProcessingInstruction

public void writeProcessingInstruction(String target, String content, int offset, int length)