com.novell.xml.xpath
Class NumberValue

java.lang.Object
  extended bycom.novell.xml.xpath.NumberValue
All Implemented Interfaces:
Comparable, Expression, ExpressionValue

public class NumberValue
extends Object
implements ExpressionValue, Expression, Comparable

Class to represent a number expression value


Field Summary
 
Fields inherited from interface com.novell.xml.xpath.ExpressionValue
BOOLEAN, EXTENDED, NATIVE, NODE_SET, NUMBER, STRING
 
Constructor Summary
NumberValue()
          Construct a default NumberValue for use in casting.
NumberValue(double v)
          Construct number value
 
Method Summary
 void castFrom(Object type)
          Convert from a different type of expression value to the NumberValue type This is used primarily for converting parameters for function calls.
 int compareTo(Object other)
          Compare this NumberValue to another Object.
static double convertToNumber(String string)
          Convert a string to a number, using the rules for the XPath number() function.
 void dump(PrintWriter writer)
          Output a human-readable form for the value
 void dump(PrintWriter writer, int indent)
          Print the expression in a readable form for debugging.
 boolean equals(Object other)
          Compares this object against the specified Object.
 ExpressionValue evaluate(Node contextNode, ExpressionContext context)
          Evaluate the expression with repect to the passed context
static Class getArgType()
          Return the Class object for objects of this type.
 boolean getBooleanValue()
          Return boolean value of expression value (will convert to boolean if value is not of type boolean)
 Object getNativeValue()
          return the underlying native value (java.lang.Boolean, java.lang.Double, etc.)
 NodeSet getNodeSetValue()
          Return node-set value of this ExpressionValue.
 double getNumberValue()
          Return numeric value of ExpressionValue.
 Class getResultType()
          Return the Class object describing the result type of the expression.
 String getStringValue()
          Return string value of this ExpressionValue.
static String getStringValue(double value)
          Return string value of a double according to XPath spec
 int getValueType()
          Return type of expression value
 int hashCode()
          Returns a hash code for the value in this NumberValue.
 boolean isConstant()
          Return true if the expression is a constant value.
 void registerForReset(XPathResetRegistrar registrar)
          Register this expression or any subexpression that implements XPathResetCache with an object that wants to call resetCache()
 String toString()
          Provide a readable description for debugging.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumberValue

public NumberValue(double v)
Construct number value

Parameters:
v -

NumberValue

public NumberValue()
Construct a default NumberValue for use in casting.

Method Detail

getArgType

public static Class getArgType()
Return the Class object for objects of this type. This is used for FunctionSignature objects.

Returns:
The Class object corresponding to NumberValue

toString

public String toString()
Provide a readable description for debugging.

Returns:
String representation

convertToNumber

public static double convertToNumber(String string)
Convert a string to a number, using the rules for the XPath number() function. The string may consist of optional whitespace, an optional '-' character, a Number production, and optional whitespace.

Parameters:
string - The string to convert.
Returns:
The numeric value of the string, or NaN if string doesn't match rules for Number()

evaluate

public ExpressionValue evaluate(Node contextNode,
                                ExpressionContext context)
Evaluate the expression with repect to the passed context

Specified by:
evaluate in interface Expression
Parameters:
contextNode - context node for expression evaluation
context - expression context for expression evaluation
Returns:
result of evaluating expression

isConstant

public boolean isConstant()
Return true if the expression is a constant value.

Specified by:
isConstant in interface Expression
Returns:
True is expression is constant, false otherwise.

getResultType

public Class getResultType()
Return the Class object describing the result type of the expression.

Specified by:
getResultType in interface Expression
Returns:
A Class object.

registerForReset

public void registerForReset(XPathResetRegistrar registrar)
Register this expression or any subexpression that implements XPathResetCache with an object that wants to call resetCache()

Specified by:
registerForReset in interface Expression

dump

public void dump(PrintWriter writer,
                 int indent)
Print the expression in a readable form for debugging.

Specified by:
dump in interface Expression
Parameters:
writer - The output device.
indent - Number of tabs to indent the result.

getValueType

public int getValueType()
Return type of expression value

Specified by:
getValueType in interface ExpressionValue
Returns:
ExpressionValue.BOOLEAN, ExpressionValue.NUMBER, etc.

castFrom

public void castFrom(Object type)
              throws XPathConversionException
Convert from a different type of expression value to the NumberValue type This is used primarily for converting parameters for function calls.

Specified by:
castFrom in interface ExpressionValue
Parameters:
type - The object to convert from.
Throws:
XPathConversionException

getBooleanValue

public boolean getBooleanValue()
                        throws XPathConversionException
Return boolean value of expression value (will convert to boolean if value is not of type boolean)

Specified by:
getBooleanValue in interface ExpressionValue
Returns:
true or false
Throws:
XPathConversionException

getNumberValue

public double getNumberValue()
                      throws XPathConversionException
Return numeric value of ExpressionValue. Will convert to a number if value is not of NUMBER type

Specified by:
getNumberValue in interface ExpressionValue
Returns:
numeric value
Throws:
XPathConversionException

getStringValue

public String getStringValue()
Return string value of this ExpressionValue. Will convert to a string if underlying type is not string.

Specified by:
getStringValue in interface ExpressionValue
Returns:
String value of ExpressionValue

getStringValue

public static String getStringValue(double value)
Return string value of a double according to XPath spec

Returns:
String value of passed double

getNodeSetValue

public NodeSet getNodeSetValue()
                        throws XPathConversionException
Return node-set value of this ExpressionValue. Will NOT convert an underlying type to a node-set.

Specified by:
getNodeSetValue in interface ExpressionValue
Throws:
XPathConversionException

getNativeValue

public Object getNativeValue()
return the underlying native value (java.lang.Boolean, java.lang.Double, etc.)

Specified by:
getNativeValue in interface ExpressionValue
Returns:
The native java class that is the value

dump

public void dump(PrintWriter writer)
Output a human-readable form for the value

Specified by:
dump in interface ExpressionValue
Parameters:
writer - Output device

hashCode

public int hashCode()
Returns a hash code for the value in this NumberValue. Uses the same algorithm as java.lang.Double.

Returns:
a hash code value for this object.

equals

public boolean equals(Object other)
Compares this object against the specified Object. This will return true if the other Object is a NumberValue or a java.lang.Double and the long values resulting from java.lang.Double.doubleToLongBits() are identical.

Parameters:
other - Object to which to compare
Returns:
true if objects are equal

compareTo

public int compareTo(Object other)
Compare this NumberValue to another Object. If the other Object is a NumberValue or a java.lang.Double then the comparison is valid, otherwise ClassCastException is thrown. Behaves like java.lang.Double.compareTo().

Specified by:
compareTo in interface Comparable
Parameters:
other - Object to which to compare
Returns:
zero, less-than-zero, greater-than-zero.