findPath
Where group sits in this topology, or null unless group is exactly an id findGroupId returns for it. Never throws.
So the two are exact inverses: findPath(id) is a path p exactly when findGroupId(p) is id. An id from a group this topology no longer declares, from a topology with another root, or in no topology's grammar at all reads as null.
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)Content copied to clipboard