private static Set aggregateInstancesByRegions()

in aws-cloudformation-stackset/src/main/java/software/amazon/cloudformation/stackset/util/InstancesAnalyzer.java [91:113]


    private static Set<StackInstances> aggregateInstancesByRegions(
            final Set<StackInstances> groupedStacks,
            final boolean isSelfManaged) {

        final Map<List<Object>, StackInstances> groupedStacksMap = new HashMap<>();
        for (final StackInstances stackInstances : groupedStacks) {
            final DeploymentTargets target = stackInstances.getDeploymentTargets();
            final Set<Parameter> parameterSet = stackInstances.getParameterOverrides();
            final List<Object> compositeKey = Arrays.asList(stackInstances.getRegions(), parameterSet);
            if (groupedStacksMap.containsKey(compositeKey)) {
                if (isSelfManaged) {
                    groupedStacksMap.get(compositeKey).getDeploymentTargets()
                            .getAccounts().addAll(target.getAccounts());
                } else {
                    groupedStacksMap.get(compositeKey).getDeploymentTargets()
                            .getOrganizationalUnitIds().addAll(target.getOrganizationalUnitIds());
                }
            } else {
                groupedStacksMap.put(compositeKey, stackInstances);
            }
        }
        return new HashSet<>(groupedStacksMap.values());
    }