class SecurityAnalysisResultMerger {

    public static SecurityAnalysisResult merge(SecurityAnalysisResult[] results) {
        //If one of the subtasks has failed, return a failed result
        Objects.requireNonNull(results);
        for (SecurityAnalysisResult subResult : results) {
            if (!subResult.getPreContingencyResult().isComputationOk()) {
                return FAILED_SECURITY_ANALYSIS_RESULT;
            }
        }

        //Else, actually merge results
        final SecurityAnalysisResult res = new SecurityAnalysisResult(
                                results[0].getPreContingencyResult(), new ArrayList<>(results[0].getPostContingencyResults()))
                                .setNetworkMetadata(results[0].getNetworkMetadata());
        if (results.length > 1) {
            Arrays.stream(results, 1, results.length).forEach(r -> res.getPostContingencyResults().addAll(r.getPostContingencyResults()));
        }
        return res;
    }

    private  SecurityAnalysisResultMerger();

}