ifs-rest-util/src/main/java/org/innovateuk/ifs/commons/service/BaseFailingOrSucceedingResult.java
/**
     * Function to aggregate a {@link List} of {@link BaseFailingOrSucceedingResult}.
     */
Function to aggregate a  List of  BaseFailingOrSucceedingResult.
Function to aggregate a List of BaseFailingOrSucceedingResult .
@SuppressWarnings("unchecked")
    protected static <
            Item,
            FailureType extends ErrorHolder,
            Result extends BaseFailingOrSucceedingResult<List<Item>, FailureType>,
            Input extends BaseFailingOrSucceedingResult<Item, FailureType>
            > Result aggregate(
                    final List<Input> input,
                    final BinaryOperator<FailureType> failureCollector,
                    final Result emptyResult) {
        if (input == null || input.isEmpty()) {
            return emptyResult;
        }
        final Input firstResult = input.get(0);
        final List<Item> items = new ArrayList<>();
        final List<FailureType> failures = new ArrayList<>();
        for (final Input i : input) {
            if (i.isSuccess()) {
                items.add(i.getSuccess());
            } else {
                failures.add(i.getFailure());
            }
        }
        if (failures.isEmpty()) {
            return (Result) firstResult.createSuccess(items);
        } else {
            final BaseFailingOrSucceedingResult<Item, FailureType> failure = firstResult.createFailure(failures.stream().reduce(null, nullSafe(failureCollector)));
            return (Result) failure;
        }
    }
@ SuppressWarnings ( "unchecked" ) protected static < Item , FailureType extends ErrorHolder , Result extends BaseFailingOrSucceedingResult < List < Item > , FailureType > , Input extends BaseFailingOrSucceedingResult < Item , FailureType > > Result aggregate ( final List < Input > input , final BinaryOperator < FailureType > failureCollector , final Result emptyResult ) { if ( input == null || input . isEmpty ( ) ) { return emptyResult ; } final Input firstResult = input . get ( 0 ) ; final List < Item > items = new ArrayList < > ( ) ; final List < FailureType > failures = new ArrayList < > ( ) ; for ( final Input i : input ) { if ( i . isSuccess ( ) ) { items . add ( i . getSuccess ( ) ) ; } else { failures . add ( i . getFailure ( ) ) ; } } if ( failures . isEmpty ( ) ) { return ( Result ) firstResult . createSuccess ( items ) ; } else { final BaseFailingOrSucceedingResult < Item , FailureType > failure = firstResult . createFailure ( failures . stream ( ) . reduce ( null , nullSafe ( failureCollector ) ) ) ; return ( Result ) failure ; } }
Function to aggregate a {@link List} of {@link BaseFailingOrSucceedingResult}.
Function to aggregate a { @link List } of { @link BaseFailingOrSucceedingResult } .