Class Log2Function

java.lang.Object
net.sf.basedb.util.jep.Log2Function
All Implemented Interfaces:
JepExpressionFunction, JepFunction, org.nfunk.jep.function.PostfixMathCommandI

public class Log2Function extends Object implements JepExpressionFunction
A JEP function class that adds a log2(expression) function to a JEP expression parser. The function will look take the 2-based logarithm of it's argument.

This function is added automatically by the Jep.newJep(String, JepFunction[]) method to the parser.

Version:
2.0
Author:
Nicklas
See Also:
Last modified
$Date: 2015-04-20 11:08:18 +0200 (må, 20 apr 2015) $
  • Field Details

    • theInstance

      private static final Log2Function theInstance
      The one and only instance of this function.
    • LOG2

      private static final double LOG2
      The natural logarithm of 2. This is used when calculating the 2-based logarithm of a value since it can be calculated as: ln(x) / ln(2)
  • Constructor Details

    • Log2Function

      private Log2Function()
      Create a new instance of this function.
  • Method Details

    • getInstance

      public static Log2Function getInstance()
      Get the singleton instance of this function.
      Returns:
      The Log2Function object
    • getFunctionName

      public String getFunctionName()
      Description copied from interface: JepFunction
      Get the name of this function. It is used when registering the function with a JEP parser.
      Specified by:
      getFunctionName in interface JepFunction
      Returns:
      The string "log2"
      See Also:
    • toExpression

      public Expression toExpression(Node node)
      Use the Expressions.log2(Expression) method to create an expression taking the 2-based logarithm of the argument.
      Specified by:
      toExpression in interface JepExpressionFunction
      Parameters:
      node - The node representing this function
      Returns:
      An Expression object
    • getNumberOfParameters

      public int getNumberOfParameters()
      Specified by:
      getNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI
      Returns:
      Always 1
    • setCurNumberOfParameters

      public void setCurNumberOfParameters(int n)
      Specified by:
      setCurNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI
    • checkNumberOfParameters

      public boolean checkNumberOfParameters(int n)
      Specified by:
      checkNumberOfParameters in interface org.nfunk.jep.function.PostfixMathCommandI
    • run

      public void run(Stack stack) throws ParseException
      Specified by:
      run in interface org.nfunk.jep.function.PostfixMathCommandI
      Throws:
      ParseException
    • log2

      public double log2(Number argument) throws ParseException
      Calculate the 2-based logarithm of the argument.
      Parameters:
      argument - A number to calculate on
      Returns:
      a double object
      Throws:
      ParseException - If the logarithm could not be calculated.