Blame view

src/kernel/function/Average.java 808 Bytes
2e8fbd04   Remi   global refactor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  package kernel.function;
  
  import kernel.Cell;
  
  import java.util.OptionalDouble;
  import java.util.stream.Collectors;
  
  public class Average extends Function {
  
      public String toString() {
          return "MOYENNE(" + this.listCells.stream()
                  .map(Cell::getId)
                  .collect(Collectors.joining(","))
                  + ")";
      }
  
      public String getDevelopedFormula() {
          return "MOYENNE(" + this.listCells.stream()
                  .map(Cell::getDevelopedFormula)
                  .collect(Collectors.joining(","))
                  + ")";
      }
  
      public Double eval() {
          OptionalDouble average = this.listCells.stream()
                  .mapToDouble(Cell::getValue)
                  .average();
  
          return average.isPresent() ? average.getAsDouble() : 0.;
      }
  }