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.
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 <32BEGIN_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
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
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.
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.
attrStart
public int attrStart
If non-zero, gap is in an attribute starting (1 less than) here.
docStart
public int docStart
If non-zero, gap is in an document starting (1 less than) here.
gapStart
public int gapStart
objects
public Object[] objects
append
public Consumer append(CharSequence csq)
append
public Consumer append(CharSequence csq,
int start,
int end)
compare
public int compare(int ipos1,
int ipos2)
Compare two positions, and indicate their relative order.
- compare in interface AbstractSequence
consume
public void consume(SeqPosition position)
Consume node at current position.
The caller may invalidate or change the position after consume returns,
so if the consumer wants to save it, it needs to copy it.
- consume in interface PositionConsumer
consumeIRange
public int consumeIRange(int startPosition,
int endPosition,
Consumer out)
createPos
public int createPos(int index,
boolean isAfter)
Generate a position at a given index.
The result is a position cookie that must be free'd with releasePos.
- createPos in interface AbstractSequence
index
- offset from beginning of desired positionisAfter
- should the position have the isAfter property
documentUriOfPos
public Object documentUriOfPos(int pos)
dump
public void dump(java.io.PrintWriter out)
dump
public void dump(java.io.PrintWriter out,
int start,
int limit)
endAttribute
public void endAttribute()
End of an attribute or end of an actual parameter.
The former use matches a startAttribute; the latter may not,
and can be used to separate parameters in a parameter list.
This double duty suggsts the method should at least be re-named.
- endAttribute in interface Consumer
ensureSpace
public void ensureSpace(int needed)
find
public int find(Object arg1)
firstAttributePos
public int firstAttributePos(int ipos)
Like firstChildPos.
Problem: Should this stop before we get to children?
I think so, but that requires changes to TreeList.
- firstAttributePos in interface AbstractSequence
firstChildPos
public int firstChildPos(int ipos)
Get position before first child (of the element following position).
- firstChildPos in interface AbstractSequence
ipos
- parent position. It is not released by this method.
- non-zero position cookie if there is a child sequence
(which might be empty); zero if current position is end of sequence
or following element is atomic (cannot have children).
getAttributeCount
public int getAttributeCount(int parent)
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.
getNextKindI
public int getNextKindI(int index)
getPosNext
public Object getPosNext(int ipos)
Get the element following the specified position.
- getPosNext in interface AbstractSequence
ipos
- the specified position.
- the following element, or eofValue if there is none.
Called by SeqPosition.getNext.
getPosNextInt
public int getPosNextInt(int ipos)
Return following value (like getPosNext), as an integer.
getPosPrevious
public Object getPosPrevious(int ipos)
Get the element before the specified position.
- getPosPrevious in interface AbstractSequence
ipos
- the specified position.
- the following element, or eofValue if there is none.
gotoAttributesStart
public int gotoAttributesStart(int index)
gotoChildrenStart
public final int gotoChildrenStart(int index)
ignoring
public boolean ignoring()
True if consumer is ignoring rest of element.
The producer can use this information to skip ahead.
- ignoring in interface Consumer
nextDataIndex
public final int nextDataIndex(int pos)
nextMatching
public int nextMatching(int startPos,
ItemPredicate predicate,
int endPos,
boolean descend)
Get next matching child or descendent (ignoring attributes).
- nextMatching in interface AbstractSequence
startPos
- starting positionendPos
- stop before endPosdescend
- if true do depth-first traversal.
- poistion of next match or 0 if none found
nextNodeIndex
public final int nextNodeIndex(int pos,
int limit)
Skip all primitive content nodes.
nextPos
public int nextPos(int position)
Return the next position following the argument.
The new position has the isAfter property.
The argument is implicitly released (as in releasePos).
Returns 0 if we are already at end of file.
- nextPos in interface AbstractSequence
parentOrEntityI
public int parentOrEntityI(int index)
parentOrEntityPos
public int parentOrEntityPos(int ipos)
parentPos
public int parentPos(int ipos)
Get position of parent.
- parentPos in interface AbstractSequence
ipos
- child position. It is not released by this method.
- the p os of the parent, or endPos() is there is no known parent.
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)
startAttribute
public void startAttribute(Object attrType)
Write a attribute for the current element.
This is only allowed immediately after a startElement.
- startAttribute in interface Consumer
startAttribute
public void startAttribute(int index)
startElement
public void startElement(int index)
statistics
public void statistics()
statistics
public void statistics(java.io.PrintWriter out)
stringValue
public int stringValue(boolean inElement,
int index,
StringBuffer sbuf)
stringValue
public int stringValue(int index,
StringBuffer sbuf)
stringValue
public void stringValue(int startIndex,
int endIndex,
StringBuffer sbuf)
write
public void write(CharSequence str,
int start,
int length)
- write in interface Consumer
write
public void write(char[] buf,
int off,
int len)
- write in interface Consumer
writeByte
public void writeByte(int v)
writeCDATA
public void writeCDATA(char[] chars,
int offset,
int length)
- writeCDATA in interface XConsumer
writeComment
public void writeComment(String comment,
int offset,
int length)
writeComment
public void writeComment(char[] chars,
int offset,
int length)
- writeComment in interface XConsumer
writeDocumentUri
public void writeDocumentUri(Object uri)
Write/set the document-uri property of the current document.
Only allowed immediately following startDocument.
writeJoiner
public void writeJoiner()
writePosition
public void writePosition(AbstractSequence seq,
int ipos)
Consume a single position pair.
This PositionConsumer may assume the sequence does no reference
management; i.e. that copyPos is trivial and releasePos is
a no-op. If that is not the case, use consume(TreePosition) instead.
- writePosition in interface PositionConsumer
writeProcessingInstruction
public void writeProcessingInstruction(String target,
String content,
int offset,
int length)