Sum.java 712 Bytes
package kernel.function;

import kernel.Cell;
import kernel.function.Function;

import java.util.stream.Collectors;

public class Sum extends Function {

    public String toString() {
        return "SOMME(" + this.listCells.stream()
                .map(Cell::getId)
                .collect(Collectors.joining(","))
                + ")";
    }

    public String getDevelopedFormula() {
        return "SOMME(" + this.listCells.stream()
                .map(Cell::getDevelopedFormula)
                .collect(Collectors.joining(","))
                + ")";
    }

    public Double eval() {
        return this.listCells.stream()
                .mapToDouble(Cell::getValue)
                .sum();
    }
}