org.exist.numbering
Interface NodeId

All Superinterfaces:
Comparable
All Known Implementing Classes:
DLN

public interface NodeId
extends Comparable

Represents the internal id of a node within eXist. Basically, all stored nodes in eXist need to have an id that implements this interface. The id will be assigned according to used numbering scheme. From a given id, we can determine the relationship of the node it represents to any other node in the same document.


Field Summary
static NodeId DOCUMENT_NODE
          Static field representing the document node.
static NodeId END_OF_DOCUMENT
           
static int IS_CHILD
           
static int IS_DESCENDANT
           
static int IS_SELF
           
static int LENGTH_NODE_ID_UNITS
           
static NodeId ROOT_NODE
           
 
Method Summary
 boolean after(NodeId other, boolean isFollowing)
          Returns true if the node represented by this node id comes after the argument node in document order.
 NodeId append(NodeId other)
           
 boolean before(NodeId other, boolean isPreceding)
          Returns true if the node represented by this node id comes before the argument node in document order.
 int compareTo(NodeId other)
           
 int computeRelation(NodeId ancestor)
          Computes the relationship of this node to the given potential ancestor node.
 boolean equals(NodeId other)
           
 NodeId getChild(int child)
          Returns a new NodeId representing the nth child node of this node.
 NodeId getParentId()
          Returns a new NodeId representing the parent of the current node.
 int getTreeLevel()
          Returns the level within the document tree at which this node occurs.
 NodeId insertBefore()
           
 NodeId insertNode(NodeId right)
           
 boolean isChildOf(NodeId parent)
          Is the current node a child node of the specified parent?
 boolean isDescendantOf(NodeId ancestor)
          Is the current node id a descendant of the specified node?
 boolean isDescendantOrSelfOf(NodeId ancestor)
           
 boolean isSiblingOf(NodeId sibling)
           
 NodeId newChild()
          Returns a new NodeId representing the first child node of this node.
 NodeId nextSibling()
          Returns a new NodeId representing the next following sibling of this node.
 NodeId precedingSibling()
          Returns a new NodeId representing the prececing sibling of this node.
 void serialize(byte[] data, int offset)
          Serializes the node id to an array of bytes.
 int size()
          Returns the size (in bytes) of this node id.
 int units()
           
 NodeId write(NodeId previous, VariableByteOutputStream os)
          Write the node id to a VariableByteOutputStream.
 void write(VariableByteOutputStream os)
          Write the node id to a VariableByteOutputStream.
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

LENGTH_NODE_ID_UNITS

static final int LENGTH_NODE_ID_UNITS
See Also:
Constant Field Values

DOCUMENT_NODE

static final NodeId DOCUMENT_NODE
Static field representing the document node.


END_OF_DOCUMENT

static final NodeId END_OF_DOCUMENT

ROOT_NODE

static final NodeId ROOT_NODE

IS_CHILD

static final int IS_CHILD
See Also:
Constant Field Values

IS_DESCENDANT

static final int IS_DESCENDANT
See Also:
Constant Field Values

IS_SELF

static final int IS_SELF
See Also:
Constant Field Values
Method Detail

newChild

NodeId newChild()
Returns a new NodeId representing the first child node of this node. The returned id can be used for creating new nodes. The actual id of the first node might be different, depending on the implementation.

Returns:
new child node id

getChild

NodeId getChild(int child)
Returns a new NodeId representing the nth child node of this node. The returned id can be used to create new child nodes. The actual id of the child might be different, depending on the implementation.

Parameters:
child - the position of the child
Returns:
new node id

nextSibling

NodeId nextSibling()
Returns a new NodeId representing the next following sibling of this node. The returned id can be used to create new sibling nodes. The actual id of the next sibling might be different, depending on the implementation.

Returns:
new sibling node id.

precedingSibling

NodeId precedingSibling()
Returns a new NodeId representing the prececing sibling of this node. The returned id can be used to create new sibling nodes. The actual id of the next sibling might be different, depending on the implementation.

Returns:
new sibling node id.

insertNode

NodeId insertNode(NodeId right)

insertBefore

NodeId insertBefore()

append

NodeId append(NodeId other)

getParentId

NodeId getParentId()
Returns a new NodeId representing the parent of the current node. If the parent is the document, the constant DOCUMENT_NODE will be returned. For the document itself, the parent id will be null.

Returns:
the id of the parent node or null if the current node is the document node.

after

boolean after(NodeId other,
              boolean isFollowing)
Returns true if the node represented by this node id comes after the argument node in document order. If isFollowing is set to true, the method behaves as if called to evaluate a following::* XPath select, i.e. it returns false for descendants of the current node.

Parameters:
other - the node id to compare with
isFollowing - if true, return false for descendants of the current node
Returns:
true true if the current node comes after the other node in document order

before

boolean before(NodeId other,
               boolean isPreceding)
Returns true if the node represented by this node id comes before the argument node in document order. If isPreceding is set to true, the method behaves as if called to evaluate a preceding::* XPath select, i.e. it returns false for ancestors of the current node.

Parameters:
other - the node id to compare with
isPreceding - if true, return false for ancestors of the current node
Returns:
true if the current node comes before the other node in document order.

isDescendantOf

boolean isDescendantOf(NodeId ancestor)
Is the current node id a descendant of the specified node?

Parameters:
ancestor - node id of the potential ancestor
Returns:
true if the node id is a descendant of the given node, false otherwise

isDescendantOrSelfOf

boolean isDescendantOrSelfOf(NodeId ancestor)

isChildOf

boolean isChildOf(NodeId parent)
Is the current node a child node of the specified parent?

Parameters:
parent - the parent node
Returns:
true if the current node is a child of the specified parent

computeRelation

int computeRelation(NodeId ancestor)
Computes the relationship of this node to the given potential ancestor node. The method returns an int constant indicating the relation. Possible relations are: IS_CHILD, IS_DESCENDANT or IS_SELF. If the nodes are not in a ancestor-descendant relation, the method returns -1.

Parameters:
ancestor - the (potential) ancestor node to check against
Returns:
an int value indicating the relation

isSiblingOf

boolean isSiblingOf(NodeId sibling)

getTreeLevel

int getTreeLevel()
Returns the level within the document tree at which this node occurs.

Returns:
the tree level

compareTo

int compareTo(NodeId other)

equals

boolean equals(NodeId other)

size

int size()
Returns the size (in bytes) of this node id. Depends on the concrete implementation.

Returns:
size

units

int units()

serialize

void serialize(byte[] data,
               int offset)
Serializes the node id to an array of bytes. The first byte is written at offset.

Parameters:
data - the byte array to be filled
offset - offset into the array

write

void write(VariableByteOutputStream os)
           throws IOException
Write the node id to a VariableByteOutputStream.

Parameters:
os - the output stream
Throws:
IOException - if there's a problem with the underlying output stream

write

NodeId write(NodeId previous,
             VariableByteOutputStream os)
             throws IOException
Write the node id to a VariableByteOutputStream. To save storage space, only store those byte which are different from the previous node id.

Parameters:
previous - the node id previously written or null
os - the output stream
Returns:
this node id
Throws:
IOException - if there's a problem with the underlying output stream


Copyright (C) Wolfgang Meier. All rights reserved.