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;
}
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));
}
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;
}
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);
}
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();
}
Aggregations