All Downloads are FREE. Search and download functionalities are using the official Maven repository.

examplecalculator.function.ActionFunction Maven / Gradle / Ivy

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("Неизвестный знак дейстия");

        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy