Search in sources :

Example 26 with BinaryOperator

use of java.util.function.BinaryOperator 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)

Example 27 with BinaryOperator

use of java.util.function.BinaryOperator in project rest.li by linkedin.

the class SchemaToAvroJsonEncoder method produceFieldProperties.

@SuppressWarnings("unchecked")
static /* package private */
Map<String, ?> produceFieldProperties(RecordDataSchema.Field field, DataToAvroSchemaTranslationOptions options) {
    Stream<Map.Entry<String, Object>> toBeFiltered = field.getProperties().entrySet().stream();
    // and merge with record field's properties.
    if (field.getType().getType() == DataSchema.Type.TYPEREF) {
        toBeFiltered = Stream.concat(toBeFiltered, ((TyperefDataSchema) field.getType()).getMergedTyperefProperties().entrySet().stream()).filter(entry -> !options.getTyperefPropertiesExcludeSet().contains(entry.getKey()));
    }
    // Property merge rule:
    // For property content inherited from TypeRef that appears to be have same property name as the record field:
    // if the two property contents are Map type, they will be merged at this level,
    // otherwise Typeref field property content will be overridden by record field property's content.
    BinaryOperator<Object> propertyMergeLogic = (originalPropertyContent, inheritedPropertyContent) -> {
        if (originalPropertyContent instanceof Map && inheritedPropertyContent instanceof Map) {
            Map<String, Object> mergedMap = new DataMap((Map<String, Object>) originalPropertyContent);
            ((Map<String, Object>) inheritedPropertyContent).forEach(mergedMap::putIfAbsent);
            return mergedMap;
        } else {
            return originalPropertyContent;
        }
    };
    return toBeFiltered.filter(entry -> !RESERVED_DATA_PROPERTIES.contains(entry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, propertyMergeLogic));
}
Also used : Arrays(java.util.Arrays) DataSchema(com.linkedin.data.schema.DataSchema) JsonBuilder(com.linkedin.data.schema.JsonBuilder) ArrayList(java.util.ArrayList) Formatter(java.util.Formatter) Data(com.linkedin.data.Data) HashSet(java.util.HashSet) DataMap(com.linkedin.data.DataMap) Named(com.linkedin.data.schema.Named) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) Map(java.util.Map) AVRO_PREFIX(com.linkedin.data.avro.SchemaTranslator.AVRO_PREFIX) SchemaToJsonEncoder(com.linkedin.data.schema.SchemaToJsonEncoder) Set(java.util.Set) TYPE_KEY(com.linkedin.data.schema.DataSchemaConstants.TYPE_KEY) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) List(java.util.List) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) Stream(java.util.stream.Stream) DEFAULT_KEY(com.linkedin.data.schema.DataSchemaConstants.DEFAULT_KEY) DataSchemaConstants(com.linkedin.data.schema.DataSchemaConstants) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) DataMap(com.linkedin.data.DataMap) Map(java.util.Map) DataMap(com.linkedin.data.DataMap)

Example 28 with BinaryOperator

use of java.util.function.BinaryOperator in project JDK8 by ABHSY.

the class MethodReference method test3.

public void test3() {
    String name = getName();
    Runnable runnable = () -> System.out.print(name);
    ActionListener actionListener = event -> System.out.print(1);
    Runnable runnable1 = () -> {
        System.out.print(1);
    };
    BinaryOperator<Integer> binaryOperator = (x, y) -> x + y;
    BinaryOperator<Long> binaryOperator1 = (Long x, Long y) -> x + y;
}
Also used : Consumer(java.util.function.Consumer) Arrays(java.util.Arrays) List(java.util.List) ActionListener(java.awt.event.ActionListener) Test(org.junit.Test) Comparator(java.util.Comparator) Supplier(java.util.function.Supplier) BinaryOperator(java.util.function.BinaryOperator) ActionListener(java.awt.event.ActionListener)

Example 29 with BinaryOperator

use of java.util.function.BinaryOperator in project Field2 by OpenEndedGroup.

the class BoxChildHelper method asMap_get.

