|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.velocity.tools.generic.SafeConfig org.apache.velocity.tools.generic.LocaleConfig org.apache.velocity.tools.generic.FormatConfig org.apache.velocity.tools.generic.MathTool
@DefaultKey(value="math") public class MathTool
Tool for performing math in Velocity.
Some things should be noted here:
Example tools.xml config: <tools> <toolbox scope="application"> <tool class="org.apache.velocity.tools.generic.MathTool"/> </toolbox> </tools>
Field Summary |
---|
Fields inherited from class org.apache.velocity.tools.generic.FormatConfig |
---|
DEFAULT_FORMAT, FORMAT_KEY |
Fields inherited from class org.apache.velocity.tools.generic.LocaleConfig |
---|
DEFAULT_LOCALE |
Fields inherited from class org.apache.velocity.tools.generic.SafeConfig |
---|
LOCK_CONFIG_KEY, OLD_LOCK_CONFIG_KEY, SAFE_MODE_KEY |
Constructor Summary | |
---|---|
MathTool()
|
Method Summary | |
---|---|
java.lang.Number |
abs(java.lang.Object num)
|
java.lang.Number |
add(java.lang.Object... nums)
|
java.lang.Number |
add(java.lang.Object num1,
java.lang.Object num2)
|
java.lang.Integer |
ceil(java.lang.Object num)
|
java.lang.Number |
div(java.lang.Object... nums)
|
java.lang.Number |
div(java.lang.Object num1,
java.lang.Object num2)
|
java.lang.Integer |
floor(java.lang.Object num)
|
java.lang.Number |
getAverage(java.util.Collection collection)
Get the average of the values |
java.lang.Number |
getAverage(java.util.Collection collection,
java.lang.String field)
Get the average of the values from a list |
java.lang.Number |
getAverage(double... values)
Get the average of the values in an array of double values |
java.lang.Number |
getAverage(long... values)
Get the average of the values in an array of long values |
java.lang.Number |
getAverage(java.lang.Object... array)
Get the average of the values |
java.lang.Number |
getAverage(java.lang.Object[] array,
java.lang.String field)
Get the sum of the values from a list |
java.lang.Double |
getRandom()
|
java.lang.Number |
getTotal(java.util.Collection collection)
Get the sum of the values |
java.lang.Number |
getTotal(java.util.Collection collection,
java.lang.String field)
Get the sum of the values from a list |
java.lang.Number |
getTotal(double... values)
Get the sum of the values |
java.lang.Number |
getTotal(long... values)
Get the sum of the values |
java.lang.Number |
getTotal(java.lang.Object... array)
Get the sum of the values |
java.lang.Number |
getTotal(java.lang.Object[] array,
java.lang.String field)
Get the sum of the values from a list |
protected boolean |
hasFloatingPoint(java.lang.String value)
|
java.lang.Integer |
idiv(java.lang.Object num1,
java.lang.Object num2)
Does integer division on the int values of the specified numbers. |
protected java.lang.Number |
matchType(double out,
java.lang.Number... in)
Takes the original argument(s) and returns the resulting value as an instance of the best matching type (Integer, Long, or Double). |
protected java.lang.Number |
matchType(java.lang.Number in,
double out)
|
protected java.lang.Number |
matchType(java.lang.Number in1,
java.lang.Number in2,
double out)
|
java.lang.Number |
max(java.lang.Object... nums)
|
java.lang.Number |
max(java.lang.Object num1,
java.lang.Object num2)
|
java.lang.Number |
min(java.lang.Object... nums)
|
java.lang.Number |
min(java.lang.Object num1,
java.lang.Object num2)
|
java.lang.Integer |
mod(java.lang.Object num1,
java.lang.Object num2)
Does integer modulus on the int values of the specified numbers. |
java.lang.Number |
mul(java.lang.Object... nums)
|
java.lang.Number |
mul(java.lang.Object num1,
java.lang.Object num2)
|
protected java.lang.Number |
parseNumber(java.lang.String value)
Deprecated. |
java.lang.Number |
pow(java.lang.Object num1,
java.lang.Object num2)
|
java.lang.Number |
random(java.lang.Object num1,
java.lang.Object num2)
This returns a random Number within the
specified range. |
java.lang.Integer |
round(java.lang.Object num)
Rounds a number to the nearest whole Integer |
java.lang.Double |
roundTo(java.lang.Object decimals,
java.lang.Object num)
Rounds a number to the specified number of decimal places. |
java.lang.Number |
sub(java.lang.Object... nums)
|
java.lang.Number |
sub(java.lang.Object num1,
java.lang.Object num2)
|
java.lang.Double |
toDouble(java.lang.Object num)
Converts an object with a numeric value into a Double Valid formats are Number or a String
representation of a number |
java.lang.Integer |
toInteger(java.lang.Object num)
Converts an object with a numeric value into an Integer Valid formats are Number or a String
representation of a number |
java.lang.Number |
toNumber(java.lang.Object num)
Converts an object with a numeric value into a Number Valid formats are Number or a String
representation of a number. |
Methods inherited from class org.apache.velocity.tools.generic.FormatConfig |
---|
configure, getFormat, setFormat |
Methods inherited from class org.apache.velocity.tools.generic.LocaleConfig |
---|
getLocale, setLocale |
Methods inherited from class org.apache.velocity.tools.generic.SafeConfig |
---|
configure, isConfigLocked, isSafeMode, setLockConfig, setSafeMode |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MathTool()
Method Detail |
---|
public java.lang.Number add(java.lang.Object num1, java.lang.Object num2)
public java.lang.Number sub(java.lang.Object num1, java.lang.Object num2)
public java.lang.Number mul(java.lang.Object num1, java.lang.Object num2)
public java.lang.Number div(java.lang.Object num1, java.lang.Object num2)
public java.lang.Number max(java.lang.Object num1, java.lang.Object num2)
public java.lang.Number min(java.lang.Object num1, java.lang.Object num2)
public java.lang.Number add(java.lang.Object... nums)
nums
- the numbers to be added
null
if they're invalidtoNumber(java.lang.Object)
public java.lang.Number sub(java.lang.Object... nums)
nums
- the numbers to be subtracted
null
if they're invalidtoNumber(java.lang.Object)
public java.lang.Number mul(java.lang.Object... nums)
nums
- the numbers to be multiplied
null
if they're invalidtoNumber(java.lang.Object)
public java.lang.Number div(java.lang.Object... nums)
nums
- the numbers to be divided
null
if they're invalid
or if any denominator equals zerotoNumber(java.lang.Object)
public java.lang.Number pow(java.lang.Object num1, java.lang.Object num2)
num1
- the first numbernum2
- the second number
null
if they're invalidtoNumber(java.lang.Object)
public java.lang.Integer idiv(java.lang.Object num1, java.lang.Object num2)
So, $math.idiv('5.1',3) will return '1', and $math.idiv(6,'3.9') will return '2'.
num1
- the first numbernum2
- the second number
toInteger(java.lang.Object)
public java.lang.Integer mod(java.lang.Object num1, java.lang.Object num2)
So, $math.mod('5.1',3) will return '2', and $math.mod(6,'3.9') will return '0'.
num1
- the first numbernum2
- the second number
toInteger(java.lang.Object)
public java.lang.Number max(java.lang.Object... nums)
nums
- the numbers to be searched
null
if they're invalidtoNumber(java.lang.Object)
public java.lang.Number min(java.lang.Object... nums)
nums
- the numbers to be searched
null
if they're invalidtoNumber(java.lang.Object)
public java.lang.Number abs(java.lang.Object num)
num
- the number
null
if it's invalidtoDouble(java.lang.Object)
public java.lang.Integer ceil(java.lang.Object num)
num
- the number
public java.lang.Integer floor(java.lang.Object num)
num
- the number
public java.lang.Integer round(java.lang.Object num)
num
- the number to round
null
if it's invalidMath.rint(double)
public java.lang.Double roundTo(java.lang.Object decimals, java.lang.Object num)
round(java.lang.Object)
, as that will return
an Integer
rather than a Double
.
decimals
- the number of decimal placesnum
- the number to round
null
if it's invalidtoNumber(java.lang.Object)
public java.lang.Double getRandom()
Double
greater
than or equal to 0.0 and less than 1.0Math.random()
public java.lang.Number random(java.lang.Object num1, java.lang.Object num2)
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.
num1
- the first numbernum2
- the second number
Number
greater than
or equal to the first number and less than
the secondMath.random()
public java.lang.Integer toInteger(java.lang.Object num)
Number
or a String
representation of a number
num
- the number to be converted
Integer
representation of the number
or null
if it's invalidpublic java.lang.Double toDouble(java.lang.Object num)
Number
or a String
representation of a number
num
- the number to be converted
Double
representation of the number
or null
if it's invalidpublic java.lang.Number toNumber(java.lang.Object num)
Number
or a String
representation of a number. Note that this does not
handle localized number formats. Use the NumberTool
to handle such conversions.
num
- the number to be converted
Number
representation of the number
or null
if it's invalidprotected java.lang.Number matchType(java.lang.Number in, double out)
matchType(double,Number...)
protected java.lang.Number matchType(java.lang.Number in1, java.lang.Number in2, double out)
matchType(double,Number...)
protected java.lang.Number matchType(double out, java.lang.Number... in)
protected boolean hasFloatingPoint(java.lang.String value)
@Deprecated protected java.lang.Number parseNumber(java.lang.String value)
public java.lang.Number getTotal(java.util.Collection collection, java.lang.String field)
collection
- A collection containing Java beansfield
- A Java Bean field for the objects in collection that
will return a number.
public java.lang.Number getAverage(java.util.Collection collection, java.lang.String field)
collection
- A collection containing Java beansfield
- A Java Bean field for the objects in collection that
will return a number.
public java.lang.Number getTotal(java.lang.Object[] array, java.lang.String field)
array
- An array containing Java beansfield
- A Java Bean field for the objects in array that
will return a number.
public java.lang.Number getAverage(java.lang.Object[] array, java.lang.String field)
array
- A collection containing Java beansfield
- A Java Bean field for the objects in array that
will return a number.
public java.lang.Number getTotal(java.util.Collection collection)
collection
- A collection containing numeric values
public java.lang.Number getAverage(java.util.Collection collection)
collection
- A collection containing number values
public java.lang.Number getTotal(java.lang.Object... array)
array
- An array containing number values
public java.lang.Number getAverage(java.lang.Object... array)
array
- An array containing number values
public java.lang.Number getTotal(double... values)
values
- The list of double values to add up.
public java.lang.Number getAverage(double... values)
values
- The list of double values
public java.lang.Number getTotal(long... values)
values
- The list of long values to add up.
public java.lang.Number getAverage(long... values)
values
- The list of long values
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |