findGroupId

The ledger id of the group at path, or null when this topology has no such group: a GroupPath.Declared it does not declare, a GroupPath.Attached whose group has no template, or a GroupPath.Nested whose parent's template carries no template. Never throws.

Gives the same id as groupId and attachedChildId wherever they do not throw, and is the exact inverse of findPath.

Samples

val pool = draft("pool") {
    group("tenants") {
        lane("x")
        template()
    }
}
// A declared lane and an attached child share the name `x`, and their paths stay apart.
val lane = GroupPath.Declared(listOf("tenants", "x"))
val tenant = GroupPath.Attached(group = listOf("tenants"), name = "x")
val laneId = checkNotNull(pool.findGroupId(lane))
val tenantId = checkNotNull(pool.findGroupId(tenant))
check(laneId == pool.groupId("tenants", "x") && tenantId == pool.attachedChildId(listOf("tenants"), "x"))
check(laneId != tenantId)

// Back from an id: the arm says whether the last name is an attached child's.
check(pool.findPath(laneId) == lane && pool.findPath(tenantId) == tenant)
check(pool.findPath(tenantId)?.names == listOf("tenants", "x"))
check(pool.findPath(pool.groupId()) == GroupPath.Declared(emptyList()))

// Not in this topology: `null`, never an exception.
check(pool.findGroupId(GroupPath.Declared(listOf("tenants", "y"))) == null)
check(pool.findGroupId(GroupPath.Attached(listOf("tenants", "x"), "y")) == null)
check(pool.findPath(GroupId("elsewhere/tenants")) == null)