Java Doc for MathTool.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.MathTool

MathTool
public class MathTool (Code)

Tool for performing math in Velocity.

Some things should be noted here:

  • This class does not have methods that take primitives. This is simply because Velocity wraps all primitives for us automagically.
  • No null pointer, number format, or divide by zero exceptions are thrown here. This is because such exceptions thrown in template halt rendering. It should be sufficient debugging feedback that Velocity will render the reference literally. (e.g. $math.div(1, 0) renders as '$math.div(1, 0)')

 Example toolbox.xml config (if you want to use this with VelocityView):
 <tool>
 <key>math</key>
 <scope>application</scope>
 <class>org.apache.velocity.tools.generic.MathTool</class>
 </tool>
 


author:
   Nathan Bubna
author:
   Leon Messerschmidt
version:
   $Revision: 479724 $ $Date: 2006-11-27 10:49:37 -0800 (Mon, 27 Nov 2006) $




Method Summary
public  Numberabs(Object num)
    
public  Numberadd(Object num1, Object num2)
    
public  Integerceil(Object num)
    
public  Numberdiv(Object num1, Object num2)
    
public  Integerfloor(Object num)
    
public  NumbergetAverage(Collection collection, String field)
     Get the average of the values from a list
Parameters:
  collection - A collection containing Java beans
Parameters:
  field - A Java Bean field for the objects in collection thatwill return a number.
public  NumbergetAverage(Object[] array, String field)
     Get the sum of the values from a list
Parameters:
  array - A collection containing Java beans
Parameters:
  field - A Java Bean field for the objects in array thatwill return a number.
public  NumbergetAverage(Collection collection)
    
public  NumbergetAverage(Object[] array)
    
public  NumbergetAverage(double[] values)
    
public  NumbergetAverage(long[] values)
    
public  DoublegetRandom()
    
public  NumbergetTotal(Collection collection, String field)
     Get the sum of the values from a list
Parameters:
  collection - A collection containing Java beans
Parameters:
  field - A Java Bean field for the objects in collection thatwill return a number.
public  NumbergetTotal(Object[] array, String field)
     Get the sum of the values from a list
Parameters:
  array - An array containing Java beans
Parameters:
  field - A Java Bean field for the objects in array thatwill return a number.
public  NumbergetTotal(Collection collection)
    
public  NumbergetTotal(Object[] array)
    
public  NumbergetTotal(double[] values)
     Get the sum of the values
Parameters:
  values - The list of double values to add up.
public  NumbergetTotal(long[] values)
     Get the sum of the values
Parameters:
  values - The list of long values to add up.
public  Integeridiv(Object num1, Object num2)
     Does integer division on the int values of the specified numbers.
protected  NumbermatchType(Number in, double out)
    
