Average.java 638 Bytes
package kernel.function;

import kernel.Cell;
import kernel.LanguageEnum;

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

public class Average extends Function {

    private static final long serialVersionUID = 1L;

    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.;
    }
}