com.logikdev.jsftools
Class StaticMathTool

java.lang.Object
  extended by com.logikdev.jsftools.StaticMathTool

public class StaticMathTool
extends java.lang.Object

Tool for performing math in JSF.

Since:
0.1
Author:
Stéphane Moreau
See Also:
org.apache.velocity.tools.generic.MathTool

Constructor Summary
StaticMathTool()
           
 
Method Summary
static java.lang.Number abs(java.lang.Object num)
          Returns the absolute value of the number or null if it's invalid.
static java.lang.Number add(java.lang.Object[] nums)
          Returns the sum of the numbers or null if they're invalid.
static java.lang.Number add(java.lang.Object num1, java.lang.Object num2)
          Returns the sum of the two numbers or null if they're invalid.
static java.lang.Integer ceil(java.lang.Object num)
          Returns the smallest integer that is not less than the given number.
static java.lang.Number div(java.lang.Object[] nums)
          Returns the quotient of the numbers or null if they're invalid or if any denominator equals zero.
static java.lang.Number div(java.lang.Object num1, java.lang.Object num2)
          Returns the quotient of the two numbers or null if they're invalid or if any denominator equals zero.
static java.lang.Integer floor(java.lang.Object num)
          Returns the integer portion of the number.
static java.lang.Number getAverage(java.util.Collection<?> collection)
          Gets the average of the values.
static java.lang.Number getAverage(java.util.Collection<?> collection, java.lang.String field)
          Gets the average of the values from a list.
static java.lang.Number getAverage(java.lang.Double[] values)
          Gets the average of the values in an array of double values.
static java.lang.Number getAverage(java.lang.Long[] values)
          Gets the average of the values in an array of long values.
static java.lang.Number getAverage(java.lang.Object[] array)
          Gets the average of the values.
static java.lang.Number getAverage(java.lang.Object[] array, java.lang.String field)
          Get the average of the values from a list.
static java.lang.Double getRandom()
          Returns a pseudo-random Double greater than or equal to 0.0 and less than 1.0.
static java.lang.Number getTotal(java.util.Collection<?> collection)
          Gets the sum of the values.
static java.lang.Number getTotal(java.util.Collection<?> collection, java.lang.String field)
          Gets the sum of the values from a list.
static java.lang.Number getTotal(java.lang.Double[] values)
          Gets the sum of the values.
static java.lang.Number getTotal(java.lang.Long[] values)
          Gets the sum of the values.
static java.lang.Number getTotal(java.lang.Object[] array)
          Gets the sum of the values.
static java.lang.Number getTotal(java.lang.Object[] array, java.lang.String field)
          Gets the sum of the values from a list.
static java.lang.Integer idiv(java.lang.Object num1, java.lang.Object num2)
          Does integer division on the int values of the specified numbers.
static java.lang.Number max(java.lang.Object[] nums)
          Returns the largest of the numbers or null if they're invalid.
static java.lang.Number max(java.lang.Object num1, java.lang.Object num2)
          Returns the largest of the two numbers or null if they're invalid.
static java.lang.Number min(java.lang.Object[] nums)
          Returns the smallest of the numbers or null if they're invalid.
static java.lang.Number min(java.lang.Object num1, java.lang.Object num2)
          Returns the smallest of the numbers or null if they're invalid.
static java.lang.Integer mod(java.lang.Object num1, java.lang.Object num2)
          Does integer modulus on the int values of the specified numbers.
static java.lang.Number mul(java.lang.Object[] nums)
          Returns the product of the numbers or null if they're invalid.
static java.lang.Number mul(java.lang.Object num1, java.lang.Object num2)
          Returns the product of the two numbers or null if they're invalid.
static java.lang.Number pow(java.lang.Object num1, java.lang.Object num2)
          Returns the first number raised to the power of the second or null if they're invalid.
static java.lang.Number random(java.lang.Object num1, java.lang.Object num2)
          This returns a random Number within the specified range.
static java.lang.Integer round(java.lang.Object num)
          Rounds a number to the nearest whole Integer.
static java.lang.Double roundTo(java.lang.Object decimals, java.lang.Object num)
          Rounds a number to the specified number of decimal places.
