private void findContained(ShapeId container, Collection<Shape> shapes) {
        Set<ResourceShape> containedResources = new TreeSet<>();
        Set<OperationShape> containedOperations = new TreeSet<>();

        for (Shape shape : shapes) {
            if (!shape.getId().equals(container)) {
                if (shape instanceof ResourceShape) {
                    containedResources.add((ResourceShape) shape);
                } else if (shape instanceof OperationShape) {
                    containedOperations.add((OperationShape) shape);
                }
            }
        }

        operations.put(container, Collections.unmodifiableSet(containedOperations));
        resources.put(container, Collections.unmodifiableSet(containedResources));
    }
Provides top-down access to all resources and operations contained within a
service or resource closure.
smithy-model/src/main/java/software/amazon/smithy/model/knowledge/TopDownIndex.java