@Override
public Object asMap_get(String p) {
    if (p.equals("all")) {
        return new All();
    }
    if (p.equals("first")) {
        if (c.size() == 0)
            return null;
        return c.get(0);
    }
    if (t.containsKey(p))
        return t.get(p);
    Stream<Object> o = c.stream().map(x -> x.asMap_get(p)).filter(x -> x != null);
    Optional val = null;
    Dict.Prop c = new Dict.Prop(p).findCanon();
    if (c != null) {
        BinaryOperator sr = c.getAttributes().get(Dict.streamReducer);
        if (sr != null)
            val = o.reduce(sr);
        else {
            Function<Collection, Optional<Object>> cr = c.getAttributes().get(Dict.collectionReducer);
            if (cr != null) {
                List<Object> q = o.collect(Collectors.toList());
                if (q.size() > 0)
                    val = cr.apply(q);
            }
        }
    }
    if (val != null && val.isPresent())
        return val.get();
    List<Object> q = o.collect(Collectors.toList());
    if (q.size() == 0)
        return null;
    if (q.size() == 1)
        return q.get(0);
    return new ListProxy(q);
}
Also used : HandlesCompletion(fieldbox.execution.HandlesCompletion) Linker(fieldlinker.Linker) java.util(java.util) Predicate(java.util.function.Predicate) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) SafeToToString(fieldnashorn.annotations.SafeToToString) Consumer(java.util.function.Consumer) Stream(java.util.stream.Stream) Dict(field.utility.Dict) ObjectToHTML(fielded.boxbrowser.ObjectToHTML) Completion(fieldbox.execution.Completion) Dict(field.utility.Dict) BinaryOperator(java.util.function.BinaryOperator)

Example 30 with BinaryOperator

use of java.util.function.BinaryOperator in project gaffer-doc by gchq.

the class PropertiesWalkthrough method listAggregators.

protected boolean listAggregators(final Class<?> clazz) {
    final List<String> aggregateClasses = new ArrayList<>();
    for (final BinaryOperator function : AGGREGATE_FUNCTIONS) {
        final Signature signature = Signature.getInputSignature(function);
        if (signature.assignable(clazz).isValid()) {
            aggregateClasses.add(WalkthroughStrSubstitutor.getJavaDocLink(function.getClass(), false, 3));
        }
    }
    if (!aggregateClasses.isEmpty()) {
        print(AGGREGATORS_KEY, "\nAggregators:");
        print(AGGREGATORS_KEY, "\n- " + StringUtils.join(aggregateClasses, "\n- "));
    }
    return !aggregateClasses.isEmpty();
}
Also used : Signature(uk.gov.gchq.koryphe.signature.Signature) ArrayList(java.util.ArrayList) AdaptedBinaryOperator(uk.gov.gchq.koryphe.binaryoperator.AdaptedBinaryOperator) TupleAdaptedBinaryOperator(uk.gov.gchq.koryphe.tuple.binaryoperator.TupleAdaptedBinaryOperator) BinaryOperator(java.util.function.BinaryOperator)

Aggregations

BinaryOperator (java.util.function.BinaryOperator)38 List (java.util.List)20 ArrayList (java.util.ArrayList)12 Arrays (java.util.Arrays)12 Function (java.util.function.Function)10 Test (org.junit.jupiter.api.Test)10 Collections (java.util.Collections)8 Optional (java.util.Optional)8 Collectors (java.util.stream.Collectors)8 Stream (java.util.stream.Stream)8 BiFunction (java.util.function.BiFunction)7 Map (java.util.Map)6 Collector (java.util.stream.Collector)6 CommonUtils.checkArgument (com.amazon.randomcutforest.CommonUtils.checkArgument)4 CommonUtils.checkNotNull (com.amazon.randomcutforest.CommonUtils.checkNotNull)4 CommonUtils.toDoubleArray (com.amazon.randomcutforest.CommonUtils.toDoubleArray)4 CommonUtils.toFloatArray (com.amazon.randomcutforest.CommonUtils.toFloatArray)4 AnomalyAttributionVisitor (com.amazon.randomcutforest.anomalydetection.AnomalyAttributionVisitor)4 AnomalyScoreVisitor (com.amazon.randomcutforest.anomalydetection.AnomalyScoreVisitor)4 DynamicAttributionVisitor (com.amazon.randomcutforest.anomalydetection.DynamicAttributionVisitor)4