org.codehaus.jackson.impl
Class JsonNumericParserBase

java.lang.Object
  extended by org.codehaus.jackson.JsonParser
      extended by org.codehaus.jackson.impl.JsonParserMinimalBase
          extended by org.codehaus.jackson.impl.JsonParserBase
              extended by org.codehaus.jackson.impl.JsonNumericParserBase
All Implemented Interfaces:
Closeable, Versioned
Direct Known Subclasses:
ReaderBasedParserBase, StreamBasedParserBase

public abstract class JsonNumericParserBase
extends JsonParserBase

Another intermediate base class used by all Jackson JsonParser implementations. Contains shared functionality for dealing with number parsing aspects, independent of input source decoding.

Author:
Tatu Saloranta

Nested Class Summary
 
Nested classes/interfaces inherited from class org.codehaus.jackson.JsonParser
JsonParser.Feature, JsonParser.NumberType
 
Field Summary
protected  BigDecimal _numberBigDecimal
           
protected  BigInteger _numberBigInt
           
protected  double _numberDouble
           
protected  int _numberInt
           
protected  long _numberLong
           
protected  boolean _numberNegative
          Flag that indicates whether numeric value has a negative value.
protected  int _numTypesValid
          Bitfield that indicates which numeric representations have been calculated for the current type
protected static char CHAR_NULL
           
protected static int INT_0
           
protected static int INT_1
           
protected static int INT_2
           
protected static int INT_3
           
protected static int INT_4
           
protected static int INT_5
           
protected static int INT_6
           
protected static int INT_7
           
protected static int INT_8
           
protected static int INT_9
           
protected static int INT_DECIMAL_POINT
           
protected static int INT_e
           
protected static int INT_E
           
protected static int INT_MINUS
           
protected static int INT_PLUS
           
protected  int mExpLength
          Length of the exponent part of the number, if any, not including 'e' marker or sign, just digits.
protected  int mFractLength
          Length of the fractional part (not including decimal point or exponent), in characters.
protected  int mIntLength
          Length of integer part of the number, in characters
protected static int NR_BIGDECIMAL
           
protected static int NR_BIGINT
           
protected static int NR_DOUBLE
           
protected static int NR_INT
           
protected static int NR_LONG
           
protected static int NR_UNKNOWN
           
 
Fields inherited from class org.codehaus.jackson.impl.JsonParserBase
_binaryValue, _byteArrayBuilder, _closed, _currInputProcessed, _currInputRow, _currInputRowStart, _inputEnd, _inputPtr, _ioContext, _nameCopied, _nameCopyBuffer, _nextToken, _parsingContext, _textBuffer, _tokenIncomplete, _tokenInputCol, _tokenInputRow, _tokenInputTotal
 
Fields inherited from class org.codehaus.jackson.impl.JsonParserMinimalBase
INT_APOSTROPHE, INT_ASTERISK, INT_b, INT_BACKSLASH, INT_COLON, INT_COMMA, INT_CR, INT_f, INT_LBRACKET, INT_LCURLY, INT_LF, INT_n, INT_QUOTE, INT_r, INT_RBRACKET, INT_RCURLY, INT_SLASH, INT_SPACE, INT_t, INT_TAB, INT_u
 
Fields inherited from class org.codehaus.jackson.JsonParser
_currToken, _features, _lastClearedToken
 
Constructor Summary
protected JsonNumericParserBase(IOContext ctxt, int features)
           
 
Method Summary
protected  void _parseNumericValue(int expType)
          Method that will parse actual numeric value out of a syntactically valid number value.
protected  void convertNumberToBigDecimal()
           
protected  void convertNumberToBigInteger()
           
protected  void convertNumberToDouble()
           
protected  void convertNumberToInt()
           
protected  void convertNumberToLong()
           
 BigInteger getBigIntegerValue()
          Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can not be used as a Java long primitive type due to its magnitude.
 BigDecimal getDecimalValue()
          Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_FLOAT or JsonToken.VALUE_NUMBER_INT.
 double getDoubleValue()
          Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_FLOAT and it can be expressed as a Java double primitive type.
 float getFloatValue()
          Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_FLOAT and it can be expressed as a Java float primitive type.
 int getIntValue()
          Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a value of Java int primitive type.
 long getLongValue()
          Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a Java long primitive type.
 JsonParser.NumberType getNumberType()
          If current token is of type JsonToken.VALUE_NUMBER_INT or JsonToken.VALUE_NUMBER_FLOAT, returns one of JsonParser.NumberType constants; otherwise returns null.
 Number getNumberValue()
          Generic number value accessor method that will work for all kinds of numeric values.
protected  void reportInvalidNumber(String msg)
           
protected  void reportOverflowInt()
           
protected  void reportOverflowLong()
           
protected  void reportUnexpectedNumberChar(int ch, String comment)
           
