Search in sources :

Example 1 with AdaptedBinaryOperator

use of uk.gov.gchq.koryphe.binaryoperator.AdaptedBinaryOperator in project Gaffer by gchq.

the class AggregateValidator method validateElementAggregator.

private ValidationResult validateElementAggregator(final Map.Entry<String, ?> entry, final Schema schema) {
    final ValidationResult result = new ValidationResult();
    List<TupleAdaptedBinaryOperator<String, ?>> aggregateFunctions = new ArrayList<>();
    final SchemaElementDefinition schemaElement = schema.getElement(entry.getKey());
    if (null != schemaElement) {
        aggregateFunctions = schemaElement.getOriginalAggregateFunctions();
    }
    List<BinaryOperator<?>> schemaOperators = new ArrayList<>();
    if (null != aggregateFunctions) {
        schemaOperators = Streams.toStream(aggregateFunctions).map(AdaptedBinaryOperator::getBinaryOperator).collect(Collectors.toList());
    }
    if (schemaOperators.contains(null)) {
        result.addError("Schema contains an ElementAggregator with a null function.");
    }
    final AggregatePair pair = (AggregatePair) entry.getValue();
    final ElementAggregator aggregator = pair.getElementAggregator();
    if (null != aggregator && null != aggregator.getComponents()) {
        for (final TupleAdaptedBinaryOperator<String, ?> adaptedFunction : aggregator.getComponents()) {
            if (null == adaptedFunction.getBinaryOperator()) {
                result.addError(aggregator.getClass().getSimpleName() + " contains a null function.");
            }
        }
    }
    return result;
}
Also used : TupleAdaptedBinaryOperator(uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator) AdaptedBinaryOperator(uk.gov.gchq.koryphe.binaryoperator.AdaptedBinaryOperator) ArrayList(java.util.ArrayList) TupleAdaptedBinaryOperator(uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator) AggregatePair(uk.gov.gchq.gaffer.operation.util.AggregatePair) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) TupleAdaptedBinaryOperator(uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator) BinaryOperator(java.util.function.BinaryOperator) AdaptedBinaryOperator(uk.gov.gchq.koryphe.binaryoperator.AdaptedBinaryOperator) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator)

Aggregations

ArrayList (java.util.ArrayList)1 BinaryOperator (java.util.function.BinaryOperator)1 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)1 AggregatePair (uk.gov.gchq.gaffer.operation.util.AggregatePair)1 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)1 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)1 AdaptedBinaryOperator (uk.gov.gchq.koryphe.binaryoperator.AdaptedBinaryOperator)1 TupleAdaptedBinaryOperator (uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator)1