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
Represent a tree. A tree is a particular type of directed graph.
- Author:
- ActiveViam
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a child to a node in the tree.clone()Returns a shallow copy of thisITreeinstance (the nodes are not cloned) but only the internal tree structures are.getChildren(K node) Each node of the tree has potentially children nodes.Each node of a tree but the root has a parent.getRoot()Returns the root of the tree.voidInserts the given subtree into the current tree at the given node, replacing the previous subtree if its exsits.Methods inherited from interface com.qfs.graph.IDirectedGraph
addNode, filterEdges, forEachNode, getEdge, getEdges, getEdgesFrom, getEdgesTo, getNodes, getReached, getReachers, getTo, hasEdge, isAcyclic, moveKey, removeEdge, removeNode, setEdge, setNodeMethods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Method Details
-
getRoot
K getRoot()Returns the root of the tree. -
getChildren
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
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
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 newnodeshould contain.edge- the edge betweenparentandnode.- Throws:
NullPointerException- ifparentornodeare null.
-
replaceSubtree
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 wantclone()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 thisT.replace(b, ST): a:a └── b:z ├── x:x └── y:y- Parameters:
node- where to insert the treesubtree- the tree to insert
-
clone
Returns a shallow copy of thisITreeinstance (the nodes are not cloned) but only the internal tree structures are.- Returns:
- a clone of this instance.
-