cz.cuni.mff.mirovsky.trees
Class NGForest

java.lang.Object
  extended by cz.cuni.mff.mirovsky.trees.NGForest

public class NGForest
extends java.lang.Object

A class keeping a forest of trees. It is usually only one tree, in case of multi-tree query it consists of several trees.


Field Summary
static byte EOL
          a line break in messages with the server.
static byte EOL_2
          an alternative line break in messages with the server.
static byte EOM
          an end-of-message character in messages with the server.
 
Constructor Summary
NGForest(ShowMessagesAble mess)
          Creates a new empty forest.
 
Method Summary
 void addAttributes(int number)
          It increases number of attributes at all nodes of all trees by number.
 void addTree(NGTree tree)
          Adds a tree as the new last tree in the forest.
 TNode findNodeById(int id_index, java.lang.String value)
          Searches for a node in the forest that has a given id.
 NGForest getClone()
          Returns a deep copy of the forest.
 java.lang.String getFileName()
          Return the file name the forest comes from.
 int getFirstMatchingNodeDepthOrder(boolean count_hidden)
          Returns depth-first order (counted from 1) of the node matching the root of the first tree of the query.
 boolean getFlagForestChanged()
          Says whether the forest has changed and coordinates of (some of) its trees and their nodes must be calculated.
 int getForestNumber()
          Returns the number of the forest in the file it comes from.
 NGTreeHead getHead()
          Returns the head of the forest.
 TNode getChosenNode()
          Returns the actually selected node.
 int getChosenNodeDepthOrder(boolean count_hidden)
          Returns depth-first order of the chosen node, counted from 1.
 NGTree getChosenTree()
          Returns the actually selected tree.
 int getChosenTreeOrder()
          Returns the order of the selected tree (the tree with the selected node), counted from 1.
 java.lang.String getId()
          Returns an id of the first tree in the forest.
 int getNumberOfHiddenNodes()
          Returns the total number of hidden nodes in all trees in the forest.
 int getNumberOfNodes()
          Returns the total number of all nodes in all trees in the forest.
 int getNumberOfTrees()
          Returns the number of trees in the forest.
 java.util.ArrayList<NGTree> getTrees()
          Returns the trees of the forest in ArrayList.
 javax.swing.DefaultListModel getVybraneAtributy()
          Returns a list of selected attributes.
 int readForest(char[] p_source, int start_position, int p_number_of_attributes)
          Reads a forest from p_source in FS format (without a head).
 void setFileName(java.lang.String p_name)
          Sets the name of the file the forest comes from.
 void setFlagForestChanged(boolean flag)
          Signals whether a tree in the forest has changed and coordinates the tree and its nodes and coordinates of the subsequent trees must be calculated.
 void setFlagWholeForestChanged(boolean flag)
          Signals whether the whole forest has changed and coordinates of all its trees and their nodes must be calculated.
 void setForestNumber(int number)
          Sets the number of the forest in the file it comes from.
 void setHead(NGTreeHead head)
          Sets a head of the forest.
 void setChosenNodeByDepthOrder(int order)
          Marks a node with given order as selected, as well as the tree the node is from.
 void setChosenTreeByOrder(int order)
          Sets the tree with a given order as selected.
 void setMatchingMetaTags()
          It sets the matching meta tag at the matching nodes of the trees of the forest.
 void setVybraneAtributy(javax.swing.DefaultListModel p_vybrane_atributy)
          Sets a list of selected attributes.
 java.lang.String toFSString(boolean with_head)
          Returns FS representation of the forest (with or without the head).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOL

public static final byte EOL
a line break in messages with the server. It is a copy of the value from object ServerCommunication; if changed there, it must be changed here, too.

See Also:
Constant Field Values

EOL_2

public static final byte EOL_2
an alternative line break in messages with the server. It is a copy of the value from object ServerCommunication; if changed there, it must be changed here, too.

See Also:
Constant Field Values

EOM

public static final byte EOM
an end-of-message character in messages with the server. It is a copy of the value from object ServerCommunication; if changed there, it must be changed here, too.

See Also:
Constant Field Values
Constructor Detail

NGForest

public NGForest(ShowMessagesAble mess)
Creates a new empty forest.

Parameters:
mess - an object capable of displaying messages
Method Detail

getClone

public NGForest getClone()
Returns a deep copy of the forest.

Returns:
deep copy of the forest

toFSString

public java.lang.String toFSString(boolean with_head)
Returns FS representation of the forest (with or without the head).

Parameters:
with_head - says if the head should be included in the FS representation
Returns:
the FS representation of the forest

getId

public java.lang.String getId()
Returns an id of the first tree in the forest.

Returns:
an id of the first tree in the forest or an emtpy String if there are no trees.

getNumberOfTrees

public int getNumberOfTrees()
Returns the number of trees in the forest.

Returns:
the number of trees in the forest

addTree

public void addTree(NGTree tree)
Adds a tree as the new last tree in the forest.

Parameters:
tree - a tree to be added

setFlagWholeForestChanged

public void setFlagWholeForestChanged(boolean flag)
Signals whether the whole forest has changed and coordinates of all its trees and their nodes must be calculated.

Parameters:
flag - value true signals that the coordinates need to be calculated

setFlagForestChanged

public void setFlagForestChanged(boolean flag)
Signals whether a tree in the forest has changed and coordinates the tree and its nodes and coordinates of the subsequent trees must be calculated.

Parameters:
flag - value true signals that the coordinates need to be calculated

getFlagForestChanged