protected  JsonToken reset(boolean negative, int intLen, int fractLen, int expLen)
           
 
Methods inherited from class org.codehaus.jackson.impl.JsonParserBase
_closeInput, _decodeBase64, _finishString, _getByteArrayBuilder, _handleEOF, _releaseBuffers, _reportMismatchedEndMarker, close, getBinaryValue, getCurrentLocation, getCurrentName, getParsingContext, getText, getTextCharacters, getTextLength, getTextOffset, getTokenCharacterOffset, getTokenColumnNr, getTokenLineNr, getTokenLocation, hasTextCharacters, isClosed, loadMore, loadMoreGuaranteed, version
 
Methods inherited from class org.codehaus.jackson.impl.JsonParserMinimalBase
_constructError, _getCharDesc, _handleUnrecognizedCharacterEscape, _reportError, _reportInvalidEOF, _reportInvalidEOF, _reportUnexpectedChar, _throwInternal, _throwInvalidSpace, _throwUnquotedSpace, _wrapError, getValueAsDouble, getValueAsInt, getValueAsLong, nextToken, skipChildren
 
Methods inherited from class org.codehaus.jackson.JsonParser
_constructError, clearCurrentToken, configure, disable, disableFeature, enable, enableFeature, getBinaryValue, getBooleanValue, getByteValue, getCodec, getCurrentToken, getEmbeddedObject, getLastClearedToken, getShortValue, getValueAsDouble, getValueAsInt, getValueAsLong, hasCurrentToken, isEnabled, isFeatureEnabled, nextValue, readValueAs, readValueAs, readValueAsTree, releaseBuffered, releaseBuffered, setCodec, setFeature
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NR_UNKNOWN

protected static final int NR_UNKNOWN
See Also:
Constant Field Values

NR_INT

protected static final int NR_INT
See Also:
Constant Field Values

NR_LONG

protected static final int NR_LONG
See Also:
Constant Field Values

NR_BIGINT

protected static final int NR_BIGINT
See Also:
Constant Field Values

NR_DOUBLE

protected static final int NR_DOUBLE
See Also:
Constant Field Values

NR_BIGDECIMAL

protected static final int NR_BIGDECIMAL
See Also:
Constant Field Values

INT_0

protected static final int INT_0
See Also:
Constant Field Values

INT_1

protected static final int INT_1
See Also:
Constant Field Values

INT_2

protected static final int INT_2
See Also:
Constant Field Values

INT_3

protected static final int INT_3
See Also:
Constant Field Values

INT_4

protected static final int INT_4
See Also:
Constant Field Values

INT_5

protected static final int INT_5
See Also:
Constant Field Values

INT_6

protected static final int INT_6
See Also:
Constant Field Values

INT_7

protected static final int INT_7
See Also:
Constant Field Values

INT_8

protected static final int INT_8
See Also:
Constant Field Values

INT_9

protected static final int INT_9
See Also:
Constant Field Values

INT_MINUS

protected static final int INT_MINUS
See Also:
Constant Field Values

INT_PLUS

protected static final int INT_PLUS
See Also:
Constant Field Values

INT_DECIMAL_POINT

protected static final int INT_DECIMAL_POINT
See Also:
Constant Field Values

INT_e

protected static final int INT_e
See Also:
Constant Field Values

INT_E

protected static final int INT_E
See Also:
Constant Field Values

CHAR_NULL

protected static final char CHAR_NULL
See Also:
Constant Field Values

_numTypesValid

protected int _numTypesValid
Bitfield that indicates which numeric representations have been calculated for the current type


_numberInt

protected int _numberInt

_numberLong

protected long _numberLong

_numberDouble

protected double _numberDouble

_numberBigInt

protected BigInteger _numberBigInt

_numberBigDecimal

protected BigDecimal _numberBigDecimal

_numberNegative

protected boolean _numberNegative
Flag that indicates whether numeric value has a negative value. That is, whether its textual representation starts with minus character.


mIntLength

protected int mIntLength
Length of integer part of the number, in characters


mFractLength

protected int mFractLength
Length of the fractional part (not including decimal point or exponent), in characters. Not used for pure integer values.


mExpLength

protected int mExpLength
Length of the exponent part of the number, if any, not including 'e' marker or sign, just digits. Not used for pure integer values.

Constructor Detail

JsonNumericParserBase

protected JsonNumericParserBase(IOContext ctxt,
                                int features)
Method Detail

reset

protected final JsonToken reset(boolean negative,
                                int intLen,
                                int fractLen,
                                int expLen)

getNumberValue

public Number getNumberValue()
                      throws IOException,
                             JsonParseException
Description copied from class: JsonParser
Generic number value accessor method that will work for all kinds of numeric values. It will return the optimal (simplest/smallest possible) wrapper object that can express the numeric value just parsed.

Specified by:
getNumberValue in class JsonParser
Throws:
IOException
JsonParseException

getNumberType

public JsonParser.NumberType getNumberType()
                                    throws IOException,
                                           JsonParseException
Description copied from class: JsonParser
If current token is of type JsonToken.VALUE_NUMBER_INT or JsonToken.VALUE_NUMBER_FLOAT, returns one of JsonParser.NumberType constants; otherwise returns null.

