Structured Text Toolkit

com.saelist.stx
Class Pair

java.lang.Object
  extended bycom.saelist.stx.Pair

public class Pair
extends java.lang.Object

The central data structure of the toolkit. A Pair contains text (key) and optionally a list of pairs (values). The term 'value' is used to refer to the text of the first sub-pair.


Field Summary
protected  int indent
           
static Logger logger
           
protected  PairList pairList
           
protected  Pair parent
           
protected  int srcColumn
           
protected  int srcLine
           
protected  java.lang.String text
           
 
Constructor Summary
protected Pair()
           
  Pair(Pair parent, int indent, java.lang.String line, int srcLine, int srcColumn)
           
  Pair(Pair parent, java.lang.String text)
           
 
Method Summary
 void add(int pos, Pair pair)
          Insert the pair at position pos in the list of sub-pairs.
 void add(Pair pair)
          Appends the pair to the list of sub-pairs.
 void clear()
          Removes all sub-pairs.
 Pair copy()
           
 boolean equals(java.lang.Object object)
          Two pairs are equal if their texts are equals and their sub-pairs match.
 java.lang.String eval(java.lang.String xpath)
          Returns the concatenated texts of all sub-pairs of the matching xpaths or "" if none match.
 java.lang.String eval1(java.lang.String xpath)
          Returns the 'value' of the first pair maching the xpath or "" if none.
 Pair get(int index)
           
 Pair get(java.lang.String text)
           
 int getIndent()
           
 java.util.Iterator getPairs()
           
 Pair getParent()
           
 Pair getRoot()
           
 int getSrcColumn()
           
 int getSrcLine()
           
 java.lang.String getText()
           
 java.lang.String getValue()
          Returns the text of the first sub-pair or "" if none exists.
 java.lang.String getValues()
          Returns the concatenated texts of all sub-pairs or "" if non exist.
 int hashCode()
           
 void remove(Pair pair)
          Removes the pair from the list of sub-pairs.
 java.util.Iterator select(java.lang.String xpath)
          Returns the pairs matching the xpath.
 Pair select1(java.lang.String xpath)
          Returns the 1st pair matching the xpath or null if none matches.
 void setParent(Pair parent)
           
 void setText(java.lang.String text)
           
 int size()
           
 java.lang.String toString()
          A String of the form text[ sub-pair1 sub-pair2 ...
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

public static Logger logger

parent

protected Pair parent

text

protected java.lang.String text

pairList

protected PairList pairList

indent

protected int indent

srcLine

protected int srcLine

srcColumn

protected int srcColumn
Constructor Detail

Pair

public Pair(Pair parent,
            java.lang.String text)

Pair

public Pair(Pair parent,
            int indent,
            java.lang.String line,
            int srcLine,
            int srcColumn)

Pair

protected Pair()
Method Detail

getSrcColumn

public int getSrcColumn()

getSrcLine

public int getSrcLine()

getIndent

public int getIndent()

getRoot

public Pair getRoot()

getParent

public Pair getParent()

setParent

public void setParent(Pair parent)

setText

public void setText(java.lang.String text)

getText

public java.lang.String getText()

get

public Pair get(java.lang.String text)
Returns:
the first sub-pair with the given text or null if none exists.

get

public Pair get(int index)
Returns:
the index'th sub-pair if any.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index exceeds size.

getPairs

public java.util.Iterator getPairs()
Returns:
an Iterator over the sub-pairs, potentially empty.

getValue

public java.lang.String getValue()
Returns the text of the first sub-pair or "" if none exists.


getValues

public java.lang.String getValues()
Returns the concatenated texts of all sub-pairs or "" if non exist. Values are separated by a space.


select

public java.util.Iterator select(java.lang.String xpath)
Returns the pairs matching the xpath.


select1

public Pair select1(java.lang.String xpath)
Returns the 1st pair matching the xpath or null if none matches.


eval1

public java.lang.String eval1(java.lang.String xpath)
Returns the 'value' of the first pair maching the xpath or "" if none.


eval

public java.lang.String eval(java.lang.String xpath)
Returns the concatenated texts of all sub-pairs of the matching xpaths or "" if none match.


add

public void add(int pos,
                Pair pair)
Insert the pair at position pos in the list of sub-pairs.

Throws:
java.lang.IndexOutOfBoundsException - if no such position exists. I.e. if pos > size().

add

public void add(Pair pair)
Appends the pair to the list of sub-pairs.


clear

public void clear()
Removes all sub-pairs. Does not change the parent property of the removed pairs.


remove

public void remove(Pair pair)
Removes the pair from the list of sub-pairs. Does not change the parent property of the removed pair.


copy

public Pair copy()
Returns:
a deep copy of this pair.

size

public int size()
Returns:
the number of sub-pairs.

toString

public java.lang.String toString()
A String of the form text[ sub-pair1 sub-pair2 ... ] where each sub-pair may also be composite.


hashCode

public int hashCode()

equals

public boolean equals(java.lang.Object object)
Two pairs are equal if their texts are equals and their sub-pairs match.


Structured Text Toolkit