public boolean getFlagForestChanged()
Says whether the forest has changed and coordinates of (some of) its trees and their nodes must be calculated.

Returns:
true iff the coordinates need to be calculated

getHead

public NGTreeHead getHead()
Returns the head of the forest.

Returns:
the head of the forest

setHead

public void setHead(NGTreeHead head)
Sets a head of the forest.

Parameters:
head - a head

getTrees

public java.util.ArrayList<NGTree> getTrees()
Returns the trees of the forest in ArrayList.

Returns:
the trees in ArrayList

getVybraneAtributy

public javax.swing.DefaultListModel getVybraneAtributy()
Returns a list of selected attributes. Selected attributes are displayed at nodes in the tree.

Returns:
a list of selected attributes

setVybraneAtributy

public void setVybraneAtributy(javax.swing.DefaultListModel p_vybrane_atributy)
Sets a list of selected attributes. Selected attributes are displayed at nodes in the tree.

Parameters:
p_vybrane_atributy - the list of selected attributes

getNumberOfNodes

public int getNumberOfNodes()
Returns the total number of all nodes in all trees in the forest.

Returns:
the total number of all nodes in all trees in the forest

getNumberOfHiddenNodes

public int getNumberOfHiddenNodes()
Returns the total number of hidden nodes in all trees in the forest.

Returns:
the total number of hidden nodes in all trees in the forest

addAttributes

public void addAttributes(int number)
It increases number of attributes at all nodes of all trees by number. The new attributes are added at the end of the list of attributes. Values of the new attributes are set empty (""). The head of the forest is not changed (must be changed separately).

Parameters:
number - number of attributes to be added

setMatchingMetaTags

public void setMatchingMetaTags()
It sets the matching meta tag at the matching nodes of the trees of the forest. The matching meta tag marks matching nodes after the forest is saved e.g. to local disc.


getChosenNode

public TNode getChosenNode()
Returns the actually selected node.

Returns:
the selected node

getChosenTree

public NGTree getChosenTree()
Returns the actually selected tree.

Returns:
the selected tree

getFileName

public java.lang.String getFileName()
Return the file name the forest comes from.

Returns:
the name of the file the forest comes from

setFileName

public void setFileName(java.lang.String p_name)
Sets the name of the file the forest comes from.

Parameters:
p_name - the name of the file the forest comes from

getForestNumber

public int getForestNumber()
Returns the number of the forest in the file it comes from. It is counted from 1.

Returns:
the number of the forest in the file it comes from

setForestNumber

public void setForestNumber(int number)
Sets the number of the forest in the file it comes from. It is counted from 1.

Parameters:
number - the number of the forest in the file it comes from

setChosenNodeByDepthOrder

public void setChosenNodeByDepthOrder(int order)
Marks a node with given order as selected, as well as the tree the node is from. The root of the first tree has order 1, the first tree has order 1, the first node of each subsequent tree has the order like the last node of the previous tree plus 1.

Parameters:
order - depth-first order of the node to be selected

getChosenNodeDepthOrder

public int getChosenNodeDepthOrder(boolean count_hidden)
Returns depth-first order of the chosen node, counted from 1. If count_hidden is true, hidden nodes are counted as normal nodes. If count_hidden is false, hidden nodes are not counted; if the chosen node is hidden, the order of its nearest non-hidden predecessor is returned. The root of the first tree is 1, the order of the root of any other tree is 1 bigger than the order of the last node of the previous tree.

Parameters:
count_hidden - says if hidden nodes should be counted
Returns:
-1 if not found; a positive value (depth-first order counted from 1) if found; 0 if the chosen node is hidden, count_hidden is false and there is no non-hidden node is on the path from it to the root (if in the first tree, otherwise returns the order of the last node in the previous tree)

getFirstMatchingNodeDepthOrder

public int getFirstMatchingNodeDepthOrder(boolean count_hidden)
Returns depth-first order (counted from 1) of the node matching the root of the first tree of the query. If count_hidden is true, hidden nodes are counted as normal nodes. If count_hidden is false, hidden nodes are not counted; if the matching node is hidden, the order of its nearest non-hidden predecessor is returned. The root of the first tree is 1, the order of the root of any other tree is 1 bigger than the order of the last node of the previous tree.

Parameters:
count_hidden - says if hidden nodes should be counted
Returns:
-1 if not found; a positive value (depth-first order counted from 1) if found; 0 if the matching node is hidden, count_hidden is false and there is no non-hidden node is on the path from it to the root (if in the first tree, otherwise returns the order of the last node in the previous tree)

getChosenTreeOrder

public int getChosenTreeOrder()
Returns the order of the selected tree (the tree with the selected node), counted from 1.

Returns:
the order of the selected tree

setChosenTreeByOrder

public void setChosenTreeByOrder(int order)
Sets the tree with a given order as selected. The order of the first tree is 1.

Parameters:
order - the order of the tree to be selected

findNodeById

public TNode findNodeById(int id_index,
                          java.lang.String value)
Searches for a node in the forest that has a given id.

Parameters:
id_index - an index of the id-attribute in the head of the forest
value - an identifier to be searched for
Returns:
the node with the given id or null if not found

readForest

public int readForest(char[] p_source,
                      int start_position,
                      int p_number_of_attributes)
Reads a forest from p_source in FS format (without a head). The head must have already been set.

Parameters:
p_source - the source in FS format
start_position - a position in p_source of the first character to be read
p_number_of_attributes - number of attributes in the head
Returns:
the number of read characters