Package com.qfs.graph

Interface ITree<K,V,E>

Type Parameters:
K - the type of the keys for the vertices.
V - the type of the content for the vertices.
E - the type of the edges. Edge convention: a null value for an edge between two nodes is interpreted as the absence of edges between these two nodes.
All Superinterfaces:
Cloneable, IDirectedGraph<K,V,E>, Map<K,V>
All Known Subinterfaces:
IQueryStoreTree
All Known Implementing Classes:
QueryStoreTree, Tree

public interface ITree<K,V,E> extends IDirectedGraph<K,V,E>, Cloneable
Represent a tree. A tree is a particular type of directed graph.
Author:
ActiveViam
  • Method Details

    • getRoot

      K getRoot()
      Returns the root of the tree.
    • getChildren

      Collection<K> getChildren(K node) throws NullPointerException
      Each node of the tree has potentially children nodes.
      Parameters:
      node - the node for which children are required. Should not be null.
      Returns:
      the children of this node. Will be empty but not null.
      Throws:
      NullPointerException - if node is null.
    • getParent

      K getParent(K node) throws NullPointerException
      Each node of a tree but the root has a parent.
      Parameters:
      node - the node for which the parent is asked. Should not be null.
      Returns:
      the parent of this node, or null if this node is the root of the tree.
      Throws:
      NullPointerException - if node is null.
    • addChild

      void addChild(K parent, K node, V value, E edge) throws NullPointerException
      Add a child to a node in the tree.
      Parameters:
      parent - the node to which a child should be added.
      node - the new node to add to the tree as child of parent.
      value - the value that the new node should contain.
      edge - the edge between parent and node.
      Throws:
      NullPointerException - if parent or node are null.
    • replaceSubtree

      void replaceSubtree(K node, ITree<K,V,E> subtree)
      Inserts the given subtree into the current tree at the given node, replacing the previous subtree if its exsits. For the node where the change takes place, the key remains the same but the value is the one of the root of the given subtree. It modifies the tree so you might want clone() it beforehand depending on your use case.
       For instance, if the current tree T looks like (a key:value):
       a:a
        └── b:b
             ├── c:c
             └── d:d
       and the subtree ST is:
       z:z
        ├── x:x
        └── y:y
       The tree will look like this 
       T.replace(b, ST)
       :
       a:a
        └── b:z
             ├── x:x
             └── y:y
       
      Parameters:
      node - where to insert the tree
      subtree - the tree to insert
    • clone

      ITree<K,V,E> clone()
      Returns a shallow copy of this ITree instance (the nodes are not cloned) but only the internal tree structures are.
      Returns:
      a clone of this instance.