static java.lang.Number sub(java.lang.Object[] nums)
          Returns the difference of the numbers (subtracted in order) or null if they're invalid.
static java.lang.Number sub(java.lang.Object num1, java.lang.Object num2)
          Returns the difference of the two numbers (subtracted in order) or null if they're invalid.
static 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.
static 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.
static 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StaticMathTool

public StaticMathTool()
Method Detail

abs

public static final java.lang.Number abs(java.lang.Object num)
Returns the absolute value of the number or null if it's invalid.

Parameters:
num - The number
Returns:
The absolute value of the number or null if it's invalid
See Also:
org.apache.velocity.tools.generic.MathTool#abs(java.lang.Object)

add

public static final java.lang.Number add(java.lang.Object[] nums)
Returns the sum of the numbers or null if they're invalid.

Parameters:
nums - The numbers to be added
Returns:
The sum of the numbers or null if they're invalid
See Also:
org.apache.velocity.tools.generic.MathTool#add(java.lang.Object...)

add

public static final java.lang.Number add(java.lang.Object num1,
                                         java.lang.Object num2)
Returns the sum of the two numbers or null if they're invalid.

Parameters:
num1 - The first number
num2 - The second number
Returns:
The sum of the two numbers or null if they're invalid
See Also:
org.apache.velocity.tools.generic.MathTool#add(java.lang.Object, java.lang.Object)

ceil

public static final java.lang.Integer ceil(java.lang.Object num)
Returns the smallest integer that is not less than the given number.

Parameters:
num - The number
Returns:
The smallest integer that is not less than the given number
See Also:
org.apache.velocity.tools.generic.MathTool#ceil(java.lang.Object)

div

public static final java.lang.Number div(java.lang.Object[] nums)
Returns the quotient of the numbers or null if they're invalid or if any denominator equals zero.

Parameters:
nums - The numbers to be divided
Returns:
The quotient of the numbers or null if they're invalid or if any denominator equals zero
See Also:
org.apache.velocity.tools.generic.MathTool#div(java.lang.Object...)

div

public static final java.lang.Number div(java.lang.Object num1,
                                         java.lang.Object num2)
Returns the quotient of the two numbers or null if they're invalid or if any denominator equals zero.

Parameters:
num1 - The first number
num2 - The second number
Returns:
The quotient of the two numbers or null if they're invalid or if any denominator equals zero
See Also:
org.apache.velocity.tools.generic.MathTool#div(java.lang.Object, java.lang.Object)

floor

public static final java.lang.Integer floor(java.lang.Object num)
Returns the integer portion of the number.

Parameters:
num - The number
Returns:
The integer portion of the number
See Also:
org.apache.velocity.tools.generic.MathTool#floor(java.lang.Object)

getAverage

public static final java.lang.Number getAverage(java.util.Collection<?> collection)
Gets the average of the values.

Parameters:
collection - A collection containing number values
Returns:
The average of the values in collection.
See Also:
org.apache.velocity.tools.generic.MathTool#getAverage(java.util.Collection)

getAverage

public static final java.lang.Number getAverage(java.util.Collection<?> collection,
                                                java.lang.String field)
Gets the average of the values from a list.

Parameters:
collection - A collection containing Java beans
field - A Java Bean field for the objects in collection that will return a number
Returns:
The average of the values in collection.
See Also:
org.apache.velocity.tools.generic.MathTool#getAverage(java.util.Collection, java.lang.String)

getAverage

public static final java.lang.Number getAverage(java.lang.Double[] values)
Gets the average of the values in an array of double values.

Parameters:
values - The list of double values
Returns:
The average of the array of values.
See Also:
org.apache.velocity.tools.generic.MathTool#getAverage(double...)

getAverage

public static final java.lang.Number getAverage(java.lang.Long[] values)
Gets the average of the values in an array of long values.

Parameters:
values - The list of long values
Returns:
The average of the array of values
See Also:
org.apache.velocity.tools.generic.MathTool#getAverage(long...)

getAverage

public static final java.lang.Number getAverage(java.lang.Object[] array)
Gets the average of the values.

Parameters:
array - An array containing number values
Returns:
The sum of the values in array.
See Also:
org.apache.velocity.tools.generic.MathTool#getAverage(java.lang.Object...)

