Example usage for java.util.function BinaryOperator BinaryOperator

List of usage examples for java.util.function BinaryOperator BinaryOperator

Introduction

In this page you can find the example usage for java.util.function BinaryOperator BinaryOperator.

Prototype

BinaryOperator

Source Link

Usage

From source file:org.briljantframework.data.Collectors.java

public static <T> Collector<T, ?, Vector> valueCounts() {
    return Collector.of(HashMap::new, (map, t) -> map.compute(t, (v, c) -> c == null ? 1 : c + 1),
            new BinaryOperator<HashMap<T, Integer>>() {
                @Override//from  w  w w  .j  ava 2 s  .  c om
                public HashMap<T, Integer> apply(HashMap<T, Integer> left, HashMap<T, Integer> right) {
                    right.forEach((k, v) -> left.merge(k, v, (Integer o, Integer n) -> o == null ? n : o + n));
                    return left;
                }
            }, (map) -> {
                Vector.Builder b = new TypeInferenceVectorBuilder();
                for (Map.Entry<T, Integer> e : map.entrySet()) {
                    b.set(e.getKey(), e.getValue());
                }
                return b.build();
            }, Collector.Characteristics.UNORDERED);
}