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/text/CONCATENATE.java
-rw-r--r--
1148
 1package io.protobase.f7.formulas.text;
 2
 3import io.protobase.f7.formulas.AbstractFormula;
 4import io.protobase.f7.formulas.FormulaName;
 5import io.protobase.f7.models.GridColumnRowKey;
 6import io.protobase.f7.utils.Converters;
 7import io.protobase.f7.utils.Mappers;
 8
 9import java.util.Arrays;
10import java.util.Objects;
11import java.util.function.BiFunction;
12import java.util.function.Function;
13
14public class CONCATENATE extends AbstractFormula {
15  public static FormulaName NAME = FormulaName.CONCATENATE;
16  public static CONCATENATE SELF = new CONCATENATE();
17
18  public CONCATENATE() {
19    super();
20  }
21
22  public CONCATENATE(Function<Object, Object> lookup, BiFunction<GridColumnRowKey, Object, Object> collateralLookup) {
23    super(lookup, collateralLookup);
24  }
25
26  @Override
27  public Object internal(GridColumnRowKey origin, Object... values) {
28    checkAtLeastLength(values.length, 1, NAME);
29    return Arrays.stream(values)
30        .map(lookup)
31        .flatMap(Mappers::toFlatStream)
32        .map(Mappers::throwIfException)
33        .filter(Objects::nonNull)
34        .map(Converters::toText)
35        .reduce(String::concat)
36        .orElse("");
37  }
38}