Hum indeed, it would be a bit clearer to have a method `String extractNodeIdWithParentId(String parentNodeId, Collection<HierarchyNode> nodes)` which would return the node which has `parentNodeId` for parent, and removes it from `nodes`.