examplecalculator.function.ActionFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of GradleProject.Calculate Show documentation
Show all versions of GradleProject.Calculate Show documentation
Project to ease pain of test automation
The newest version!
package examplecalculator.function;
import examplecalculator.ExampleException;
import java.util.List;
import java.util.function.BiFunction;
public final class ActionFunction {
private static final BiFunction ADDITIONAL = Double::sum;
private static final BiFunction SUBTRACTION = (x, y) -> x - y;
private static final BiFunction MULTIPLICATION = (x, y) -> x * y;
private static final BiFunction DIVISION = (x, y) -> x / y;
private static final BiFunction EXPONENTIATION = Math::pow;
public static final List ACTION_ORDER = List.of(EXPONENTIATION, DIVISION, MULTIPLICATION, SUBTRACTION, ADDITIONAL);
public static BiFunction getMathAction(final String sign) {
switch (sign) {
case "+":
return ADDITIONAL;
case "-":
return SUBTRACTION;
case "*":
return MULTIPLICATION;
case "/":
return DIVISION;
case "^":
return EXPONENTIATION;
default:
throw new ExampleException("Неизвестный знак дейстия");
}
}
}