package kernel.function; import kernel.Cell; import kernel.Formula; import kernel.Grid; import kernel.LanguageEnum; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.ArrayList; import java.util.Iterator; abstract public class Function extends Formula { protected Map names = new HashMap<>(); protected List listCells; public Function(List listCells) { this.listCells = listCells; } abstract public Double eval(); public String getDevelopedFormula() { return names.get(Grid.language) + "(" + this.listCells.stream() .map(Cell::getDevelopedFormula) .collect(Collectors.joining(",")) + ")"; } public String toString() { return names.get(Grid.language) + "(" + this.listCells.stream() .map(Cell::getId) .collect(Collectors.joining(",")) + ")"; } public Boolean createCycle(Cell cell) { boolean cycle=false; if (!this.listCells.contains(cell)){ Iterator it=listCells.iterator(); while (it.hasNext() &&!cycle){ if (it.next().containFormula()){ cycle=it.next().getFormula().createCycle(cell); } } return cycle; } else return true; } }