Class NumberFunction
- java.lang.Object
-
- org.jaxen.function.NumberFunction
-
- All Implemented Interfaces:
Function
public class NumberFunction extends java.lang.Object implements Function
4.4
number number(object)The number function converts its argument to a number as follows:
-
a string that consists of optional whitespace followed by an optional minus sign followed by a Number followed by whitespace is converted to the IEEE 754 number that is nearest (according to the IEEE 754 round-to-nearest rule) to the mathematical value represented by the string; any other string is converted to NaN
-
boolean true is converted to 1; boolean false is converted to 0
-
a node-set is first converted to a string as if by a call to the string function and then converted in the same way as a string argument
-
an object of a type other than the four basic types is converted to a number in a way that is dependent on that type
If the argument is omitted, it defaults to a node-set with the context node as its only member.
NOTE: The number function should not be used for conversion of numeric data occurring in an element in an XML document unless the element is of a type that represents numeric data in a language-neutral format (which would typically be transformed into a language-specific format for presentation to a user). In addition, the number function cannot be used unless the language-neutral format used by the element is consistent with the XPath syntax for a Number.
- Author:
- bob mcwhirter (bob @ werken.com)
- See Also:
- Section 4.4 of the XPath Specification
-
-
Constructor Summary
Constructors Constructor Description NumberFunction()Create a newNumberFunctionobject.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectcall(Context context, java.util.List args)Returns the number value ofargs.get(0), or the number value of the context node ifargsis empty.static java.lang.Doubleevaluate(java.lang.Object obj, Navigator nav)Returns the number value ofobj.static booleanisNaN(double val)Determines whether the argument is not a number (NaN) as defined by IEEE 754.static booleanisNaN(java.lang.Double val)Determines whether the argument is not a number (NaN) as defined by IEEE 754.
-
-
-
Method Detail
-
call
public java.lang.Object call(Context context, java.util.List args) throws FunctionCallException
Returns the number value ofargs.get(0), or the number value of the context node ifargsis empty.- Specified by:
callin interfaceFunction- Parameters:
context- the context at the point in the expression when the function is calledargs- a list containing the single item to be converted to aDouble- Returns:
- a
Double - Throws:
FunctionCallException- ifargshas more than one item
-
evaluate
public static java.lang.Double evaluate(java.lang.Object obj, Navigator nav)Returns the number value ofobj.- Parameters:
obj- the object to be converted to a numbernav- theNavigatorused to calculate the string-value of node-sets- Returns:
- a
Double
-
isNaN
public static boolean isNaN(double val)
Determines whether the argument is not a number (NaN) as defined by IEEE 754.- Parameters:
val- the double to test- Returns:
- true if the value is NaN, false otherwise
-
isNaN
public static boolean isNaN(java.lang.Double val)
Determines whether the argument is not a number (NaN) as defined by IEEE 754.- Parameters:
val- theDoubleto test- Returns:
- true if the value is NaN, false otherwise
-
-