Package io.openml.gearbox.binarytree
Class TreeGraph<T>
java.lang.Object
io.openml.gearbox.binarytree.TreeGraph<T>
- Type Parameters:
T
- The type of value store in the node of the original tree
TreeGraph
is a view on top of a binary tree and maps each tree node to its neighbors, including parent and
left&right children.
For example, a tree of
1
/ \
2 3
/
4
will be represented as a map as
[
3:[1],
4:[2],
1:[2, 3],
2:[1, 4]
]-
Method Summary
Modifier and TypeMethodDescriptionReturns an immutable list of all neighbors to which the specifiedTreeNode
key is mapped, orCollections.emptyList()
if thisTreeGraph
map contains no mapping for the key.keySet()
Returns an immutableSet
view of the all nodes of the original tree.static <T> TreeGraph<T>
Creates the map view of a specified tree.
-
Method Details
-
of
Creates the map view of a specified tree.- Type Parameters:
T
- The type of value store in the node of the original tree- Parameters:
root
- The root of the provided tree- Returns:
- a new
TreeGraph
instance - Throws:
NullPointerException
- if theroot
isnull
-
get
Returns an immutable list of all neighbors to which the specifiedTreeNode
key is mapped, orCollections.emptyList()
if thisTreeGraph
map contains no mapping for the key.More formally, if this map contains a mapping from a key
k
to a listl
such that(key == null ? k == null : key.equals(k))
, then this method returnsl
; otherwise it returnsCollections.emptyList()
. (There can be at most one such mapping.)- Parameters:
key
- TheTreeNode
key whose associated list of values is to be returned- Returns:
- the list of neighbors to which the specified key is mapped, or
Collections.emptyList()
if this map contains no mapping for the key - Throws:
NullPointerException
- if the specified key isnull
-
keySet
Returns an immutableSet
view of the all nodes of the original tree.- Returns:
- A set view of the keys contained in this map
-