org.inria.ns.reflex.xml.operator
Class NumberOperator

java.lang.Object
  extended by org.inria.ns.reflex.xml.operator.AbstractXOperator
      extended by org.inria.ns.reflex.xml.operator.DefaultXOperator
          extended by org.inria.ns.reflex.xml.operator.NumberOperator
All Implemented Interfaces:
XOperator

public class NumberOperator
extends DefaultXOperator
implements XOperator

XML operations on numbers.

Only the static methods of this class are usable directly. To use the methods of the singleton, use the master operator that ensure the type of the arguments.

Author:
Philippe Poulard
See Also:
Number, XMaster

Method Summary
 boolean booleanValueOf(Object referent)
          This implementation returns the boolean value of the referent based on its string value.
 Map getAttributes(Object referent)
          Return the facets of this number.
 short getNodeType(Object referent)
          The referent behave like an XML text node.
 QName getTypeName(Object referent)
          Return #xs:number.
 Number numberValueOf(Object referent)
          This implementation returns the number value of the referent based on its string value.
static Number parseNumber(String number)
          Parse a number from the given string.
static Number parseNumber(String number, boolean isFloatingPoint)
          Parse a number from the given string.
static Number parseNumber(String number, boolean isFloatingPoint, Class numberClass)
          Parse a number from the given string.
static void register(XMaster xmaster)
          Registers this operator to the master operator.
 
Methods inherited from class org.inria.ns.reflex.xml.operator.DefaultXOperator
getChildren
 
Methods inherited from class org.inria.ns.reflex.xml.operator.AbstractXOperator
append, append, clear, clear, clearAll, clearAll, clone, clone, getAttributeValue, getCommentAt, getElementAt, getElementById, getElementsByName, getFamilyIndex, getFamilySize, getIndex, getNamedElementAt, getNamedProcessingInstructionAt, getNameIndex, getNameSize, getNamespaces, getNext, getNodeAt, getNodeKind, getParent, getPrevious, getProcessingInstructionAt, getQName, getRoot, getSize, getStringAttributeValue, getStringName, getTextAt, getType, getTypeIndex, getTypeSize, getValue, getXFactory, getXMLType, getXOperator, insertAfter, insertAfter, insertBefore, insertBefore, isAttribute, isComment, isDocument, isElement, isParentNode, isProcessingInstruction, isText, remove, remove, removeAttribute, rename, rename, replace, replace, setAttribute, stringValueOf, update, update, valueOf
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.inria.ns.reflex.xml.operator.XOperator
append, append, clear, clear, clearAll, clearAll, clone, clone, getAttributeValue, getChildren, getCommentAt, getElementAt, getElementById, getElementsByName, getFamilyIndex, getFamilySize, getIndex, getNamedElementAt, getNamedProcessingInstructionAt, getNameIndex, getNameSize, getNamespaces, getNext, getNodeAt, getNodeKind, getParent, getPrevious, getProcessingInstructionAt, getQName, getRoot, getSize, getStringAttributeValue, getStringName, getTextAt, getType, getTypeIndex, getTypeSize, getValue, getXFactory, getXMLType, insertAfter, insertAfter, insertBefore, insertBefore, isAttribute, isComment, isDocument, isElement, isParentNode, isProcessingInstruction, isText, remove, remove, removeAttribute, rename, rename, replace, replace, setAttribute, stringValueOf, update, update, valueOf
 

Method Detail

register

public static void register(XMaster xmaster)
Registers this operator to the master operator.

Parameters:
xmaster - The master operator.

numberValueOf

public Number numberValueOf(Object referent)
Description copied from class: AbstractXOperator
This implementation returns the number value of the referent based on its string value. May return an arbitrary-precision signed decimal number.

Specified by:
numberValueOf in interface XOperator
Overrides:
numberValueOf in class AbstractXOperator
Parameters:
referent - The referent.
Returns:
Its number value.
See Also:
AbstractXOperator.stringValueOf(Object), parseNumber(String)

booleanValueOf

public boolean booleanValueOf(Object referent)
Description copied from class: AbstractXOperator
This implementation returns the boolean value of the referent based on its string value.

Specified by:
booleanValueOf in interface XOperator
Overrides:
booleanValueOf in class AbstractXOperator
Parameters:
referent - The referent.
Returns:
Its boolean value.
See Also:
AbstractXOperator.stringValueOf(Object)

getNodeType

public short getNodeType(Object referent)
The referent behave like an XML text node.

Specified by:
getNodeType in interface XOperator
Overrides:
getNodeType in class DefaultXOperator
Parameters:
referent - The referent object.
Returns:
This implementation returns the text-node-type.
See Also:
XType.TEXT_NODE

getAttributes

public Map getAttributes(Object referent)
Return the facets of this number.

Specified by:
getAttributes in interface XOperator
Overrides:
getAttributes in class DefaultXOperator
Parameters:
referent - The number from which the facets will be extracted.
Returns:
The facets of this number.
See Also:
XOperator.getAttributes(Object)

getTypeName

public QName getTypeName(Object referent)
Return #xs:number.

Specified by:
getTypeName in interface XOperator
Overrides:
getTypeName in class DefaultXOperator
Parameters:
referent - A number.
Returns:
The name of the type.

parseNumber

public static Number parseNumber(String number)
Parse a number from the given string.

Parameters:
number - The number to parse ; all characters must be valid characters for the result number.
Returns:
A number, which class is the most suitable.
Throws:
NumberFormatException - When the string is not a number.
See Also:
Scanner.nextNumber(org.inria.ns.reflex.util.NumberConstraint)

parseNumber

public static Number parseNumber(String number,
                                 boolean isFloatingPoint)
Parse a number from the given string.

Parameters:
number - The number to parse ; all characters must be valid characters for the result number.
isFloatingPoint - false if the string doesn't represent a decimal number (with a dot or an exponent) ; true otherwise. If we don't know, true is acceptable, and if it appears that the number was an integer, getting the result will be a little more longer, but not so much. If false and the number do have fraction digits, they will be ignored.
Returns:
A number, which class is the most suitable.
Throws:
NumberFormatException - When the string is not a number.
See Also:
Scanner.nextNumber(org.inria.ns.reflex.util.NumberConstraint)

parseNumber

public static Number parseNumber(String number,
                                 boolean isFloatingPoint,
                                 Class numberClass)
Parse a number from the given string.

Parameters:
number - The number to parse ; all characters must be valid characters for the result number.
isFloatingPoint - false if the string doesn't represent a decimal number (with a dot or an exponent) ; true otherwise. If we don't know, true is acceptable, and if it appears that the number was an integer, getting the result will be a little more longer, but not so much. If false and the number do have fraction digits, they will be ignored. IN ANY CASE, if the numberClass is not null this value is useless.
numberClass - Used to enforce the number to be an instance of the class given. The class must implement Number and belong either to java.lang or to java.math. If null, the most suitable class will be returned.
Returns:
A number.
Throws:
NumberFormatException - When the string is not a number.
See Also:
Scanner.nextNumber(org.inria.ns.reflex.util.NumberConstraint)