Blame view

src/kernel/function/Average.java 590 Bytes
2e8fbd04   Remi   global refactor
1
2
3
  package kernel.function;
  
  import kernel.Cell;
94ba86ff   Remi   Auto stash before...
4
  import kernel.LanguageEnum;
2e8fbd04   Remi   global refactor
5
  
94ba86ff   Remi   Auto stash before...
6
  import java.util.List;
2e8fbd04   Remi   global refactor
7
  import java.util.OptionalDouble;
2e8fbd04   Remi   global refactor
8
9
10
  
  public class Average extends Function {
  
94ba86ff   Remi   Auto stash before...
11
12
13
14
      public Average(List<Cell> listCells) {
          super(listCells);
          this.names.put(LanguageEnum.FR, "MOYENNE");
          this.names.put(LanguageEnum.EN, "AVERAGE");
2e8fbd04   Remi   global refactor
15
16
17
      }
  
      public Double eval() {
0c16a45a   [mandjemb]   test
18
      	
2e8fbd04   Remi   global refactor
19
20
21
22
23
24
25
          OptionalDouble average = this.listCells.stream()
                  .mapToDouble(Cell::getValue)
                  .average();
  
          return average.isPresent() ? average.getAsDouble() : 0.;
      }
  }