org.inria.ns.reflex.util
Interface NumberConstraint

All Superinterfaces:
Constraint
All Known Implementing Classes:
NumberConstraint.NumberClassConstraint, NumberConstraint.Type

public interface NumberConstraint
extends Constraint

A number constraint is used by scanners to read numbers under conditions, such as limiting the number of total digits to read, or accepting negative numbers, forcing a number to be an integer, etc.

Author:
Philippe Poulard

Nested Class Summary
static class NumberConstraint.NumberClassConstraint
          Base class for checking constraints on number types.
static class NumberConstraint.Type
          A constraint on numbers : after parsing the number, it will be of the type given.
 
Field Summary
static NumberConstraint BYTE_CONSTRAINT
          A constraint for parsing bytes.
static NumberConstraint DECIMAL_CONSTRAINT
          A constraint for parsing decimal.
static NumberConstraint DOUBLE_CONSTRAINT
          A constraint for parsing a double.
static NumberConstraint FLOAT_CONSTRAINT
          A constraint for parsing a float.
static NumberConstraint INT_CONSTRAINT
          A constraint for parsing integers.
static NumberConstraint INTEGER_CONSTRAINT
          A constraint for parsing integers.
static NumberConstraint LONG_CONSTRAINT
          A constraint for parsing longs.
static String MAX_BYTE
           
static String MAX_INTEGER
           
static String MAX_LONG
           
static String MAX_SHORT
           
static String MIN_BYTE
           
static String MIN_INTEGER
           
static String MIN_LONG
           
static String MIN_SHORT
           
static NumberConstraint NO_CONSTRAINT
          When there is no constraint, there is no stop condition (that always return true).
static NumberConstraint SHORT_CONSTRAINT
          A constraint for parsing shorts.
 
Method Summary
 Class getNumberType()
          Enforce a number to be of a specific type.
 boolean stopCondition(StringBuffer buf, int sourceIndex, int dotIndex, int exponentIndex, Scanner scanner)
          Evaluate the stop condition from the given parameters.
 

Field Detail

NO_CONSTRAINT

static final NumberConstraint NO_CONSTRAINT
When there is no constraint, there is no stop condition (that always return true).

A number under no constraint is parsed until a character is unexpected in the input sequence.


BYTE_CONSTRAINT

static final NumberConstraint BYTE_CONSTRAINT
A constraint for parsing bytes. The constraint is applied while parsing.

See Also:
Byte.MAX_VALUE, Byte.MIN_VALUE

SHORT_CONSTRAINT

static final NumberConstraint SHORT_CONSTRAINT
A constraint for parsing shorts. The constraint is applied while parsing.

See Also:
Short.MAX_VALUE, Short.MIN_VALUE

INT_CONSTRAINT

static final NumberConstraint INT_CONSTRAINT
A constraint for parsing integers. The constraint is applied while parsing.

See Also:
Integer.MAX_VALUE, Integer.MIN_VALUE

INTEGER_CONSTRAINT

static final NumberConstraint INTEGER_CONSTRAINT
A constraint for parsing integers. The constraint is applied while parsing.

See Also:
BigInteger

LONG_CONSTRAINT

static final NumberConstraint LONG_CONSTRAINT
A constraint for parsing longs. The constraint is applied while parsing.

See Also:
Long.MAX_VALUE, Long.MIN_VALUE

DECIMAL_CONSTRAINT

static final NumberConstraint DECIMAL_CONSTRAINT
A constraint for parsing decimal. A decimal doesn't accept an exponent. The constraint is applied while parsing.

See Also:
BigDecimal

DOUBLE_CONSTRAINT

static final NumberConstraint DOUBLE_CONSTRAINT
A constraint for parsing a double. The constraint is NOT applied while parsing.

See Also:
Double

FLOAT_CONSTRAINT

static final NumberConstraint FLOAT_CONSTRAINT
A constraint for parsing a float. The constraint is NOT applied while parsing.

See Also:
Float

MIN_BYTE

static final String MIN_BYTE
See Also:
Constant Field Values

MAX_BYTE

static final String MAX_BYTE
See Also:
Constant Field Values

MIN_SHORT

static final String MIN_SHORT
See Also:
Constant Field Values

MAX_SHORT

static final String MAX_SHORT
See Also:
Constant Field Values

MIN_INTEGER

static final String MIN_INTEGER
See Also:
Constant Field Values

MAX_INTEGER

static final String MAX_INTEGER
See Also:
Constant Field Values

MIN_LONG

static final String MIN_LONG
See Also:
Constant Field Values

MAX_LONG

static final String MAX_LONG
See Also:
Constant Field Values
Method Detail

stopCondition

boolean stopCondition(StringBuffer buf,
                      int sourceIndex,
                      int dotIndex,
                      int exponentIndex,
                      Scanner scanner)
                      throws IOException
Evaluate the stop condition from the given parameters.

This condition is evaluated by the scanner to check if it has to append characters to the current buffer.

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:
true to indicate that the current scan must stop, false if more characters have to be read.
Throws:
IOException - When the scanner cause an error.

getNumberType

Class getNumberType()
Enforce a number to be of a specific type.

Returns:
The type of the number, or null if the type have to be the more suitable.