Average.java 542 Bytes
package kernel.function;

import kernel.Cell;
import kernel.LanguageEnum;

import java.util.List;
import java.util.OptionalDouble;

public class Average extends Function {
	
	public Average(List<Cell> listCells) {
		super(listCells);
		this.getNames().put(LanguageEnum.FR, "MOYENNE");
		this.getNames().put(LanguageEnum.EN, "AVERAGE");
	}
	
	@Override
	public double eval() {
		OptionalDouble average = this.getUtilisedCells().stream().mapToDouble(Cell::getValue).average();
		
		return average.isPresent() ? average.getAsDouble() : 0.;
	}
}