X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=vid-app-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fvid%2Futils%2FTree.kt;h=62453756ff2634e5a7aa210ac925d056a3977e90;hb=e601bbdc43bae9a08e2e10c5139a6f76b47860d7;hp=35e913d1670e130a44bacfe6ea53ee3eb00e972d;hpb=76c6ee4a697617ec4cdee2f3b48bc83136c858c5;p=vid.git diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Tree.kt b/vid-app-common/src/main/java/org/onap/vid/utils/Tree.kt index 35e913d16..62453756f 100644 --- a/vid-app-common/src/main/java/org/onap/vid/utils/Tree.kt +++ b/vid-app-common/src/main/java/org/onap/vid/utils/Tree.kt @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -41,6 +41,14 @@ data class Tree(private val root:Node) { } } + fun getChildrenDepth(): Int { + return getMaxDepth(root) - 1 + } + + private fun getMaxDepth(level:Node): Int { + return (level.children.map{getMaxDepth(it.value)}.max() ?: 0) + 1 + } + fun getSubTree(vararg path: T): Tree? { return getSubTree(path.asList()) }