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

cdm.base.math.functions.ArithmeticOpImpl Maven / Gradle / Ivy

There is a newer version: 6.0.0-dev.89
Show newest version
package cdm.base.math.functions;

import cdm.base.math.ArithmeticOperationEnum;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.function.BiFunction;

public class ArithmeticOpImpl {

    static BiFunction operation(ArithmeticOperationEnum arithmeticOp) {
        switch (arithmeticOp) {
            case ADD:
                return BigDecimal::add;
            case SUBTRACT:
                return BigDecimal::subtract;
            case MULTIPLY:
                return BigDecimal::multiply;
            case DIVIDE:
                return (b1, b2) -> b1.divide(b2, 10, RoundingMode.HALF_EVEN);
            case MAX:
                return BigDecimal::max;
            case MIN:
                return BigDecimal::min;
            default:
                throw new IllegalArgumentException(String.format("Unknown ArithmeticOp %s", arithmeticOp));
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy