2.17.2: 2011-06-17

net.sf.basedb.util.jep
Class Log2Function

java.lang.Object
  extended by 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:
Jep
Last modified
$Date: 2009-04-06 14:52:39 +0200 (Mon, 06 Apr 2009) $

Field Summary
private static double LOG2
          The natural logarithm of 2.
private static Log2Function theInstance
          The one and only instance of this function.
 
Constructor Summary
private Log2Function()
          Create a new instance of this function.
 
Method Summary
 boolean checkNumberOfParameters(int n)
           
 String getFunctionName()
          Get the name of this function.
static Log2Function getInstance()
          Get the singleton instance of this function.
 int getNumberOfParameters()
           
 double log2(Number argument)
          Calculate the 2-based logarithm of the argument.
 void run(Stack stack)
           
 void setCurNumberOfParameters(int n)
           
 Expression toExpression(Node node)
          Use the Expressions.log2(Expression) method to create an expression taking the 2-based logarithm of the argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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 Detail

Log2Function

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

Method Detail

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:
JEP.addFunction(String, PostfixMathCommandI)

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.

2.17.2: 2011-06-17