org.pentaho.reporting.engine.classic.core.filter
Class DecimalFormatFilter

java.lang.Object
  extended by org.pentaho.reporting.engine.classic.core.filter.FormatFilter
      extended by org.pentaho.reporting.engine.classic.core.filter.NumberFormatFilter
          extended by org.pentaho.reporting.engine.classic.core.filter.DecimalFormatFilter
All Implemented Interfaces:
Serializable, Cloneable, DataFilter, DataSource, DataTarget, RawDataSource

public class DecimalFormatFilter
extends NumberFormatFilter

A filter that formats the numeric value from a data source to a string representation using the decimal number system as base.

This filter will format java.lang.Number objects using a java.text.DecimalFormat to create the string representation for the date obtained from the datasource.

If the object read from the datasource is no date, the NullValue defined by setNullValue(Object) is returned.

Author:
Thomas Morgner
See Also:
NumberFormat, Number, Serialized Form

Constructor Summary
DecimalFormatFilter()
          DefaultConstructor, this object is initialized using a DecimalFormat with the default pattern for this locale.
 
Method Summary
 DecimalFormat getDecimalFormat()
          Returns the format for the filter.
 String getFormatString()
          Synthesizes a pattern string that represents the current state of this Format object.
 FormatSpecification getFormatString(ExpressionRuntime runtime, Element element, FormatSpecification formatSpecification)
          Returns information about the formatstring that was used to transform a raw-value into a formatted text.
 String getLocalizedFormatString()
          Synthesizes a localized pattern string that represents the current state of this Format object.
 Object getValue(ExpressionRuntime runtime, Element element)
          Returns the formatted string.
 boolean isKeepState()
          Defines, whether the filter should keep its state, if a locale change is detected.
 void setDecimalFormat(DecimalFormat format)
          Sets the format for the filter.
 void setFormatString(String format)
          Applies a format string to the internal DecimalFormat instance.
 void setFormatter(Format format)
          Sets the format for the filter.
 void setKeepState(boolean keepState)
          Defines, whether the filter should keep its state, if a locale change is detected.
 void setLocalizedFormatString(String format)
          Applies a localised format string to the internal DecimalFormat instance.
 
Methods inherited from class org.pentaho.reporting.engine.classic.core.filter.NumberFormatFilter
getMaximumFractionDigits, getMaximumIntegerDigits, getMinimumFractionDigits, getMinimumIntegerDigits, getNumberFormat, isGroupingUsed, setGroupingUsed, setMaximumFractionDigits, setMaximumIntegerDigits, setMinimumFractionDigits, setMinimumIntegerDigits, setNumberFormat
 
Methods inherited from class org.pentaho.reporting.engine.classic.core.filter.FormatFilter
clone, getDataSource, getFormatter, getNullValue, getRawValue, setDataSource, setNullValue
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DecimalFormatFilter

public DecimalFormatFilter()
DefaultConstructor, this object is initialized using a DecimalFormat with the default pattern for this locale.

Method Detail

getDecimalFormat

public DecimalFormat getDecimalFormat()
Returns the format for the filter. The DecimalFormatParser has only DecimalFormat objects assigned.

Returns:
the formatter.
Throws:
NullPointerException - if the given format is null

setDecimalFormat

public void setDecimalFormat(DecimalFormat format)
Sets the format for the filter.

Parameters:
format - the format.
Throws:
NullPointerException - if the given format is null

setFormatter

public void setFormatter(Format format)
Sets the format for the filter. If the given format is no Decimal format, a ClassCastException is thrown

Overrides:
setFormatter in class NumberFormatFilter
Parameters:
format - the format.
Throws:
NullPointerException - if the given format is null
ClassCastException - if the format is no decimal format

getFormatString

public String getFormatString()
Synthesizes a pattern string that represents the current state of this Format object.

Returns:
the pattern string of the format object contained in this filter.

setFormatString

public void setFormatString(String format)
Applies a format string to the internal DecimalFormat instance.

Parameters:
format - the format string.

getLocalizedFormatString

public String getLocalizedFormatString()
Synthesizes a localized pattern string that represents the current state of this Format object.

Returns:
the localized pattern string of the format-object.

setLocalizedFormatString

public void setLocalizedFormatString(String format)
Applies a localised format string to the internal DecimalFormat instance.

Parameters:
format - the format string.

isKeepState

public boolean isKeepState()
Defines, whether the filter should keep its state, if a locale change is detected. This will effectivly disable the locale update.

Returns:
true, if the locale should not update the DateSymbols, false otherwise.

setKeepState

public void setKeepState(boolean keepState)
Defines, whether the filter should keep its state, if a locale change is detected. This will effectivly disable the locale update.

Parameters:
keepState - set to true, if the locale should not update the DateSymbols, false otherwise.

getValue

public Object getValue(ExpressionRuntime runtime,
                       Element element)
Returns the formatted string. The value is read using the data source given and formated using the formatter of this object. The formating is guaranteed to completly form the object to an string or to return the defined NullValue.

If format, datasource or object are null, the NullValue is returned.

Specified by:
getValue in interface DataSource
Overrides:
getValue in class FormatFilter
Parameters:
runtime - the expression runtime that is used to evaluate formulas and expressions when computing the value of this filter.
element -
Returns:
The formatted value.

getFormatString

public FormatSpecification getFormatString(ExpressionRuntime runtime,
                                           Element element,
                                           FormatSpecification formatSpecification)
Description copied from interface: RawDataSource
Returns information about the formatstring that was used to transform a raw-value into a formatted text. Not all elements will make use of a format-string. These elements will return FormatSpecification.TYPE_UNDEFINED in that case.

Specified by:
getFormatString in interface RawDataSource
Overrides:
getFormatString in class NumberFormatFilter
Parameters:
runtime - the Expression runtime used to possibly compute the raw-value.
element - the element to which this datasource is added.
formatSpecification - the format specification (can be null). @return a filled format specififcation. If the formatSpecification parameter was not null, this given instance is reused.