|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.text.Formats
public class Formats
Repository of Format objects to aid a
application in providing consistent text input/output.
The java.text package is very handy in creating
specialized parsing/formatting objects. Unfortunately, during
development, one often finds themselves repeatedly building and
constructing these format objects within their application. It can
become quite frustrating trying to maintain some consistency. This
class provides a mechanism to create and/or share common formats to
aid the application developer in maintaining consistency throughout
their application.
The easiest way to make use of this class is to use the
singleton available via the getInstance
method.
| Field Summary | |
|---|---|
static int |
NONE
A constant value which is different from the SHORT, MEDIUM, LONG, and FULL constants
defined in the DateFormat class. |
| Constructor Summary | |
|---|---|
Formats()
Fully constructions and intializes the object. |
|
| Method Summary | |
|---|---|
static DateFormat |
createDateFormat(Lookup l)
Creates a DateFormat object based upon values
in a Lookup object. |
static NumberFormat |
createDecimalFormat(int fdigits)
Create a standard NumberFormat which
displays real numbers with a fixed number of digits after the
decimal point. |
static NumberFormat |
createIntegerFormat()
Create a standard NumberFormat suitable for
integer values. |
static NumberFormat |
createNumberFormat(Lookup l)
Creates a NumberFormat object based upon
values in a Lookup object. |
static int |
getDateFormatConstant(String s)
Converts a string value into one of the standard DateFormat integer constants or NONE. |
static Formats |
getInstance()
Get the shared global instance of a Formats object. |
NumberFormat |
getInteger()
Get the NumberFormat to format suitable for
working with integers. |
DateFormat |
getToDay()
Get the DateFormat to format a date to day precision. |
DateFormat |
getToMilli()
Get the DateFormat to format a date to
millisecond precision. |
DateFormat |
getToMinute()
Get the DateFormat to format a date to minute
precision. |
DateFormat |
getToSecond()
Get the DateFormat to format a date to second
precision. |
(package private) void |
loadConfig(String name)
|
protected static void |
setInstance(Formats val)
Set the shared global instance of a Formats object. |
protected void |
setInteger(NumberFormat val)
Set the NumberFormat to be used for integer values. |
protected void |
setToDay(DateFormat val)
Set the DateFormat to format a date to day
precision. |
protected void |
setToMilli(DateFormat val)
Set the DateFormat to format a date to
millisecond precision. |
protected void |
setToMinute(DateFormat val)
Set the DateFormat to format a date to minute
precision. |
protected void |
setToSecond(DateFormat val)
Set the DateFormat to format a date to second
precision. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int NONE
SHORT, MEDIUM, LONG, and FULL constants
defined in the DateFormat class.
getDateFormatConstant(java.lang.String),
Constant Field Values| Constructor Detail |
|---|
public Formats()
This method fully constructs and initializes the object. It will honor any of the overrides found in the $HOME/.etc/com/ccg/text/default.Formats file - if found.
NOTE: This is a fairly expensive constructor - a configuration
file is loaded and many formats are created. It is recommended
that one hangs onto a common reference, or uses the getInstance method to share the "global"
settings.
| Method Detail |
|---|
public static int getDateFormatConstant(String s)
DateFormat integer constants or NONE.
This method attempts to translate a string value (case doesn't
matter) into one of the constants defined in the DateFormat class. Any of the following may be returned:
DateFormat.SHORTDateFormat.MEDIUMDateFormat.LONGDateFormat.FULLFormats.NONE
s - String to convert (you can pass null).
public static DateFormat createDateFormat(Lookup l)
throws IllegalArgumentException,
ParseException
DateFormat object based upon values
in a Lookup object.
This method looks for values to specific keys in the Lookup object passed to form a DateFormat object. At a minimum, at least one of the following
keys MUST have a value set: "date", "time", "template".
The following keys are supported:
SimpleDateFormat documentation for full
details on how to form the template string. If this value is set,
then the "date"/"time" keys are ignored.SHORT, MEDIUM, LONG, and FULL constants
defined in the DateFormat class. This setting is ignored
if the template=TEXT setting is present. If this setting
is omitted, or incorrectly set, then date information is omitted
from the output format.SHORT, MEDIUM, LONG, and FULL constants
defined in the DateFormat class. This setting is ignored
if the template=TEXT setting is present. If this setting
is omitted, or incorrectly set, then time information is omitted
from the output format.
props - Properties to get the information from (as described above)
IllegalArgumentException - If the properties passed were invalid (no template, date or time set).
ParseException - If a unrecoverable error was found trying to parse one of the values.public static NumberFormat createIntegerFormat()
NumberFormat suitable for
integer values.
NumberFormat
suitable for working with integer values.public static NumberFormat createDecimalFormat(int fdigits)
NumberFormat which
displays real numbers with a fixed number of digits after the
decimal point.
fdigits - Number of fractional digits to be displayed.
NumberFormat.
public static NumberFormat createNumberFormat(Lookup l)
throws IllegalArgumentException,
ParseException
NumberFormat object based upon
values in a Lookup object.
This method looks for values to specific keys in the Lookup object passed to form a NumberFormat object. At a minimum, at least one of the following
keys MUST have a value set: "type" or "template".
The following keys are supported:
DecimalFormat documentation for full
details on how to form the template string. If this value is set,
then all other values are ignored.NumberFormat instance which we start with (and the
optionally adjust with the other parameters you might
specify). The general (g) type results in a NumberFormat.getInstance() starting
point. The integer (i) type results in a NumberFormat.getInstance() starting
point except that it is set to parse only integers and not
display any fractional digits. The general (c) type results in a
NumberFormat.getCurrencyInstance() starting point. The percent
(p) type results in a NumberFormat.getPercentInstance() starting point.SHORT, MEDIUM, LONG, and FULL constants
defined in the DateFormat class. This setting is ignored
if the template=TEXT setting is present. If this setting
is omitted, or incorrectly set, then time information is omitted
from the output format.minimum number of
fractional digits shown.maximum number of
fractional digits shown.minimum number of
integer digits shown.maximum number of
integer digits shown.grouping
feature. If omitted - we leave it at the system default.
props - Properties to get the information from (as described above)
IllegalArgumentException - If the properties passed were invalid (no template, date or time set).
ParseException - If a unrecoverable error was found trying to parse one of the values.protected void setToDay(DateFormat val)
DateFormat to format a date to day
precision.
val - New DateFormat value to assign - or null if you want us to
reload the default.getToDay()public final DateFormat getToDay()
DateFormat to format a date to day precision.
setToDay(java.text.DateFormat)protected void setToMinute(DateFormat val)
DateFormat to format a date to minute
precision.
val - New DateFormat value to assign - or null if you want us to
reload the default.getToMinute()public final DateFormat getToMinute()
DateFormat to format a date to minute
precision.
setToMinute(java.text.DateFormat)protected void setToSecond(DateFormat val)
DateFormat to format a date to second
precision.
val - New DateFormat value to assign - or null if you want us to
reload the default.getToSecond()public final DateFormat getToSecond()
DateFormat to format a date to second
precision.
setToSecond(java.text.DateFormat)protected void setToMilli(DateFormat val)
DateFormat to format a date to
millisecond precision.
val - New DateFormat value to assign - or null if you want us to
reload the default.getToMilli()public final DateFormat getToMilli()
DateFormat to format a date to
millisecond precision.
setToMilli(java.text.DateFormat)protected void setInteger(NumberFormat val)
NumberFormat to be used for integer values.
val - New NumberFormat value to assign - or null if you want us to
reload the default.getInteger()public final NumberFormat getInteger()
NumberFormat to format suitable for
working with integers.
setInteger(java.text.NumberFormat)
void loadConfig(String name)
throws ConfigException,
IOException
ConfigException
IOExceptionprotected static void setInstance(Formats val)
Formats object.
val - New instance to use as the global default.getInstance()public static Formats getInstance()
Formats object.
Formats object.setInstance(com.ccg.text.Formats)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||