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

com.mpobjects.bdparsii.eval.UnaryFunction Maven / Gradle / Ivy

Go to download

bdparsii is a super fast and lightweight parser and expression evaluator. It is the BigDecimal brother of parsii.

The newest version!
/*
 * Made with all the love in the world
 * by scireum in Remshalden, Germany
 *
 * Copyright by scireum GmbH
 * http://www.scireum.de - [email protected]
 */

package com.mpobjects.bdparsii.eval;

import java.math.BigDecimal;
import java.math.MathContext;
import java.util.List;

/**
 * Represents an unary function.
 * 

* An unary function has one arguments which is always evaluated in order to compute the final result. */ public abstract class UnaryFunction implements Function { @Override public int getNumberOfArguments() { return 1; } @Override public BigDecimal eval(List args, MathContext mathContext) { BigDecimal a = args.get(0).evaluate(mathContext); if (a == null) { throw new ArithmeticException("Parameter evaluated to null"); } return eval(a, mathContext); } /** * Performs the computation of the unary function * * @param a the argument of the function * @param mathContext the math context * @return the result of calling the function with a as argument */ protected abstract BigDecimal eval(BigDecimal a, MathContext mathContext); @Override public boolean isNaturalFunction() { return true; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy