org.inria.ns.reflex.util
Class NumberConstraint.Type

java.lang.Object
  extended by org.inria.ns.reflex.util.NumberConstraint.Type
All Implemented Interfaces:
Constraint, NumberConstraint
Enclosing interface:
NumberConstraint

public static class NumberConstraint.Type
extends Object
implements NumberConstraint

A constraint on numbers : after parsing the number, it will be of the type given.

Author:
Philippe Poulard

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.inria.ns.reflex.util.NumberConstraint
NumberConstraint.NumberClassConstraint, NumberConstraint.Type
 
Field Summary
 
Fields inherited from interface org.inria.ns.reflex.util.NumberConstraint
BYTE_CONSTRAINT, DECIMAL_CONSTRAINT, DOUBLE_CONSTRAINT, FLOAT_CONSTRAINT, INT_CONSTRAINT, INTEGER_CONSTRAINT, LONG_CONSTRAINT, MAX_BYTE, MAX_INTEGER, MAX_LONG, MAX_SHORT, MIN_BYTE, MIN_INTEGER, MIN_LONG, MIN_SHORT, NO_CONSTRAINT, SHORT_CONSTRAINT
 
Constructor Summary
NumberConstraint.Type(Class numberClass)
           
 
Method Summary
 Class getNumberType()
          Return the type of the number.
 boolean stopCondition(StringBuffer buf, int sourceIndex, int dotIndex, int exponentIndex, Scanner scanner)
          No stop condition here : the string supplied must be of the type expected.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberConstraint.Type

public NumberConstraint.Type(Class numberClass)
Parameters:
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.
Method Detail

getNumberType

public Class getNumberType()
Return the type of the number.

Specified by:
getNumberType in interface NumberConstraint
Returns:
The type of the number, or null if the type have to be the more suitable.

stopCondition

public boolean stopCondition(StringBuffer buf,
                             int sourceIndex,
                             int dotIndex,
                             int exponentIndex,
                             Scanner scanner)
                      throws IOException
No stop condition here : the string supplied must be of the type expected.

Specified by:
stopCondition in interface NumberConstraint
Parameters:
buf - The buffer that receive the input characters so far. It can be used by this method to evaluate the stop condition. For example if negative numbers are not allowed, the first character of the buffer can't be "-".
sourceIndex - The number of characters read so far ; might be useful in certain stop conditions.
dotIndex - The index where the dot character was encountered, or -1 if not found so far.
exponentIndex - The index where the exponent character was encountered, or -1 if not found so far.
scanner - The scanner that reads the input. According to the parsing strategy, if the sequence of characters involved in the stop condition (if any) don't have to be consumed, the relevant methods of the scanner should be involved.
Returns:
false
Throws:
IOException - When the scanner cause an error.