org.jfree.report.function |
The function package contains statefull functions and stateless expression for
JFreeReport.
The following lines apply to both functions and expressions.
JFreeReport supports 2 kinds of userdefined calculations: Functions are statefull
calculations, when the report proceedes they change their state, they sum up, calculate
averages, count etc. Statefull means in that case, given you feed the same event
multiple times into the function,you are not guaranteed to get the same result.
Expressions in contrast do not maintain a state, they calculate a value or change
the report-elements depending on the current Event feed to them. If you feed the
same Event into the Expression multiple times, you will always get the same result.
Common to both variants is: Data is fed into the function/expression by using a
DataRow object. This object provides the (among others) these methods
Object get(String name);
Object get(int columnName);
to read the values of a function, expression, a column from the tablemodel or a
ReportProperty.
Expressions are simple and easily explained: Expression have the method
Object getValue() which is called when the expression is queried.
All expression have to override this method to perform the calculation and to return
the value.
Functions are more complex:
Functions have several notification methods, where the system informs the function
that a new event is processed.
public void pageStarted (ReportEvent event);
public void reportStarted (ReportEvent event);
public void groupStarted (ReportEvent event);
public void itemsStarted (ReportEvent event);
public void itemsAdvanced (ReportEvent event);
public void itemsFinished (ReportEvent event);
public void groupFinished (ReportEvent event);
public void reportFinished (ReportEvent event);
public void pageFinished (ReportEvent event);
By using the Event-object, you have access to the ReportState. The state can be
used for getting the current group, current item and for gaining access to the
dataRow. In case you want to manipulate the ReportElements, you also have access
to the JFreeReport object.
Functions live in an own environment, separated from the outside world. Changing
the original JFreeReport object does not affect the inner JFreeReport-Object. You
are also unable to add new Functions or expressions to the report from inside, so
all functions and expression have to be set before the report processing has begun.
All Functions have to be cloneable. It is not guaranteed that the report is processed
in an linear order, but it is guaranteed that a single instance of a function does
pass a reportstate only once.
That means: When processing the report, the system clones the functions on certain
save-points (for instance whenever a page is finished). This saved copy can later
be used to restart the report processing on that saved point. The copy-state made
will never return to a previous save point, but it can (and certainly will occur)
that this copy is used to process the report from that saved point on.
So when saving a state after page 2, it will never happen, that this page-2-copy gets
used to process page 2 a second time, but it could happen that copies of this
page-2-state process the page 3 again and again.
The best way to avoid cloning problems is to use Unmodifiable objects or primitive
datatypes when storing a state. Using java.lang.String, one of the java.lang.Number
implementers or any other unmodifiable object type is always save. If you use complex
objects, lists or hashtables and you get weird results, try to implement a
deep-object-copy in the clone() method of the function for these objects.
Using the functions
The function implementation is loaded via its default constructor by the report
parser, all function implementations which should be used from within the
xml-definitions must define a public default constructor.
The functions implementation is defined by specifiying the "class" attribute of the
"function" tag and is loaded by using the default class loader. Your function
implementation must be in the classloaders classpath.
As with every function, a single function can return one value, something
mathematicans express like y = f(x) where x is the data from your report processing.
A function is called several times, for every state change (whenever the report
advances) one of the ReportListener methods are called (reportStarted, groupStarted
etc). Expressions do not receive events, they just perform their computations based
on the current state.
The functions value is returned by the "getValue()" function. You can return any
Object, but make sure, that this object does not get modified anymore after it was
returned to the caller. (A simple way to obey to this rule is to create a new object
whenever the computed object changes).
Functions may reuse results from other functions by using and querying the DataRow
object supplied in the report state or the function.
The order of the functions and the order for receiving events is undefined for
functions of the same dependency level. So if you define a function which reads
values from an other function, it is wise to define the dependencies for these
functions.
Defining dependencies is easy: A function with an higher dependency is called
before any function with a lower dependency. By default all user functions have
the dependency of "0", the lowest possible level. The dependency is defined by
specifying the "deplevel" attribute of the function or expression tag.
When using the API, the dependency level is read by "getDependencyLevel()" and can
be set with "setDependencyLevel(int)".
For the example above, the caller function would have the dependency level of '0'
and the called function the level of '1' or higher.
|
Java Source File Name | Type | Comment |
AbstractCompareExpression.java | Class | The base class for all expressions that compare a value read from the datarow with another value. |
AbstractElementFormatFunction.java | Class | The AbstractElementFormatFunction provides a common base implementation for all functions that need to modify the
report definition or the style of an report element or band during the report processing. |
AbstractExpression.java | Class | An abstract base class for implementing new report expressions.
Expressions are stateless functions which have access to the report's
DataRow . |
AbstractFunction.java | Class | Base class for implementing new report functions. |
AverageExpression.java | Class | An expression that takes values from one or more fields and returns the average of
them. |
ColumnAggregationExpression.java | Class | The base-class for all expressions that aggregate values from multiple columns. |
ColumnAverageExpression.java | Class | Computes the horizontal average over all columns specified in the field-list. |
ColumnDifferenceExpression.java | Class | Computes the difference between the given column values. |
ColumnDivisionExpression.java | Class | Divides all values read from the field-list. |
ColumnMaximumExpression.java | Class | Computes the maximum of all data-row columns defined in the field-list. |
ColumnMinimumExpression.java | Class | Computes the minimum of all data-row columns defined in the field-list. |
ColumnMultiplyExpression.java | Class | Multiplies all values read from the field-list. |
ColumnSumExpression.java | Class | Adds all values read from the field-list. |
CompareFieldsExpression.java | Class | Compares the values of two fields. |
ConditionalItemSumFunction.java | Class | A item sum function that only sums up the current value, if the value read from the conditionField is the same as the
value from the conditionValue property. |
ConvertToDateExpression.java | Class | Parses a string into a date using the given date-format. |
ConvertToNumberExpression.java | Class | Parses a string into a number using the given decimal-format. |
CountDistinctFunction.java | Class | Counts the distinct occurences of an certain value of an column. |
CreateGroupAnchorsFunction.java | Class | Creates anchor objects for the current group. |
CreateHyperLinksFunction.java | Class | Adds hyperlinks to all elements with the name specified in 'element'. |
DateCutExpression.java | Class | Prunes a date in a calendar-unware way. |
ElementColorFunction.java | Class | A function that alternates between true and false for each item within a group. |
ElementTrafficLightFunction.java | Class | A function that performs basic traffic lighting based on a range of values and a given set of colors to use. |
ElementVisibilityFunction.java | Class | Triggers the visiblity of an element based on the boolean value read from the defined field. |
ElementVisibilitySwitchFunction.java | Class | A function that alternates between true and false for each item within a group. |
EventMonitorFunction.java | Class | A function that logs each event that it receives. |
Expression.java | Interface | An expression is a lightweight function that does not maintain a state. |
ExpressionCollection.java | Class | Collects all expressions used in the report. |
ExpressionRuntime.java | Interface | The expression runtime encapsulates all properties of the current report processing run that might be needed to
successfully evaluate an expression. |
ExpressionUtilities.java | Class | A collection of utility methods which may be useful for expression-implementors. |
FormulaExpression.java | Class | The formula expression is used to evaluate a LibFormula/OpenFormula expression. |
FormulaFunction.java | Class | The formula function is a stateful version of the FormulaExpression and is used to evaluate a LibFormula/OpenFormula
expression. |
Function.java | Interface | The interface for report functions. |
FunctionInitializeException.java | Class | An exception that indicates that a function has not been correctly initialised. |
FunctionProcessingException.java | Class | An exception that indicates that a function has not been correctly initialised. |
FunctionUtilities.java | Class | A collection of utility methods relating to functions. |
GroupCountFunction.java | Class | A report function that counts groups in a report. |
HideElementByNameFunction.java | Class | This function hides all elements with a given name, as long as the defined field does not contain
the element name. |
HideElementIfDataAvailableExpression.java | Class | This functions checks the tablemodel and shows the named band, if there
is no data available. |
HideNullValuesFunction.java | Class | Hides the specified elements if the given field contains empty strings or
zero numbers. |
HidePageBandForTableExportFunction.java | Class | Hides the page header and footer if the export type is not pageable. |
IsEmptyExpression.java | Class | Checks, whether a field is empty. |
IsNullExpression.java | Class | Checks, whether a field contains a NULL value. |
ItemAvgFunction.java | Class | A report function that calculates the average of one field (column) from the TableModel. |
ItemColumnQuotientExpression.java | Class | A report function that calculates the quotient of two fields (columns) from the current
row.
This function expects its input values to be java.lang.Number instances.
The function undestands two parameters. |
ItemCountFunction.java | Class | A report function that counts items in a report. |
ItemHideFunction.java | Class | The ItemHideFunction hides equal values in a group. |
ItemMaxFunction.java | Class | A report function that calculates the maximum value of one field (column) from the data-row.
The function can be used in two ways: - to calculate a maximum value for the entire report;
- to
calculate a maximum value within a particular group;
This function expects its input values to be either
java.lang.Number instances or Strings that can be parsed to java.lang.Number instances using a
java.text.DecimalFormat.
The function undestands two parameters, the field parameter is required and denotes the name of an
ItemBand-field which gets summed up.
The parameter group denotes the name of a group. |
ItemMinFunction.java | Class | A report function that calculates the minimum value of one field (column) from the
data-row. |
ItemPercentageFunction.java | Class | Calculates the percentage value of a numeric field. |
ItemSumFunction.java | Class | A report function that calculates the sum of one field (column) from the data-row. |
NegativeNumberPaintChangeFunction.java | Class | This function changes the color of the named elements according to the current value of a numeric field. |
OutputFunction.java | Interface | A simple tagging interface for the transition from function-based layouting back to explicit layouting. |
PageFunction.java | Class | A report function that counts pages. |
PageItemCountFunction.java | Class | An ItemCount function, that is reset to zero on every new page. |
PageItemSumFunction.java | Class | An ItemSum function, that is reset to zero on every new page. |
PageOfPagesFunction.java | Class | A report function that combines
PageFunction and
PageTotalFunction . |
PageTotalFunction.java | Class | Prints the total number of pages of an report. |
PaintComponentFunction.java | Class | Paints a AWT or Swing Component, fitting the component into the element bounds. |
PaintDynamicComponentFunction.java | Class | Paints a AWT or Swing Component. |
PercentageExpression.java | Class | Computes the percentage for a column in relation to a base column.
The function undestands two parameters. |
ProcessingContext.java | Interface | The processing context hold information about the progress of the report processing and contains global properties
used during the report processing. |
ReportFormulaContext.java | Class | The report formula context is a FormulaContext implementation that connects the formula evaluator with the current
data-row of the report process.
This is an internal class used by the FormulaExpression and FormulaFunction. |
RowBandingFunction.java | Class | A function that alternates the background-color for each item-band within a group. |
ShowElementByNameFunction.java | Class | This function hiddes the elements with the name specified in the 'element'
parameter, if the given field has one of the values specified in the
values array. |
ShowElementIfDataAvailableExpression.java | Class | This functions checks the tablemodel and hides the named elements, if there
is no data available. |
StructureFunction.java | Interface | A structure function is a annonymous function that modifes the structure of the report or computes changes to the
report definition on the current report.
Structure functions are considered to be part of the initial master-report. |
TextFormatExpression.java | Class | A TextFormatExpression uses a java.text.MessageFormat to concat and format one or more values evaluated from an
expression, function or report datasource.
The TextFormatExpression uses the pattern property to define the global format-pattern used when evaluating the
expression. |
TotalCalculationFunction.java | Class | A report function that stores the result of a calculation for a group or the complete report. |
TotalGroupCountFunction.java | Class | A report function that counts the total of groups in a report. |
TotalGroupSumFunction.java | Class | A report function that calculates the sum of one field (column) from the Data-Row. |
TotalGroupSumQuotientFunction.java | Class | A report function that calculates the quotient of two summed fields (columns) from the report's data row. |
TotalGroupSumQuotientPercentFunction.java | Class | A report function that calculates the quotient of two summed fields (columns) from the data-row. |
TotalItemCountFunction.java | Class | A report function that counts the total number of items contained in groups in a
report. |
TotalItemMaxFunction.java | Class | A report function that pre-computes the largest item in a group. |
TotalItemMinFunction.java | Class | A report function that pre-computes the smallest item in a group. |
TotalPageItemCountFunction.java | Class | A report function that counts the total number of items contained in groups in a
report. |
TriggerPageFooterFunction.java | Class | This function enables a "PageFooter only on last page" functionality. |