java.lang.Object | |
↳ | com.atlassian.jira.util.velocity.NumberTool |
This class is stolen borrowed from Apache's velocity tools.
If we need more tools in future, we should look at importing this instead
Tool for working with Number
in Velocity templates.
It is useful for accessing and
formatting arbitrary Number
objects. Also
the tool can be used to retrieve NumberFormat instances
or make conversions to and from various number types.
Example uses: $myNumber -> 13.55 $number.format('currency',$myNumber) -> $13.55 $number.format('integer',$myNumber) -> 13 Example toolbox.xml config (if you want to use this with VelocityView): <tool> <key>number</key> <scope>application</scope> <class>org.apache.velocity.tools.generic.NumberTool</class> </tool>
This tool is entirely threadsafe, and has no instance members. It may be used in any scope (request, session, or application). As such, the methods are highly interconnected, and overriding key methods provides an easy way to create subclasses that use a non-default format or locale.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | DEFAULT_FORMAT | The default format to be used when none is specified. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Default constructor.
| |||||||||||
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Converts the specified object to a number and formats it according to
the pattern or style returned by
getFormat() . | |||||||||||
Converts the specified object to a number and returns
a formatted string representing that number in the specified
Locale . | |||||||||||
Converts the specified object to a number and returns
a formatted string representing that number in the locale
returned by
getLocale() . | |||||||||||
Return the pattern or style to be used for formatting numbers when none
is specified.
| |||||||||||
This implementation returns the default locale.
| |||||||||||
Returns a
NumberFormat instance for the specified
format and Locale . | |||||||||||
Converts an object to an instance of
Number using the
format returned by getFormat() and the Locale
returned by getLocale() if the object is not already
an instance of Number. | |||||||||||
Converts an object to an instance of
Number using the
specified format and the Locale returned by
getLocale() if the object is not already an instance
of Number. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns a
NumberFormat instance for the specified
number style and Locale . | |||||||||||
Checks a string to see if it matches one of the standard
NumberFormat style patterns:
NUMBER, CURRENCY, PERCENT, INTEGER, or DEFAULT.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
The default format to be used when none is specified.
Default constructor.
Converts the specified object to a number and formats it according to
the pattern or style returned by getFormat()
.
obj | the number object to be formatted |
---|
Converts the specified object to a number and returns
a formatted string representing that number in the specified
Locale
.
format | the custom or standard pattern to be used |
---|---|
obj | the number object to be formatted |
locale | the Locale to be used when formatting |
null
if the parameters are invalid
Converts the specified object to a number and returns
a formatted string representing that number in the locale
returned by getLocale()
.
format | the formatting instructions |
---|---|
obj | the number object to be formatted |
null
if the parameters are invalidReturn the pattern or style to be used for formatting numbers when none is specified. This implementation gives a 'default' number format. Subclasses may override this to provide a different default format.
NOTE: At some point in the future it may be feasible to configure this value via the toolbox definition, but at present, it is not possible to specify custom tool configurations there. For now you should just override this in a subclass to have a different default.
This implementation returns the default locale. Subclasses may override this to return alternate locales. Please note that doing so will affect all formatting methods where no locale is specified in the parameters.
Locale
Returns a NumberFormat
instance for the specified
format and Locale
. If the format specified is a standard
style pattern, then a number instance
will be returned with the number style set to the
specified style. If it is a custom format, then a customized
NumberFormat
will be returned.
format | the custom or standard formatting pattern to be used |
---|---|
locale | the Locale to be used |
NumberFormat
Converts an object to an instance of Number
using the
format returned by getFormat()
and the Locale
returned by getLocale()
if the object is not already
an instance of Number.
obj | the number to convert |
---|
Number
or null
if no
conversion is possible
Converts an object to an instance of Number
using the
specified format and Locale
if the object is not already
an instance of Number.
format | - the format the number is in |
---|---|
obj | - the number to convert |
locale | - the Locale |
Number
or null
if no
conversion is possibleConverts an object to an instance of Number
using the
specified format and the Locale
returned by
getLocale()
if the object is not already an instance
of Number.
format | - the format the number is in |
---|---|
obj | - the number to convert |
Number
or null
if no
conversion is possibleReturns a NumberFormat
instance for the specified
number style and Locale
.
numberStyle | the number style (number will be ignored if this is less than zero or the number style is not recognized) |
---|---|
locale | the Locale to be used |
NumberFormat
or null
if an instance cannot be constructed with the given
parameters
Checks a string to see if it matches one of the standard NumberFormat style patterns: NUMBER, CURRENCY, PERCENT, INTEGER, or DEFAULT. if it does it will return the integer constant for that pattern. if not, it will return -1.
style | the string to be checked |
---|