Blame view

src/kernel/function/Average.java 512 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
  
  public class Average extends Function {
4186cd92   Remi   fix tests
10
11
12
13
14
15
16
17
18
19
20
21
  	
  	public Average(List<Cell> listCells) {
  		super(listCells);
  		this.names.put(LanguageEnum.FR, "MOYENNE");
  		this.names.put(LanguageEnum.EN, "AVERAGE");
  	}
  	
  	public double eval() {
  		OptionalDouble average = this.listCells.stream().mapToDouble(Cell::getValue).average();
  		
  		return average.isPresent() ? average.getAsDouble() : 0.;
  	}
2e8fbd04   Remi   global refactor
22
  }