feat: Number of children #421

This commit is contained in:
J-Jamet 2024-10-20 21:15:21 +02:00
parent 0312b504a9
commit 9fb4754430
12 changed files with 72 additions and 38 deletions

View file

@ -295,19 +295,19 @@ class Group : Node, GroupVersionedInterface<Group, Entry> {
*/
private fun getNumberOfChildEntriesInGroups(filter: (Node) -> Boolean): Int {
var counter = 0
getChildGroups().forEach { childGroup ->
getChildGroups().filter(filter).forEach { childGroup ->
counter += childGroup.getNumberOfChildEntriesInGroups(filter)
}
return getChildEntries().filter(filter).size + counter
}
fun getNumberOfChildEntries(
directChildren: Boolean = true,
recursive: Boolean = false,
filter: (Node) -> Boolean = { true }
): Int {
numberOfChildEntries = getChildEntries().filter(filter).size
recursiveNumberOfChildEntries = getNumberOfChildEntriesInGroups(filter)
return if (directChildren) numberOfChildEntries else recursiveNumberOfChildEntries
return if (recursive) recursiveNumberOfChildEntries else numberOfChildEntries
}
/**