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 |
int | attrStart If non-zero, gap is in an attribute starting (1 less than) here. |
protected static int | BEGIN_ATTRIBUTE_LONG The beginning of an attribute.
|
static int | BEGIN_ATTRIBUTE_LONG_SIZE |
protected static int | BEGIN_DOCUMENT Beginning of a document (or top-level value).
|
protected static int | BEGIN_ELEMENT_LONG Begin of an element, non-compact form.
|
protected static int | BEGIN_ELEMENT_SHORT Beginning of an element, compact form.
|
protected static int | BEGIN_ELEMENT_SHORT_INDEX_MAX |
static 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. |
static int | BEGIN_ENTITY_SIZE |
char[] | data |
int | docStart If non-zero, gap is in an document starting (1 less than) here. |
protected static int | DOCUMENT_URI The document-uri property of a node.
|
static int | END_ATTRIBUTE_SIZE |
protected static int | END_DOCUMENT End of a document. |
protected static int | END_ELEMENT_LONG End of n element, non-compact form.
|
protected static int | END_ELEMENT_SHORT End of an element, compact form.
|
protected static int | END_ENTITY |
int | gapEnd |
int | gapStart |
static int | INT_FOLLOWS A 32-bit integer, non-compact form.
|
static int | MAX_CHAR_SHORT The largest Unicode character that can be encoded in one char. |
Object[] | objects |
int | oindex |
protected static char | POSITION_PAIR_FOLLOWS A position triple referenceing some other "nodes".
|
protected static int | PROCESSING_INSTRUCTION A processing-instruction node follows.
|
Method Summary |
Consumer | append(char c) |
Consumer | append(CharSequence csq) |
Consumer | append(CharSequence csq, int start, int end) |
void | beginEntity(Object base) |
void | clear() |
int | compare(int ipos1, int ipos2) Compare two positions, and indicate their relative order. |
void | consume(SeqPosition position) |
void | consume(Consumer out) |
int | consumeIRange(int startPosition, int endPosition, Consumer out) |
boolean | consumeNext(int ipos, Consumer out) |
void | consumePosRange(int startPos, int endPos, Consumer out) |
int | createPos(int index, boolean isAfter) |
int | createRelativePos(int istart, int offset, boolean isAfter) |
Object | documentUriOfPos(int pos) |
void | dump() |
void | dump(PrintWriter out) |
void | dump(PrintWriter out, int start, int limit) |
void | endAttribute() |
void | endDocument() |
void | endElement() |
void | endEntity() |
void | ensureSpace(int needed) |
int | find(Object arg1) |
int | firstAttributePos(int ipos) |
int | firstChildPos(int ipos) |
Object | get(int index) |
int | getAttributeCount(int parent) |
protected int | getIndexDifference(int ipos1, int ipos0) |
protected int | getIntN(int index) Get a 32-bit int from the data array. |
protected long | getLongN(int index) Get a 64-bit long from the data array. |
int | getNextKind(int ipos) |
int | getNextKindI(int index) |
String | getNextTypeName(int ipos) |
Object | getNextTypeObject(int ipos) |
Object | getPosNext(int ipos) |
int | getPosNextInt(int ipos) Return following value (like getPosNext), as an integer. |
Object | getPosPrevious(int ipos) |
boolean | gotoAttributesStart(TreePosition pos) |
int | gotoAttributesStart(int index) |
int | gotoChildrenStart(int index) |
int | hashCode() |
boolean | hasNext(int ipos) |
boolean | ignoring() |
boolean | isEmpty() |
int | nextDataIndex(int pos) |
int | nextMatching(int startPos, ItemPredicate predicate, int endPos, boolean descend) |
int | nextNodeIndex(int pos, int limit) Skip all primitive content nodes. |
int | nextPos(int position) |
int | parentOrEntityI(int index) |
int | parentOrEntityPos(int ipos) |
int | parentPos(int ipos) |
int | posToDataIndex(int ipos) |
void | resizeObjects() |
void | setAttributeName(int attrIndex, int nameIndex) |
void | setElementName(int elementIndex, int nameIndex) |
void | setIntN(int index, int i) |
int | size() |
void | startAttribute(Object attrType) |
void | startAttribute(int index) |
void | startDocument() |
void | startElement(Object type) |
void | startElement(int index) |
void | statistics() |
void | statistics(PrintWriter out) |
void | stringValue(int startIndex, int endIndex, StringBuffer sbuf) |
int | stringValue(int index, StringBuffer sbuf) |
int | stringValue(boolean inElement, int index, StringBuffer sbuf) |
void | toString(String sep, StringBuffer sbuf) |
void | write(int c) |
void | write(char[] buf, int off, int len) |
void | write(String str) |
void | write(CharSequence str, int start, int length) |
void | writeBoolean(boolean v) |
void | writeByte(int v) |
void | writeCDATA(char[] chars, int offset, int length) |
void | writeComment(char[] chars, int offset, int length) |
void | writeComment(String comment, int offset, int length) |
void | writeDocumentUri(Object uri) Write/set the document-uri property of the current document.
|
void | writeDouble(double v) |
void | writeFloat(float v) |
void | writeInt(int v) |
void | writeJoiner() |
void | writeLong(long v) |
void | writeObject(Object v) |
void | writePosition(AbstractSequence seq, int ipos) |
void | writeProcessingInstruction(String target, char[] content, int offset, int length) |
void | writeProcessingInstruction(String target, String content, int offset, int length) |
public int attrStart
If non-zero, gap is in an attribute starting (1 less than) here.
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.
public static final int BEGIN_ATTRIBUTE_LONG_SIZE
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.
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.
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.
protected static final int BEGIN_ELEMENT_SHORT_INDEX_MAX
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.
public static final int BEGIN_ENTITY_SIZE
public char[] data
public int docStart
If non-zero, gap is in an document starting (1 less than) here.
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.
public static final int END_ATTRIBUTE_SIZE
protected static final int END_DOCUMENT
End of a document.
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.
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.)
protected static final int END_ENTITY
public int gapEnd
public int gapStart
public static final int INT_FOLLOWS
A 32-bit integer, non-compact form.
[INT_FOLLOWS]
[word1], [word2]: The big-endian bits of the integer.
public static final int MAX_CHAR_SHORT
The largest Unicode character that can be encoded in one char.
public Object[] objects
public int oindex
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).
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.
public 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
public
Consumer append(CharSequence csq)
public
Consumer append(CharSequence csq, int start, int end)
public void beginEntity(Object base)
public void clear()
public int compare(int ipos1, int ipos2)
Compare two positions, and indicate their relative order.
public int consumeIRange(int startPosition, int endPosition,
Consumer out)
public boolean consumeNext(int ipos,
Consumer out)
public void consumePosRange(int startPos, int endPos,
Consumer out)
public int createPos(int index, boolean isAfter)
public int createRelativePos(int istart, int offset, boolean isAfter)
public Object documentUriOfPos(int pos)
public void dump()
public void dump(PrintWriter out)
public void dump(PrintWriter out, int start, int limit)
public void endAttribute()
public void endDocument()
public void endElement()
public void endEntity()
public void ensureSpace(int needed)
public int find(Object arg1)
public int firstAttributePos(int ipos)
public int firstChildPos(int ipos)
public Object get(int index)
public int getAttributeCount(int parent)
protected int getIndexDifference(int ipos1, int ipos0)
protected final int getIntN(int index)
Get a 32-bit int from the data array.
protected final long getLongN(int index)
Get a 64-bit long from the data array.
public int getNextKind(int ipos)
public int getNextKindI(int index)
public String getNextTypeName(int ipos)
public Object getNextTypeObject(int ipos)
public Object getPosNext(int ipos)
public int getPosNextInt(int ipos)
Return following value (like getPosNext), as an integer.
public Object getPosPrevious(int ipos)
public int gotoAttributesStart(int index)
public final int gotoChildrenStart(int index)
public int hashCode()
public boolean hasNext(int ipos)
public boolean ignoring()
public boolean isEmpty()
public final int nextDataIndex(int pos)
public int nextMatching(int startPos,
ItemPredicate predicate, int endPos, boolean descend)
public final int nextNodeIndex(int pos, int limit)
Skip all primitive content nodes.
public int nextPos(int position)
public int parentOrEntityI(int index)
public int parentOrEntityPos(int ipos)
public int parentPos(int ipos)
public final int posToDataIndex(int ipos)
public final void resizeObjects()
public void setAttributeName(int attrIndex, int nameIndex)
public void setElementName(int elementIndex, int nameIndex)
public final void setIntN(int index, int i)
public int size()
public void startAttribute(Object attrType)
public void startAttribute(int index)
public void startDocument()
public void startElement(Object type)
public void startElement(int index)
public void statistics()
public void statistics(PrintWriter out)
public void stringValue(int startIndex, int endIndex, StringBuffer sbuf)
public int stringValue(int index, StringBuffer sbuf)
public int stringValue(boolean inElement, int index, StringBuffer sbuf)
public void toString(String sep, StringBuffer sbuf)
public void write(int c)
public void write(char[] buf, int off, int len)
public void write(String str)
public void write(CharSequence str, int start, int length)
public void writeBoolean(boolean v)
public void writeByte(int v)
public void writeCDATA(char[] chars, int offset, int length)
public void writeComment(char[] chars, int offset, int length)
public void writeComment(String comment, int offset, int length)
public void writeDocumentUri(Object uri)
Write/set the document-uri property of the current document.
Only allowed immediately following startDocument.
public void writeDouble(double v)
public void writeFloat(float v)
public void writeInt(int v)
public void writeJoiner()
public void writeLong(long v)
public void writeObject(Object v)
public void writeProcessingInstruction(String target, char[] content, int offset, int length)
public void writeProcessingInstruction(String target, String content, int offset, int length)