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/math/MINUS.java
-rw-r--r--
1169
 1package io.protobase.f7.formulas.math;
 2
 3import io.protobase.f7.errors.F7Exception;
 4import io.protobase.f7.formulas.AbstractFormula;
 5import io.protobase.f7.formulas.FormulaName;
 6import io.protobase.f7.models.GridColumnRowKey;
 7import io.protobase.f7.utils.Converters;
 8
 9import java.util.function.BiFunction;
10import java.util.function.Function;
11
12public class MINUS extends AbstractFormula {
13  public static FormulaName NAME = FormulaName.MINUS;
14  public static MINUS SELF = new MINUS();
15
16  public MINUS() {
17    super();
18  }
19
20  public MINUS(Function<Object, Object> lookup, BiFunction<GridColumnRowKey, Object, Object> collateralLookup) {
21    super(lookup, collateralLookup);
22  }
23
24  @Override
25  public Object internal(GridColumnRowKey origin, Object... values) {
26    checkLength(values.length, 2, NAME);
27    Object first = Converters.first(collateralLookup.apply(origin, values[0]));
28    Object second = Converters.first(collateralLookup.apply(origin, values[1]));
29    if (first instanceof F7Exception) {
30      return first;
31    }
32    if (second instanceof F7Exception) {
33      return second;
34    }
35    return Converters.toDouble(first) - Converters.toDouble(second);
36  }
37}