static EndpointGroup of(EndpointSelectionStrategy selectionStrategy,
                            Iterable<? extends EndpointGroup> endpointGroups) {
        requireNonNull(selectionStrategy, "selectionStrategy");
        requireNonNull(endpointGroups, "endpointGroups");

        final List<EndpointGroup> groups = new ArrayList<>();
        final List<Endpoint> staticEndpoints = new ArrayList<>();
        for (EndpointGroup endpointGroup : endpointGroups) {
            // We merge raw Endpoint and StaticEndpointGroup into one StaticEndpointGroup for a bit of
            // efficiency.
            if (endpointGroup instanceof Endpoint) {
                staticEndpoints.add((Endpoint) endpointGroup);
            } else if (endpointGroup instanceof StaticEndpointGroup) {
                staticEndpoints.addAll(endpointGroup.endpoints());
            } else {
                groups.add(endpointGroup);
            }
        }

        if (groups.isEmpty() && staticEndpoints.isEmpty()) {
            return of();
        }

        if (groups.isEmpty()) {
            if (staticEndpoints.size() == 1) {
                // Only one static endpoint, can return it directly.
                return staticEndpoints.get(0);
            }
            // Only static endpoints, return an optimized endpoint group.
            return new StaticEndpointGroup(selectionStrategy, staticEndpoints);
        }

        if (!staticEndpoints.isEmpty()) {
            groups.add(new StaticEndpointGroup(selectionStrategy, staticEndpoints));
        }

        if (groups.size() == 1) {
            return groups.get(0);
        }

        return new CompositeEndpointGroup(selectionStrategy, groups);
    }
Returns an {@link EndpointGroup} that combines all the {@link Endpoint}s of {@code endpointGroups}.
{@code endpointGroups} can be instances of {@link Endpoint} as well, any {@link EndpointGroup}s and
{@link Endpoint} will all be combined into a single {@link EndpointGroup} that contains the total set.
core/src/main/java/com/linecorp/armeria/client/endpoint/EndpointGroup.java