f7
f7 is a spreadsheet formula execution library
git clone https://git.vogt.world/f7.git
Log | Files | README.md | LICENSE.md
← All files
name: src/main/java/io/protobase/f7/formulas/statistical/COUNTA.java
-rw-r--r--
991
 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.Arrays;
 9import java.util.function.BiFunction;
10import java.util.function.Function;
11import java.util.stream.Collectors;
12
13public class COUNTA extends AbstractFormula {
14  public static FormulaName NAME = FormulaName.COUNTA;
15  public static COUNTA SELF = new COUNTA();
16
17  public COUNTA() {
18    super();
19  }
20
21  public COUNTA(Function<Object, Object> lookup, BiFunction<GridColumnRowKey, Object, Object> collateralLookup) {
22    super(lookup, collateralLookup);
23  }
24
25  @Override
26  public Object internal(GridColumnRowKey origin, Object... values) {
27    checkAtLeastLength(values.length, 1, NAME);
28    return ((double) Arrays.stream(values)
29        .map(lookup)
30        .flatMap(Mappers::toFlatStream)
31        .collect(Collectors.toList()).size());
32  }
33}