gnu.lists
Class TreePosition

java.lang.Object
  extended by gnu.lists.SeqPosition
      extended by gnu.lists.TreePosition
All Implemented Interfaces:
java.lang.Cloneable, java.util.Enumeration, java.util.Iterator, java.util.ListIterator
Direct Known Subclasses:
Focus

public class TreePosition
extends SeqPosition
implements java.lang.Cloneable

A position that can also go down and up in a tree. A TreePosition is a stack of positions. The "current" position (i.e. the one you get if you tree the TreePosition as a SeqPosition) is that in the innermost containing sequence. Normally, the "current" element is (the one following) a position in a sequence. As a special (initial case), we may want to treat the entire sequence is the "current element". This is represented by depth==-1 and xpos set to the root element (which need not actually be a sequence).


Field Summary
 
Fields inherited from class gnu.lists.SeqPosition
ipos, sequence
 
Constructor Summary
TreePosition()
           
TreePosition(AbstractSequence seq, int index)
           
TreePosition(java.lang.Object root)
          Not a position *in* a sequence, but the current element is the entire sequence.
TreePosition(TreePosition pos)
           
 
Method Summary
 java.lang.Object clone()
           
 void dump()
          Copy this position into pos.
 java.lang.Object getAncestor(int up)
          Get the value of an ancestor node.
 int getDepth()
          Number of ancestor sequences, including current sequence.
 java.lang.Object getPosNext()
           
 AbstractSequence getRoot()
          Get the "root document".
 boolean gotoAttributesStart()
          Set position before first attribute (of the element following position).
 boolean gotoChildrenStart()
          Set position before first child (of the element following position).
 boolean gotoParent()
           
 void pop()
           
 void popNoRelease()
           
 void push(AbstractSequence child, int iposChild)
           
 void release()
           
 void set(TreePosition position)
           
 
Methods inherited from class gnu.lists.SeqPosition
add, copy, finalize, fromEndIndex, getContainingSequenceSize, getNext, getNextKind, getNextTypeName, getNextTypeObject, getPos, getPrevious, gotoEnd, gotoNext, gotoPrevious, gotoStart, hasMoreElements, hasNext, hasPrevious, isAfter, make, next, nextElement, nextIndex, previous, previousIndex, remove, set, set, set, setNext, setPos, setPos, setPrevious, toInfo, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TreePosition

public TreePosition()

TreePosition

public TreePosition(java.lang.Object root)
Not a position *in* a sequence, but the current element is the entire sequence.


TreePosition

public TreePosition(AbstractSequence seq,
                    int index)

TreePosition

public TreePosition(TreePosition pos)
Method Detail

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

set

public void set(TreePosition position)

getDepth

public int getDepth()
Number of ancestor sequences, including current sequence.


getRoot

public AbstractSequence getRoot()
Get the "root document".


getPosNext

public java.lang.Object getPosNext()

push

public void push(AbstractSequence child,
                 int iposChild)

pop

public void pop()

popNoRelease

public void popNoRelease()

gotoParent

public final boolean gotoParent()

gotoChildrenStart

public boolean gotoChildrenStart()
Set position before first child (of the element following position).

Overrides:
gotoChildrenStart in class SeqPosition
Returns:
true if there is a child sequence (which might be empty); false if current position is end of sequence or following element is atomic (cannot have children).

gotoAttributesStart

public boolean gotoAttributesStart()
Set position before first attribute (of the element following position). This is used to iterate through the sequence of attributes.


getAncestor

public java.lang.Object getAncestor(int up)
Get the value of an ancestor node.

Parameters:
up - the number parents to go up.
Returns:
if up is 0, same getNext. Otherwise get parent applied as specified.

release

public void release()
Overrides:
release in class SeqPosition

dump

public void dump()
Copy this position into pos.