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

io.burt.jmespath.function.MathFunction Maven / Gradle / Ivy

There is a newer version: 0.6.0
Show newest version
package io.burt.jmespath.function;

import java.util.List;

import io.burt.jmespath.Adapter;
import io.burt.jmespath.JmesPathType;

/**
 * Helper base class for functions that perform operations on a single numerical
 * argument, like calculating the absolute value, rounding, etc.
 */
public abstract class MathFunction extends BaseFunction {
  public MathFunction() {
    super(ArgumentConstraints.typeOf(JmesPathType.NUMBER));
  }

  @Override
  protected  T callFunction(Adapter runtime, List> arguments) {
    T value = arguments.get(0).value();
    double n = runtime.toNumber(value).doubleValue();
    return runtime.createNumber(performMathOperation(n));
  }

  /**
   * Subclasses implement this method.
   */
  protected abstract double performMathOperation(double n);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy