Skip to content

Latest commit

 

History

History
19 lines (18 loc) · 713 Bytes

File metadata and controls

19 lines (18 loc) · 713 Bytes
class x{
    private String solveFunctions(String equation) {
        for (String functionName : this.functions.keySet()) {
            String bracketsPattern = "()";
            Pattern pattern = Pattern.compile(Pattern.quote(functionName) + "\\(" + bracketsPattern + "\\)");
            Matcher matcher = pattern.matcher(equation);
            equation = matcher.replaceAll((MatchResult matchResult) -> {
                String content = matchResult.group(1);
                double value = this.solve(content);
                double result = this.functions.get(functionName).apply(value);
                return Double.toString(result);
            });
        }

        return equation;
    }
}