package org.onap.vid.utils data class Node(val value:T, val children:MutableMap> = hashMapOf()) data class Tree(private val root:Node) { constructor(value: T) : this(Node(value)) fun getRootValue():T { return root.value; } fun addPath(vararg path: T) { addPath(path.asList()) } fun addPath(path:Collection) { var currentNode = root path.forEach { currentNode = currentNode.children.getOrPut(it) {Node(it)} } } fun getSubTree(vararg path: T): Tree? { return getSubTree(path.asList()) } fun getSubTree(path:Collection): Tree? { var currentNode:Node = root path.forEach { currentNode = currentNode.children[it] ?: return null } return Tree(currentNode) } fun isPathExist(vararg path: T): Boolean { return isPathExist(path.asList()) } fun isPathExist(path:Collection): Boolean { return getSubTree(path)!=null } }