getAverage

public static final java.lang.Number getAverage(java.lang.Object[] array,
                                                java.lang.String field)
Get the average of the values from a list.

Parameters:
array - A collection containing Java beans
field - A Java Bean field for the objects in array that will return a number
Returns:
The sum of the values in array
See Also:
org.apache.velocity.tools.generic.MathTool#getAverage(java.lang.Object[], java.lang.String)

getRandom

public static final java.lang.Double getRandom()
Returns a pseudo-random Double greater than or equal to 0.0 and less than 1.0.

Returns:
a pseudo-random Double greater than or equal to 0.0 and less than 1.0
See Also:
org.apache.velocity.tools.generic.MathTool#getRandom()

getTotal

public static final java.lang.Number getTotal(java.util.Collection<?> collection)
Gets the sum of the values.

Parameters:
collection - A collection containing numeric values
Returns:
The sum of the values in collection
See Also:
org.apache.velocity.tools.generic.MathTool#getTotal(java.util.Collection)

getTotal

public static final java.lang.Number getTotal(java.util.Collection<?> collection,
                                              java.lang.String field)
Gets the sum of the values from a list.

Parameters:
collection - A collection containing Java beans
field - A Java Bean field for the objects in collection that will return a number
Returns:
The sum of the values in collection
See Also:
org.apache.velocity.tools.generic.MathTool#getTotal(java.util.Collection, java.lang.String)

getTotal

public static final java.lang.Number getTotal(java.lang.Double[] values)
Gets the sum of the values.

Parameters:
values - The list of double values to add up
Returns:
The sum of the arrays
See Also:
org.apache.velocity.tools.generic.MathTool#getTotal(double...)

getTotal

public static final java.lang.Number getTotal(java.lang.Long[] values)
Gets the sum of the values.

Parameters:
values - The list of long values to add up
Returns:
The sum of the arrays
See Also:
org.apache.velocity.tools.generic.MathTool#getTotal(long...)

getTotal

public static final java.lang.Number getTotal(java.lang.Object[] array)
Gets the sum of the values.

Parameters:
array - An array containing number values
Returns:
The sum of the values in array
See Also:
org.apache.velocity.tools.generic.MathTool#getTotal(java.lang.Object...)

getTotal

public static final java.lang.Number getTotal(java.lang.Object[] array,
                                              java.lang.String field)
Gets the sum of the values from a list.

Parameters:
array - An array containing Java beans
field - A Java Bean field for the objects in array that will return a number
Returns:
The sum of the values in array
See Also:
org.apache.velocity.tools.generic.MathTool#getTotal(java.lang.Object[], java.lang.String)

idiv

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

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

Parameters:
num1 - The first number
num2 - The second number
Returns:
The result of performing integer division on the operands
See Also:
org.apache.velocity.tools.generic.MathTool#idiv(java.lang.Object, java.lang.Object)

max

public static final java.lang.Number max(java.lang.Object[] nums)
Returns the largest of the numbers or null if they're invalid.

Parameters:
nums - The numbers to be searched
Returns:
The largest of the numbers or null if they're invalid
See Also:
org.apache.velocity.tools.generic.MathTool#max(java.lang.Object...)

max

public static final java.lang.Number max(java.lang.Object num1,
                                         java.lang.Object num2)
Returns the largest of the two numbers or null if they're invalid.

Parameters:
num1 - The first number
num2 - The second number
Returns:
The largest of the two numbers or null if they're invalid
See Also:
org.apache.velocity.tools.generic.MathTool#max(java.lang.Object, java.lang.Object)

min

public static final java.lang.Number min(java.lang.Object[] nums)
Returns the smallest of the numbers or null if they're invalid.

Parameters:
nums - The numbers to be searched
Returns:
The smallest of the numbers or null if they're invalid
See Also:
org.apache.velocity.tools.generic.MathTool#min(java.lang.Object...)

min

public static final java.lang.Number min(java.lang.Object num1,
                                         java.lang.Object num2)
Returns the smallest of the numbers or null if they're invalid.

