org.exist.numbering
Class DLN

java.lang.Object
  extended by org.exist.numbering.DLNBase
      extended by org.exist.numbering.DLN
All Implemented Interfaces:
Comparable, NodeId

public class DLN
extends DLNBase
implements NodeId

Represents a node id in the form of a dynamic level number (DLN). DLN's are hierarchical ids, which borrow from Dewey's decimal classification. Examples for node ids: 1, 1.1, 1.2, 1.2.1, 1.2.2, 1.3. In this case, 1 represents the root node, 1.1 is the first node on the second level, 1.2 the second, and so on. To support efficient insertion of new nodes between existing nodes, we use the concept of sublevel ids. Between two nodes 1.1 and 1.2, a new node can be inserted as 1.1/1, where the / is the sublevel separator. The / does not start a new level. 1.1 and 1.1/1 are thus on the same level of the tree. In the binary encoding, the '.' is represented by a 0-bit while '/' is written as a 1-bit.


Field Summary
 
Fields inherited from class org.exist.numbering.DLNBase
BIT_MASK, BITS_PER_UNIT
 
Fields inherited from interface org.exist.numbering.NodeId
DOCUMENT_NODE, END_OF_DOCUMENT, IS_CHILD, IS_DESCENDANT, IS_SELF, LENGTH_NODE_ID_UNITS, ROOT_NODE
 
Constructor Summary
DLN()
          Constructs a new DLN with a single id with value 1.
DLN(byte prefixLen, DLN previous, short bitCnt, VariableByteInput is)
           
DLN(DLN other)
          Constructs a new DLN by copying the data of the passed DLN.
DLN(int id)
          Constructs a new DLN, using the passed id as its single level value.
DLN(int units, byte[] data, int startOffset)
          Reads a DLN from the given byte[].
DLN(short bitCnt, VariableByteInput is)
          Reads a DLN from the given VariableByteInput stream.
DLN(String s)
          Constructs a new DLN by parsing the string argument.
 
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 otherId)
           
 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 otherId)
           
 int compareTo(Object 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 DLN 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 other)
           
 boolean isSiblingOf(NodeId sibling)
           
static void main(String[] args)
           
 NodeId newChild()
          Returns a new DLN representing the first child node of this node.
 NodeId nextSibling()
          Returns a new DLN representing the next following sibling of this node.
 NodeId precedingSibling()
          Returns a new NodeId representing the prececing sibling of this node.
 NodeId write(NodeId prevId, VariableByteOutputStream os)
          Write the node id to a VariableByteOutputStream.
 void write(VariableByteOutputStream os)
          Write the node id to a VariableByteOutputStream.
 
Methods inherited from class org.exist.numbering.DLNBase
addLevelId, compareBits, debug, decrementLevelId, equals, getLengthInBytes, getLevelCount, getLevelId, getLevelIds, getSubLevelCount, incrementLevelId, isLevelSeparator, lastLevelOffset, serialize, setLevelId, size, startsWith, toBitString, toBitString, toString, units
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.exist.numbering.NodeId
serialize, size, units
 

Constructor Detail

DLN

public DLN()
Constructs a new DLN with a single id with value 1.


DLN

public DLN(String s)
Constructs a new DLN by parsing the string argument. In the string, levels are separated by a '.', sublevels by a '/'. For example, '1.2/1' or '1.2/1.2' are valid ids.

Parameters:
s -

DLN

public DLN(int id)
Constructs a new DLN, using the passed id as its single level value.

Parameters:
id -

DLN

public DLN(DLN other)
Constructs a new DLN by copying the data of the passed DLN.

Parameters:
other -

DLN

public DLN(int units,
           byte[] data,
           int startOffset)
Reads a DLN from the given byte[].

Parameters:
units - number of bits to read
data - the byte[] to read from
startOffset - the start offset to start reading at

DLN

public DLN(short bitCnt,
           VariableByteInput is)
    throws IOException
Reads a DLN from the given VariableByteInput stream.

Parameters:
is -
Throws:
IOException
See Also:
write(VariableByteOutputStream)

DLN

public DLN(byte prefixLen,
           DLN previous,
           short bitCnt,
           VariableByteInput is)
    throws IOException
Throws:
IOException
Method Detail

newChild

public NodeId newChild()
Returns a new DLN representing the first child node of this node.

Specified by:
newChild in interface NodeId
Returns:
new child node id

nextSibling

public NodeId nextSibling()
Returns a new DLN representing the next following sibling of this node.

Specified by:
nextSibling in interface NodeId
Returns:
new sibling node id.

precedingSibling

public NodeId precedingSibling()
Description copied from interface: NodeId
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.

Specified by:
precedingSibling in interface NodeId
Returns:
new sibling node id.

getChild

public NodeId getChild(int child)
Description copied from interface: NodeId
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.

Specified by:
getChild in interface NodeId
Parameters:
child - the position of the child
Returns:
new node id

insertNode

public NodeId insertNode(NodeId right)
Specified by:
insertNode in interface NodeId

insertBefore

public NodeId insertBefore()
Specified by:
insertBefore in interface NodeId

append

public NodeId append(NodeId otherId)
Specified by:
append in interface NodeId

getParentId

public NodeId getParentId()
Returns a new DLN representing the parent of the current node. If the current node is the root element of the document, the method returns NodeId.DOCUMENT_NODE. If the current node is the document node, null is returned.

Specified by:
getParentId in interface NodeId
Returns:
the id of the parent node or null if the current node is the document node.
See Also:
NodeId.getParentId()

isDescendantOf

public boolean isDescendantOf(NodeId ancestor)
Description copied from interface: NodeId
Is the current node id a descendant of the specified node?

Specified by:
isDescendantOf in interface NodeId
Parameters:
ancestor - node id of the potential ancestor
Returns:
true if the node id is a descendant of the given node, false otherwise

isDescendantOrSelfOf

public boolean isDescendantOrSelfOf(NodeId other)
Specified by:
isDescendantOrSelfOf in interface NodeId

isChildOf

public boolean isChildOf(NodeId parent)
Description copied from interface: NodeId
Is the current node a child node of the specified parent?

Specified by:
isChildOf in interface NodeId
Parameters:
parent - the parent node
Returns:
true if the current node is a child of the specified parent

computeRelation

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

Specified by:
computeRelation in interface NodeId
Parameters:
ancestor - the (potential) ancestor node to check against
Returns:
an int value indicating the relation

isSiblingOf

public boolean isSiblingOf(NodeId sibling)
Specified by:
isSiblingOf in interface NodeId

getTreeLevel

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

Specified by:
getTreeLevel in interface NodeId
Returns:
the tree level

equals

public boolean equals(NodeId other)
Specified by:
equals in interface NodeId

compareTo

public int compareTo(Object other)
Specified by:
compareTo in interface Comparable

compareTo

public int compareTo(NodeId otherId)
Specified by:
compareTo in interface NodeId

after

public boolean after(NodeId other,
                     boolean isFollowing)
Description copied from interface: NodeId
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.

Specified by:
after in interface NodeId
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

public boolean before(NodeId other,
                      boolean isPreceding)
Description copied from interface: NodeId
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.

Specified by:
before in interface NodeId
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.

write

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

Specified by:
write in interface NodeId
Parameters:
os -
Throws:
IOException

write

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

Specified by:
write in interface NodeId
Parameters:
prevId - 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

main

public static void main(String[] args)
                 throws IOException
Throws:
IOException


Copyright (C) Wolfgang Meier. All rights reserved.