name:
src/main/java/io/protobase/f7/formulas/statistical/COUNTBLANK.java
-rw-r--r--
1133
1package io.protobase.f7.formulas.statistical;
2
3import io.protobase.f7.formulas.AbstractFormula;
4import io.protobase.f7.formulas.FormulaName;
5import io.protobase.f7.models.GridColumnRowKey;
6import io.protobase.f7.utils.Mappers;
7
8import java.util.Objects;
9import java.util.function.BiFunction;
10import java.util.function.Function;
11import java.util.stream.Collectors;
12import java.util.stream.Stream;
13
14/**
15 * The count of number values in a set of data.
16 */
17public class COUNTBLANK extends AbstractFormula {
18 public static FormulaName NAME = FormulaName.COUNTBLANK;
19 public static COUNTBLANK SELF = new COUNTBLANK();
20
21 public COUNTBLANK() {
22 super();
23 }
24
25 public COUNTBLANK(Function<Object, Object> lookup, BiFunction<GridColumnRowKey, Object, Object> collateralLookup) {
26 super(lookup, collateralLookup);
27 }
28
29 @Override
30 public Object internal(GridColumnRowKey origin, Object... values) {
31 checkAtLeastLength(values.length, 1, NAME);
32 return ((double) Stream.of(values)
33 .map(lookup)
34 .flatMap(Mappers::toFlatStream)
35 .filter(Objects::isNull)
36 .collect(Collectors.toList()).size());
37 }
38}