protected  NumbermatchType(Number in1, Number in2, double out)
     Takes the original argument(s) and returns the resulting value as an instance of the best matching type (Integer, Long, or Double). If either an argument or the result is not an integer (i.e.
public  Numbermax(Object num1, Object num2)
    
public  Numbermin(Object num1, Object num2)
    
public  Integermod(Object num1, Object num2)
     Does integer modulus on the int values of the specified numbers.
public  Numbermul(Object num1, Object num2)
    
protected  NumberparseNumber(String value)
     Converts an object into a Number (if it can) This is used as the base for all numeric parsing methods.
public  Numberpow(Object num1, Object num2)
    
public  Numberrandom(Object num1, Object num2)
     This returns a random Number within the specified range.
public  Integerround(Object num)
    
public  DoubleroundTo(Object decimals, Object num)
     Rounds a number to the specified number of decimal places.
public  Numbersub(Object num1, Object num2)
    
public  DoubletoDouble(Object num)
    
public  IntegertoInteger(Object num)
    
public  NumbertoNumber(Object num)
     Converts an object with a numeric value into a Number Valid formats are Number or a String representation of a number.



Method Detail
abs
public Number abs(Object num)(Code)

Parameters:
  num - the number the absolute value of the number ornull if it's invalid
See Also:   MathTool.toDouble



add
public Number add(Object num1, Object num2)(Code)

Parameters:
  num1 - the first number
Parameters:
  num2 - the second number the sum of the numbers ornull if they're invalid
See Also:   MathTool.toNumber



ceil
public Integer ceil(Object num)(Code)

Parameters:
  num - the number the smallest integer that is notless than the given number



div
public Number div(Object num1, Object num2)(Code)

Parameters:
  num1 - the first number
Parameters:
  num2 - the second number the quotient of the numbers ornull if they're invalid
See Also:   MathTool.toNumber



floor
public Integer floor(Object num)(Code)

Parameters:
  num - the number the integer portion of the number



getAverage
public Number getAverage(Collection collection, String field)(Code)
Get the average of the values from a list
Parameters:
  collection - A collection containing Java beans
Parameters:
  field - A Java Bean field for the objects in collection thatwill return a number. The average of the values in collection.



getAverage
public Number getAverage(Object[] array, String field)(Code)
Get the sum of the values from a list
Parameters:
  array - A collection containing Java beans
Parameters:
  field - A Java Bean field for the objects in array thatwill return a number. The sum of the values in array.



getAverage
public Number getAverage(Collection collection)(Code)
Get the average of the values
Parameters:
  collection - A collection containing number values The average of the values in collection.



getAverage
public Number getAverage(Object[] array)(Code)
Get the average of the values
Parameters:
  array - An array containing number values The sum of the values in array.



getAverage
public Number getAverage(double[] values)(Code)
Get the average of the values in an array of double values
Parameters:
  values - The list of double values The average of the array of values



getAverage
public Number getAverage(long[] values)(Code)
Get the average of the values in an array of long values
Parameters:
  values - The list of long values The average of the array of values



getRandom
public Double getRandom()(Code)
a pseudo-random Double greaterthan or equal to 0.0 and less than 1.0
See Also:   Math.random



getTotal
public Number getTotal(Collection collection, String field)(Code)
Get the sum of the values from a list
Parameters:
  collection - A collection containing Java beans
Parameters:
  field - A Java Bean field for the objects in collection thatwill return a number. The sum of the values in collection.



getTotal
public Number getTotal(Object[] array, String field)(Code)
Get the sum of the values from a list
Parameters:
  array - An array containing Java beans
Parameters:
  field - A Java Bean field for the objects in array thatwill return a number. The sum of the values in array.



getTotal
public Number getTotal(Collection collection)(Code)
Get the sum of the values
Parameters:
  collection - A collection containing numeric values The sum of the values in collection.



getTotal
public Number getTotal(Object[] array)(Code)
Get the sum of the values
Parameters:
  array - An array containing number values The sum of the values in array.



getTotal
public Number getTotal(double[] values)(Code)
Get the sum of the values
Parameters:
  values - The list of double values to add up. The sum of the arrays



getTotal
public Number getTotal(long[] values)(Code)
Get the sum of the values
Parameters:
  values - The list of long values to add up. The sum of the arrays



idiv
public Integer idiv(Object num1, Object num2)(Code)
Does integer division on the int values of the specified numbers.

So, $math.idiv('5.1',3) will return '1', and $math.idiv(6,'3.9') will return '2'.


Parameters:
  num1 - the first number
Parameters:
  num2 - the second number the result of performing integer divisionon the operands.
See Also:   MathTool.toInteger



matchType
protected Number matchType(Number in, double out)(Code)

See Also:   MathTool.matchType(Number,Number,double)



matchType
protected Number matchType(Number in1, Number in2, double out)(Code)
Takes the original argument(s) and returns the resulting value as an instance of the best matching type (Integer, Long, or Double). If either an argument or the result is not an integer (i.e. has no decimal when rendered) the result will be returned as a Double. If not and the result is < -2147483648 or > 2147483647, then a Long will be returned. Otherwise, an Integer will be returned.



max
public Number max(Object num1, Object num2)(Code)

Parameters:
  num1 - the first number
Parameters:
  num2 - the second number the largest of the numbers ornull if they're invalid
See Also:   MathTool.toNumber



min
public Number min(Object num1, Object num2)(Code)

Parameters:
  num1 - the first number
Parameters:
  num2 - the second number the smallest of the numbers ornull if they're invalid
See Also:   MathTool.toNumber



mod
public Integer mod(Object num1, Object num2)(Code)
Does integer modulus on the int values of the specified numbers.

So, $math.mod('5.1',3) will return '2', and $math.mod(6,'3.9') will return '0'.


Parameters:
  num1 - the first number
Parameters:
  num2 - the second number the result of performing integer moduluson the operands.
See Also:   MathTool.toInteger



mul
public Number mul(Object num1, Object num2)(Code)

Parameters:
  num1 - the first number
Parameters:
  num2 - the second number the product of the numbers ornull if they're invalid
See Also:   MathTool.toNumber



parseNumber
protected Number parseNumber(String value) throws NumberFormatException(Code)
Converts an object into a Number (if it can) This is used as the base for all numeric parsing methods. So, sub-classes can override to allow for customized number parsing. (e.g. for i18n, fractions, compound numbers, bigger numbers, etc.)
Parameters:
  value - the string to be parsed the value as a Number



pow
public Number pow(Object num1, Object num2)(Code)

Parameters:
  num1 - the first number
Parameters:
  num2 - the second number the first number raised to the power of thesecond or null if they're invalid
See Also:   MathTool.toNumber



random
public Number random(Object num1, Object num2)(Code)
This returns a random Number within the specified range. The returned value will be greater than or equal to the first number and less than the second number. If both arguments are whole numbers then the returned number will also be, otherwise a Double will be returned.
Parameters:
  num1 - the first number
Parameters:
  num2 - the second number a pseudo-random Number greater thanor equal to the first number and less thanthe second
See Also:   Math.random



round
public Integer round(Object num)(Code)
Rounds a number to the nearest whole Integer
Parameters:
  num - the number to round the number rounded to the nearest whole Integeror null if it's invalid
See Also:   java.lang.Math.rint(double)



roundTo
public Double roundTo(Object decimals, Object num)(Code)
Rounds a number to the specified number of decimal places. This is particulary useful for simple display formatting. If you want to round an number to the nearest integer, it is better to use MathTool.round , as that will return an Integer rather than a Double .
Parameters:
  decimals - the number of decimal places
Parameters:
  num - the number to round the value rounded to the specified number ofdecimal places or null if it's invalid
See Also:   MathTool.toNumber



sub
public Number sub(Object num1, Object num2)(Code)

Parameters:
  num1 - the first number
Parameters:
  num2 - the second number the difference of the numbers ornull if they're invalid
See Also:   MathTool.toNumber



toDouble
public Double toDouble(Object num)(Code)
Converts an object with a numeric value into a Double Valid formats are Number or a String representation of a number
Parameters:
  num - the number to be converted a Double representation of the numberor null if it's invalid



toInteger
public Integer toInteger(Object num)(Code)
Converts an object with a numeric value into an Integer Valid formats are Number or a String representation of a number
Parameters:
  num - the number to be converted a Integer representation of the numberor null if it's invalid



toNumber
public Number toNumber(Object num)(Code)
Converts an object with a numeric value into a Number Valid formats are Number or a String representation of a number. Note that this does not handle localized number formats. Use the NumberTool to handle such conversions.
Parameters:
  num - the number to be converted a Number representation of the numberor null if it's invalid



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.