Parameters:
num1 - The first number
num2 - The second number
Returns:
The smallest of the numbers or null if they're invalid
See Also:
org.apache.velocity.tools.generic.MathTool#min(java.lang.Object, java.lang.Object)

mod

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

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

Parameters:
num1 - The first number
num2 - The second number
Returns:
The result of performing integer modulus on the operands
See Also:
org.apache.velocity.tools.generic.MathTool#mod(java.lang.Object, java.lang.Object)

mul

public static final java.lang.Number mul(java.lang.Object[] nums)
Returns the product of the numbers or null if they're invalid.

Parameters:
nums - The numbers to be multiplied
Returns:
The product of the numbers or null if they're invalid
See Also:
org.apache.velocity.tools.generic.MathTool#mul(java.lang.Object...)

mul

public static final java.lang.Number mul(java.lang.Object num1,
                                         java.lang.Object num2)
Returns the product of the two numbers or null if they're invalid.

Parameters:
num1 - The first number
num2 - The second number
Returns:
The product of the two numbers or null if they're invalid
See Also:
org.apache.velocity.tools.generic.MathTool#mul(java.lang.Object, java.lang.Object)

pow

public static final java.lang.Number pow(java.lang.Object num1,
                                         java.lang.Object num2)
Returns the first number raised to the power of the second or null if they're invalid.

Parameters:
num1 - The first number
num2 - The second number
Returns:
The first number raised to the power of the second or null if they're invalid
See Also:
org.apache.velocity.tools.generic.MathTool#pow(java.lang.Object, java.lang.Object)

random

public static final java.lang.Number random(java.lang.Object num1,
                                            java.lang.Object num2)
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
num2 - The second number
Returns:
a pseudo-random Number greater than or equal to the first number and less than the second
See Also:
org.apache.velocity.tools.generic.MathTool#random(java.lang.Object, java.lang.Object)

round

public static final java.lang.Integer round(java.lang.Object num)
Rounds a number to the nearest whole Integer.

Parameters:
num - The number to round
Returns:
The number rounded to the nearest whole Integer or null if it's invalid
See Also:
org.apache.velocity.tools.generic.MathTool#round(java.lang.Object)

roundTo

public static final java.lang.Double roundTo(java.lang.Object decimals,
                                             java.lang.Object num)
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 round(java.lang.Object), as that will return an Integer rather than a Double.

Parameters:
decimals - The number of decimal places
num - The number to round
Returns:
The value rounded to the specified number of decimal places or null if it's invalid
See Also:
org.apache.velocity.tools.generic.MathTool#roundTo(java.lang.Object, java.lang.Object)

sub

public static final java.lang.Number sub(java.lang.Object[] nums)
Returns the difference of the numbers (subtracted in order) or null if they're invalid.

Parameters:
nums - The numbers to be subtracted
Returns:
The difference of the numbers (subtracted in order) or null if they're invalid
See Also:
org.apache.velocity.tools.generic.MathTool#sub(java.lang.Object...)

sub

public static final java.lang.Number sub(java.lang.Object num1,
                                         java.lang.Object num2)
Returns the difference of the two numbers (subtracted in order) or null if they're invalid.

Parameters:
num1 - The first number
num2 - The second number
Returns:
The difference of the two numbers (subtracted in order) or null if they're invalid
See Also:
org.apache.velocity.tools.generic.MathTool#sub(java.lang.Object, java.lang.Object)

toDouble

public static final 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.

Parameters:
num - The number to be converted
Returns:
A Double representation of the number or null if it's invalid
See Also:
org.apache.velocity.tools.generic.MathTool#toDouble(java.lang.Object)

toInteger

public static final 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.

Parameters:
num - The number to be converted
Returns:
A Integer representation of the number or null if it's invalid
See Also:
org.apache.velocity.tools.generic.MathTool#toInteger(java.lang.Object)

toNumber

public static final 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. Note that this does not handle localized number formats. Use the StaticNumberTool to handle such conversions.

Parameters:
num - The number to be converted
Returns:
A Number representation of the number or null if it's invalid
See Also:
org.apache.velocity.tools.generic.MathTool#toNumber(java.lang.Object)


Copyright © 2009-2010 Logik Development. All Rights Reserved.