Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
org.pentaho.reporting.libraries.formula.function.Function
org.pentaho.reporting.libraries.formula.function.FunctionDescription

Before you look at those, it's best to look at the below example first.

A very simple custom formula

Follow these directions to create a simple function:

...

To see a simple example that uses these classes, open up the LibFormula source in your IDE

...

and go to the org.pentaho.reporting.libraries.formula.function.math package

...

. Then open up the classes AbsFunction and AbsFunctionDescription, and the file Abs-Function.properties.

File Descriptions:
AbsFunction - This class performs the work. It evaluates the incoming parameters, and returns the result.
AbsFunctionDescription - This class describes the function to the outside world. It is the mechanism that allows user interfaces to recognize, categorize, and display your function in the correct place.
Abs-Function.properties - This file provides the name and description for your function as well as all the arguments to your function.

...

Code Block
org.pentaho.reporting.libraries.formula.functions.math.GreatestCommonDenom.class=com.acme.libformula.GreatestCommonDenomFunction
org.pentaho.reporting.libraries.formula.functions.math.GreatestCommonDenom.description=com.acme.libformula.GreatestCommonDenomFunctionDescription

Sample Code

Attached here is a sample java Java project that implements a simple LibFormula function called sleep (SLEEP). The SLEEP function takes a numeric parameter, and calls the Thread.sleep method which causes the current thread to cease execution for the specified number of milliseconds.

...

Summary

The Pentaho LibFormula library was designed from the very beginning to allow extensions in many different ways - ; adding your own formula is only one of many possible extension points. We hope that the extensibility of LibFormula encourages community contributions like financial libraries, algebraic expressions, and the likeother useful operations.