Java Doc for NumberTool.java in  » Template-Engine » Velocity » org » apache » velocity » tools » generic » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Template Engine » Velocity » org.apache.velocity.tools.generic 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.velocity.tools.generic.NumberTool

NumberTool
public class NumberTool (Code)
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.


author:
   Nathan Bubna
author:
   Mike Kienenberger
since:
   VelocityTools 1.2
version:
   $Id: NumberTool.java 479724 2006-11-27 18:49:37Z nbubna $


Field Summary
final public static  StringDEFAULT_FORMAT
     The default format to be used when none is specified.

Constructor Summary
public  NumberTool()
     Default constructor.

Method Summary
public  Stringcurrency(Object obj)
     Convenience method equivalent to $number.format("currency", $foo).
public  Stringformat(Object obj)
     Converts the specified object to a number and formats it according to the pattern or style returned by NumberTool.getFormat() .
public  Stringformat(String format, Object obj)
     Converts the specified object to a number and returns a formatted string representing that number in the locale returned by NumberTool.getLocale() .
public  Stringformat(String format, Object obj, Locale locale)
     Converts the specified object to a number and returns a formatted string representing that number in the specified Locale .
public  StringgetFormat()
     Return the pattern or style to be used for formatting numbers when none is specified.
public  LocalegetLocale()
     This implementation returns the default locale.
public  NumberFormatgetNumberFormat(String format, Locale locale)
     Returns a NumberFormat instance for the specified format and Locale .
protected  NumberFormatgetNumberFormat(int numberStyle, Locale locale)
     Returns a NumberFormat instance for the specified number style and Locale .
protected  intgetStyleAsInt(String style)
     Checks a string to see if it matches one of the standard NumberFormat style patterns: NUMBER, CURRENCY, PERCENT, INTEGER, or DEFAULT.
public  Stringinteger(Object obj)
     Convenience method equivalent to $number.format("integer", $foo).
public  Stringnumber(Object obj)
     Convenience method equivalent to $number.format("number", $foo).
public  Stringpercent(Object obj)
     Convenience method equivalent to $number.format("percent", $foo).
public  NumbertoNumber(Object obj)
     Converts an object to an instance of Number using the format returned by NumberTool.getFormat() and the Locale returned by NumberTool.getLocale() if the object is not already an instance of Number.
public  NumbertoNumber(String format, Object obj)
     Converts an object to an instance of Number using the specified format and the Locale returned by NumberTool.getLocale() if the object is not already an instance of Number.
public  NumbertoNumber(String format, Object obj, Locale locale)
     Converts an object to an instance of Number using the specified format and Locale if the object is not already an instance of Number.

Field Detail
DEFAULT_FORMAT
final public static String DEFAULT_FORMAT(Code)
The default format to be used when none is specified.




Constructor Detail
NumberTool
public NumberTool()(Code)
Default constructor.




Method Detail
currency
public String currency(Object obj)(Code)
Convenience method equivalent to $number.format("currency", $foo).
since:
   VelocityTools 1.3



format
public String format(Object obj)(Code)
Converts the specified object to a number and formats it according to the pattern or style returned by NumberTool.getFormat() .
Parameters:
  obj - the number object to be formatted the specified number formatted as a string
See Also:   NumberTool.format(String format,Object obj,Locale locale)



format
public String format(String format, Object obj)(Code)
Converts the specified object to a number and returns a formatted string representing that number in the locale returned by NumberTool.getLocale() .
Parameters:
  format - the formatting instructions
Parameters:
  obj - the number object to be formatted a formatted string for this locale representing the specifiednumber or null if the parameters are invalid
See Also:   NumberTool.format(String format,Object obj,Locale locale)



format
public String format(String format, Object obj, Locale locale)(Code)
Converts the specified object to a number and returns a formatted string representing that number in the specified Locale .
Parameters:
  format - the custom or standard pattern to be used
Parameters:
  obj - the number object to be formatted
Parameters:
  locale - the Locale to be used when formatting a formatted string representing the specified number ornull if the parameters are invalid



getFormat
public String getFormat()(Code)
Return 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.




getLocale
public Locale getLocale()(Code)
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. the default Locale



getNumberFormat
public NumberFormat getNumberFormat(String format, Locale locale)(Code)
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.
Parameters:
  format - the custom or standard formatting pattern to be used
Parameters:
  locale - the Locale to be used an instance of NumberFormat
See Also:   NumberFormat



getNumberFormat
protected NumberFormat getNumberFormat(int numberStyle, Locale locale)(Code)
Returns a NumberFormat instance for the specified number style and Locale .
Parameters:
  numberStyle - the number style (number will be ignored if this isless than zero or the number style is not recognized)
Parameters:
  locale - the Locale to be used an instance of NumberFormat or nullif an instance cannot be constructed with the givenparameters



getStyleAsInt
protected int getStyleAsInt(String style)(Code)
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.
See Also:   NumberFormat
Parameters:
  style - the string to be checked the int identifying the style pattern



integer
public String integer(Object obj)(Code)
Convenience method equivalent to $number.format("integer", $foo).
since:
   VelocityTools 1.3



number
public String number(Object obj)(Code)
Convenience method equivalent to $number.format("number", $foo).
since:
   VelocityTools 1.3



percent
public String percent(Object obj)(Code)
Convenience method equivalent to $number.format("percent", $foo).
since:
   VelocityTools 1.3



toNumber
public Number toNumber(Object obj)(Code)
Converts an object to an instance of Number using the format returned by NumberTool.getFormat() and the Locale returned by NumberTool.getLocale() if the object is not already an instance of Number.
Parameters:
  obj - the number to convert the object as a Number or null if noconversion is possible



toNumber
public Number toNumber(String format, Object obj)(Code)
Converts an object to an instance of Number using the specified format and the Locale returned by NumberTool.getLocale() if the object is not already an instance of Number.
Parameters:
  format - - the format the number is in
Parameters:
  obj - - the number to convert the object as a Number or null if noconversion is possible
See Also:   NumberTool.toNumber(String format,Object obj,Locale locale)



toNumber
public Number toNumber(String format, Object obj, Locale locale)(Code)
Converts an object to an instance of Number using the specified format and Locale if the object is not already an instance of Number.
Parameters:
  format - - the format the number is in
Parameters:
  obj - - the number to convert
Parameters:
  locale - - the Locale the object as a Number or null if noconversion is possible
See Also:   NumberFormat.parse



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.