Specified by:
getNumberType in class JsonParser
Throws:
IOException
JsonParseException

getIntValue

public int getIntValue()
                throws IOException,
                       JsonParseException
Description copied from class: JsonParser
Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a value of Java int primitive type. It can also be called for JsonToken.VALUE_NUMBER_FLOAT; if so, it is equivalent to calling JsonParser.getDoubleValue() and then casting; except for possible overflow/underflow exception.

Note: if the resulting integer value falls outside range of Java int, a JsonParseException may be thrown to indicate numeric overflow/underflow.

Specified by:
getIntValue in class JsonParser
Throws:
IOException
JsonParseException

getLongValue

public long getLongValue()
                  throws IOException,
                         JsonParseException
Description copied from class: JsonParser
Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a Java long primitive type. It can also be called for JsonToken.VALUE_NUMBER_FLOAT; if so, it is equivalent to calling JsonParser.getDoubleValue() and then casting to int; except for possible overflow/underflow exception.

Note: if the token is an integer, but its value falls outside of range of Java long, a JsonParseException may be thrown to indicate numeric overflow/underflow.

Specified by:
getLongValue in class JsonParser
Throws:
IOException
JsonParseException

getBigIntegerValue

public BigInteger getBigIntegerValue()
                              throws IOException,
                                     JsonParseException
Description copied from class: JsonParser
Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can not be used as a Java long primitive type due to its magnitude. It can also be called for JsonToken.VALUE_NUMBER_FLOAT; if so, it is equivalent to calling JsonParser.getDecimalValue() and then constructing a BigInteger from that value.

Specified by:
getBigIntegerValue in class JsonParser
Throws:
IOException
JsonParseException

getFloatValue

public float getFloatValue()
                    throws IOException,
                           JsonParseException
Description copied from class: JsonParser
Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_FLOAT and it can be expressed as a Java float primitive type. It can also be called for JsonToken.VALUE_NUMBER_INT; if so, it is equivalent to calling JsonParser.getLongValue() and then casting; except for possible overflow/underflow exception.

Note: if the value falls outside of range of Java float, a JsonParseException will be thrown to indicate numeric overflow/underflow.

Specified by:
getFloatValue in class JsonParser
Throws:
IOException
JsonParseException

getDoubleValue

public double getDoubleValue()
                      throws IOException,
                             JsonParseException
Description copied from class: JsonParser
Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_FLOAT and it can be expressed as a Java double primitive type. It can also be called for JsonToken.VALUE_NUMBER_INT; if so, it is equivalent to calling JsonParser.getLongValue() and then casting; except for possible overflow/underflow exception.

Note: if the value falls outside of range of Java double, a JsonParseException will be thrown to indicate numeric overflow/underflow.

Specified by:
getDoubleValue in class JsonParser
Throws:
IOException
JsonParseException

getDecimalValue

public BigDecimal getDecimalValue()
                           throws IOException,
                                  JsonParseException
Description copied from class: JsonParser
Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_FLOAT or JsonToken.VALUE_NUMBER_INT. No under/overflow exceptions are ever thrown.

Specified by:
getDecimalValue in class JsonParser
Throws:
IOException
JsonParseException

_parseNumericValue

protected void _parseNumericValue(int expType)
                           throws IOException,
                                  JsonParseException
Method that will parse actual numeric value out of a syntactically valid number value. Type it will parse into depends on whether it is a floating point number, as well as its magnitude: smallest legal type (of ones available) is used for efficiency.

Parameters:
expType - Numeric type that we will immediately need, if any; mostly necessary to optimize handling of floating point numbers
Throws:
IOException
JsonParseException

convertNumberToInt

protected void convertNumberToInt()
                           throws IOException,
                                  JsonParseException
Throws:
IOException
JsonParseException

convertNumberToLong

protected void convertNumberToLong()
                            throws IOException,
                                   JsonParseException
Throws:
IOException
JsonParseException

convertNumberToBigInteger

protected void convertNumberToBigInteger()
                                  throws IOException,
                                         JsonParseException
Throws:
IOException
JsonParseException

convertNumberToDouble

protected void convertNumberToDouble()
                              throws IOException,
                                     JsonParseException
Throws:
IOException
JsonParseException

convertNumberToBigDecimal

protected void convertNumberToBigDecimal()
                                  throws IOException,
                                         JsonParseException
Throws:
IOException
JsonParseException

reportUnexpectedNumberChar

protected void reportUnexpectedNumberChar(int ch,
                                          String comment)
                                   throws JsonParseException
Throws:
JsonParseException

reportInvalidNumber

protected void reportInvalidNumber(String msg)
                            throws JsonParseException
Throws:
JsonParseException

reportOverflowInt

protected void reportOverflowInt()
                          throws IOException,
                                 JsonParseException
Throws:
IOException
JsonParseException

reportOverflowLong

protected void reportOverflowLong()
                           throws IOException,
                                  JsonParseException
Throws:
IOException
JsonParseException