net.lessy.util.format
Class FormatUtil

java.lang.Object
  extended by net.lessy.util.format.FormatUtil

public class FormatUtil
extends Object

Helper class around custom formatting of a value. Basic formatters for float, currency and date are pre-registered. Custom formatters can be registered as additionally or the default formatters can be overwritten.

Author:
hl

Field Summary
static String CURRENCY
          Constant for the currency-formatter
static String DATE
          Constant for the date-formatter
static String FLOAT
          Constant for the float-formatter
static String TIME
          Constant for the time-formatter
 
Constructor Summary
FormatUtil()
           
 
Method Summary
static void addFormatter(String pName, FormatIF pFormatter)
          Registers a new formatter.
static String format(Object pValue, String pFormat, Object pDefault, Locale pLocale, Properties pProps)
          Wrapper method for formatting a value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLOAT

public static final String FLOAT
Constant for the float-formatter

See Also:
Constant Field Values

CURRENCY

public static final String CURRENCY
Constant for the currency-formatter

See Also:
Constant Field Values

DATE

public static final String DATE
Constant for the date-formatter

See Also:
Constant Field Values

TIME

public static final String TIME
Constant for the time-formatter

See Also:
Constant Field Values
Constructor Detail

FormatUtil

public FormatUtil()
Method Detail

format

public static String format(Object pValue,
                            String pFormat,
                            Object pDefault,
                            Locale pLocale,
                            Properties pProps)
Wrapper method for formatting a value.

Parameters:
pValue - Value to be formatted
pFormat - Name of the formatter to be used to format the value
pDefault - If the passed value is null, then this is used as the value to format
pLocale - Locale to be passed to the formatter
pProps - Properties to be passed to the formatter (properties implementation dependant)
Returns:
The formatted value or null if the value could not be formatted

addFormatter

public static void addFormatter(String pName,
                                FormatIF pFormatter)
Registers a new formatter.

Parameters:
pName - Name of the formatter. With this name, the formatter is retrieved on use. If a formatter was already registered with this name, then it will be overwritten.
pFormatter - Instance of the formatter


Copyright © 2012. All Rights Reserved.