1 package org.onap.vid.utils
3 data class Node<T>(val value:T, val children:MutableMap<T, Node<T>> = hashMapOf())
5 data class Tree<T>(private val root:Node<T>) {
7 constructor(value: T) : this(Node(value))
13 fun addPath(vararg path: T) {
14 addPath(path.asList())
17 fun addPath(path:Collection<T>) {
18 var currentNode = root
20 currentNode = currentNode.children.getOrPut(it) {Node(it)}
24 fun getSubTree(vararg path: T): Tree<T>? {
25 return getSubTree(path.asList())
28 fun getSubTree(path:Collection<T>): Tree<T>? {
29 var currentNode:Node<T> = root
31 currentNode = currentNode.children[it] ?: return null
33 return Tree(currentNode)
36 fun isPathExist(vararg path: T): Boolean {
37 return isPathExist(path.asList())
40 fun isPathExist(path:Collection<T>): Boolean {
41 return getSubTree(path)!=null