• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java NumberInput类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.fasterxml.jackson.core.io.NumberInput的典型用法代码示例。如果您正苦于以下问题:Java NumberInput类的具体用法?Java NumberInput怎么用?Java NumberInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NumberInput类属于com.fasterxml.jackson.core.io包,在下文中一共展示了NumberInput类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: _parseSlowInt

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
private void _parseSlowInt(int expType) throws IOException
{
    String numStr = _textBuffer.contentsAsString();
    try {
        int len = _intLength;
        char[] buf = _textBuffer.getTextBuffer();
        int offset = _textBuffer.getTextOffset();
        if (_numberNegative) {
            ++offset;
        }
        // Some long cases still...
        if (NumberInput.inLongRange(buf, offset, len, _numberNegative)) {
            // Probably faster to construct a String, call parse, than to use BigInteger
            _numberLong = Long.parseLong(numStr);
            _numTypesValid = NR_LONG;
        } else {
            // nope, need the heavy guns... (rare case)
            _numberBigInt = new BigInteger(numStr);
            _numTypesValid = NR_BIGINT;
        }
    } catch (NumberFormatException nex) {
        // Can this ever occur? Due to overflow, maybe?
        _wrapError("Malformed numeric value '"+numStr+"'", nex);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ParserBase.java


示例2: contentsAsDecimal

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
/**
 * Convenience method for converting contents of the buffer
 * into a {@link BigDecimal}.
 */
public BigDecimal contentsAsDecimal() throws NumberFormatException
{
    // Already got a pre-cut array?
    if (_resultArray != null) {
        return NumberInput.parseBigDecimal(_resultArray);
    }
    // Or a shared buffer?
    if ((_inputStart >= 0) && (_inputBuffer != null)) {
        return NumberInput.parseBigDecimal(_inputBuffer, _inputStart, _inputLen);
    }
    // Or if not, just a single buffer (the usual case)
    if ((_segmentSize == 0) && (_currentSegment != null)) {
        return NumberInput.parseBigDecimal(_currentSegment, 0, _currentSize);
    }
    // If not, let's just get it aggregated...
    return NumberInput.parseBigDecimal(contentsAsArray());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:TextBuffer.java


示例3: testIntParsing

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
public void testIntParsing() throws Exception
{
    char[] testChars = "123456789".toCharArray();

    assertEquals(3, NumberInput.parseInt(testChars, 2, 1));
    assertEquals(123, NumberInput.parseInt(testChars, 0, 3));
    assertEquals(2345, NumberInput.parseInt(testChars, 1, 4));
    assertEquals(9, NumberInput.parseInt(testChars, 8, 1));
    assertEquals(456789, NumberInput.parseInt(testChars, 3, 6));
    assertEquals(23456, NumberInput.parseInt(testChars, 1, 5));
    assertEquals(123456789, NumberInput.parseInt(testChars, 0, 9));

    testChars = "32".toCharArray();
    assertEquals(32, NumberInput.parseInt(testChars, 0, 2));
    testChars = "189".toCharArray();
    assertEquals(189, NumberInput.parseInt(testChars, 0, 3));

    testChars = "10".toCharArray();
    assertEquals(10, NumberInput.parseInt(testChars, 0, 2));
    assertEquals(0, NumberInput.parseInt(testChars, 1, 1));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:TestNumberParsing.java


示例4: testLongBoundsChecks

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
public void testLongBoundsChecks() throws Exception
{
    String minLong = String.valueOf(Long.MIN_VALUE).substring(1);
    String maxLong = String.valueOf(Long.MAX_VALUE);
    final String VALUE_491 = "1323372036854775807"; // is within range (JACKSON-491)
    final String OVERFLOW =  "9999999999999999999"; // and this one is clearly out

    assertTrue(NumberInput.inLongRange(minLong, true));
    assertTrue(NumberInput.inLongRange(maxLong, false));
    assertTrue(NumberInput.inLongRange(VALUE_491, true));
    assertTrue(NumberInput.inLongRange(VALUE_491, false));
    assertFalse(NumberInput.inLongRange(OVERFLOW, false));
    assertFalse(NumberInput.inLongRange(OVERFLOW, true));

    char[] cbuf = minLong.toCharArray();
    assertTrue(NumberInput.inLongRange(cbuf, 0, cbuf.length, true));
    cbuf = maxLong.toCharArray();
    assertTrue(NumberInput.inLongRange(cbuf, 0, cbuf.length, false));
    cbuf = VALUE_491.toCharArray();
    assertTrue(NumberInput.inLongRange(cbuf, 0, cbuf.length, true));
    assertTrue(NumberInput.inLongRange(cbuf, 0, cbuf.length, false));
    cbuf = OVERFLOW.toCharArray();
    assertFalse(NumberInput.inLongRange(cbuf, 0, cbuf.length, true));
    assertFalse(NumberInput.inLongRange(cbuf, 0, cbuf.length, false));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:TestNumberParsing.java


示例5: parse

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
public Date parse(String paramString, ParsePosition paramParsePosition)
{
  if (looksLikeISO8601(paramString))
    return parseAsISO8601(paramString, paramParsePosition);
  int i = paramString.length();
  int j;
  do
  {
    i--;
    if (i < 0)
      break;
    j = paramString.charAt(i);
  }
  while (((j < 48) || (j > 57)) && ((i <= 0) && (j == 45)));
  if ((i < 0) && (NumberInput.inLongRange(paramString, false)))
    return new Date(Long.parseLong(paramString));
  return parseAsRFC1123(paramString, paramParsePosition);
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:19,代码来源:StdDateFormat.java


示例6: _parseSlowInt

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
private void _parseSlowInt(int expType, char[] buf, int offset, int len)
    throws IOException, JsonParseException
{
    String numStr = _textBuffer.contentsAsString();
    try {
        // [JACKSON-230] Some long cases still...
        if (NumberInput.inLongRange(buf, offset, len, _numberNegative)) {
            // Probably faster to construct a String, call parse, than to use BigInteger
            _numberLong = Long.parseLong(numStr);
            _numTypesValid = NR_LONG;
        } else {
            // nope, need the heavy guns... (rare case)
            _numberBigInt = new BigInteger(numStr);
            _numTypesValid = NR_BIGINT;
        }
    } catch (NumberFormatException nex) {
        // Can this ever occur? Due to overflow, maybe?
        _wrapError("Malformed numeric value '"+numStr+"'", nex);
    }
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:21,代码来源:ParserBase.java


示例7: convertNumberToBigDecimal

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
protected void convertNumberToBigDecimal()
    throws IOException, JsonParseException
{
    /* 05-Aug-2008, tatus: Important note: this MUST start with
     *   more accurate representations, since we don't know which
     *   value is the original one (others get generated when
     *   requested)
     */

    if ((_numTypesValid & NR_DOUBLE) != 0) {
        /* Let's actually parse from String representation,
         * to avoid rounding errors that non-decimal floating operations
         * would incur
         */
        _numberBigDecimal = NumberInput.parseBigDecimal(getText());
    } else if ((_numTypesValid & NR_BIGINT) != 0) {
        _numberBigDecimal = new BigDecimal(_numberBigInt);
    } else if ((_numTypesValid & NR_LONG) != 0) {
        _numberBigDecimal = BigDecimal.valueOf(_numberLong);
    } else if ((_numTypesValid & NR_INT) != 0) {
        _numberBigDecimal = BigDecimal.valueOf(_numberInt);
    } else {
        _throwInternal();
    }
    _numTypesValid |= NR_BIGDECIMAL;
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:27,代码来源:ParserBase.java


示例8: _parseSlowIntValue

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
private void _parseSlowIntValue(int expType, char[] buf, int offset, int len)
    throws IOException, JsonParseException
{
    String numStr = _textBuffer.contentsAsString();
    try {
        // [JACKSON-230] Some long cases still...
        if (NumberInput.inLongRange(buf, offset, len, _numberNegative)) {
            // Probably faster to construct a String, call parse, than to use BigInteger
            _numberLong = Long.parseLong(numStr);
            _numTypesValid = NR_LONG;
        } else {
            // nope, need the heavy guns... (rare case)
            _numberBigInt = new BigInteger(numStr);
            _numTypesValid = NR_BIGINT;
        }
    } catch (NumberFormatException nex) {
        // Can this ever occur? Due to overflow, maybe?
        _wrapError("Malformed numeric value '"+numStr+"'", nex);
    }
}
 
开发者ID:kbase,项目名称:cmonkey,代码行数:21,代码来源:KBaseJsonParser.java


示例9: rangeCheckedLong

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
private Long rangeCheckedLong(JsonParser parser, DeserializationContext context)
throws IOException {
    String text = parser.getText().trim();
    if (text.length() == 0) {
        return null;
    }
    try {
        return Long.valueOf(NumberInput.parseLong(text));
    }
    catch (Exception e) {
        throw context.weirdStringException(//NOSONAR
            _valueClass,
            "Over/underflow: numeric value (" + text +") out of range of Long ("
                + Long.MIN_VALUE + " to " + Long.MAX_VALUE + ")"
        );
    }
}
 
开发者ID:betfair,项目名称:cougar,代码行数:18,代码来源:JSONBindingFactory.java


示例10: _parseLongPrimitive

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
protected final long _parseLongPrimitive(JsonParser jp, DeserializationContext ctxt)
    throws IOException, JsonProcessingException
{
    JsonToken t = jp.getCurrentToken();
    if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) {
        return jp.getLongValue();
    }
    if (t == JsonToken.VALUE_STRING) {
        String text = jp.getText().trim();
        if (text.length() == 0) {
            return 0L;
        }
        try {
            return NumberInput.parseLong(text);
        } catch (IllegalArgumentException iae) { }
        throw ctxt.weirdStringException(text, _valueClass, "not a valid long value");
    }
    if (t == JsonToken.VALUE_NULL) {
        return 0L;
    }
    throw ctxt.mappingException(_valueClass, t);
}
 
开发者ID:joyplus,项目名称:joyplus-tv,代码行数:23,代码来源:StdDeserializer.java


示例11: parse

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
@Override
public Date parse(String dateStr, ParsePosition pos)
{
    if (looksLikeISO8601(dateStr)) { // also includes "plain"
        return parseAsISO8601(dateStr, pos);
    }
    /* 14-Feb-2010, tatu: As per [JACKSON-236], better also
     *   consider "stringified" simple time stamp
     */
    int i = dateStr.length();
    while (--i >= 0) {
        char ch = dateStr.charAt(i);
        if (ch < '0' || ch > '9') break;
    }
    if (i < 0) { // all digits
        if (NumberInput.inLongRange(dateStr, false)) {
            return new Date(Long.parseLong(dateStr));
        }
    }
    // Otherwise, fall back to using RFC 1123
    return parseAsRFC1123(dateStr, pos);
}
 
开发者ID:joyplus,项目名称:joyplus-tv,代码行数:23,代码来源:StdDateFormat.java


示例12: getValueAsInt

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
@Override
public int getValueAsInt(int defaultValue) throws IOException, JsonParseException
{
    if (_currToken != null) {
        switch (_currToken) {
        case VALUE_NUMBER_INT:
        case VALUE_NUMBER_FLOAT:
            return getIntValue();
        case VALUE_TRUE:
            return 1;
        case VALUE_FALSE:
        case VALUE_NULL:
            return 0;
        case VALUE_STRING:
            return NumberInput.parseAsInt(getText(), defaultValue);
        case VALUE_EMBEDDED_OBJECT:
            {
                Object value = this.getEmbeddedObject();
                if (value instanceof Number) {
                    return ((Number) value).intValue();
                }
            }
        }
    }
    return defaultValue;
}
 
开发者ID:joyplus,项目名称:joyplus-tv,代码行数:27,代码来源:ParserMinimalBase.java


示例13: getValueAsLong

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
@Override
public long getValueAsLong(long defaultValue) throws IOException, JsonParseException
{
    if (_currToken != null) {
        switch (_currToken) {
        case VALUE_NUMBER_INT:
        case VALUE_NUMBER_FLOAT:
            return getLongValue();
        case VALUE_TRUE:
            return 1;
        case VALUE_FALSE:
        case VALUE_NULL:
            return 0;
        case VALUE_STRING:
            return NumberInput.parseAsLong(getText(), defaultValue);
        case VALUE_EMBEDDED_OBJECT:
            {
                Object value = this.getEmbeddedObject();
                if (value instanceof Number) {
                    return ((Number) value).longValue();
                }
            }
        }
    }
    return defaultValue;
}
 
开发者ID:joyplus,项目名称:joyplus-tv,代码行数:27,代码来源:ParserMinimalBase.java


示例14: getValueAsDouble

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
@Override
public double getValueAsDouble(double defaultValue) throws IOException, JsonParseException
{
    if (_currToken != null) {
        switch (_currToken) {
        case VALUE_NUMBER_INT:
        case VALUE_NUMBER_FLOAT:
            return getDoubleValue();
        case VALUE_TRUE:
            return 1;
        case VALUE_FALSE:
        case VALUE_NULL:
            return 0;
        case VALUE_STRING:
            return NumberInput.parseAsDouble(getText(), defaultValue);
        case VALUE_EMBEDDED_OBJECT:
            {
                Object value = this.getEmbeddedObject();
                if (value instanceof Number) {
                    return ((Number) value).doubleValue();
                }
            }
        }
    }
    return defaultValue;
}
 
开发者ID:joyplus,项目名称:joyplus-tv,代码行数:27,代码来源:ParserMinimalBase.java


示例15: _parseIndex

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
private final static int _parseIndex(String str) {
    final int len = str.length();
    // [core#133]: beware of super long indexes; assume we never
    // have arrays over 2 billion entries so ints are fine.
    if (len == 0 || len > 10) {
        return -1;
    }
    // [core#176]: no leading zeroes allowed
    char c = str.charAt(0);
    if (c <= '0') {
        return (len == 1 && c == '0') ? 0 : -1;
    }
    if (c > '9') {
        return -1;
    }
    for (int i = 1; i < len; ++i) {
        c = str.charAt(i);
        if (c > '9' || c < '0') {
            return -1;
        }
    }
    if (len == 10) {
        long l = NumberInput.parseLong(str);
        if (l > Integer.MAX_VALUE) {
            return -1;
        }
    }
    return NumberInput.parseInt(str);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:JsonPointer.java


示例16: getValueAsInt

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
@Override
public int getValueAsInt(int defaultValue) throws IOException
{
    JsonToken t = _currToken;
    if ((t == JsonToken.VALUE_NUMBER_INT) || (t == JsonToken.VALUE_NUMBER_FLOAT)) {
        return getIntValue();
    }
    if (t != null) {
        switch (t.id()) {
        case ID_STRING:
            String str = getText();
            if (_hasTextualNull(str)) {
                return 0;
            }
            return NumberInput.parseAsInt(str, defaultValue);
        case ID_TRUE:
            return 1;
        case ID_FALSE:
            return 0;
        case ID_NULL:
            return 0;
        case ID_EMBEDDED_OBJECT:
            Object value = getEmbeddedObject();
            if (value instanceof Number) {
                return ((Number) value).intValue();
            }
        }
    }
    return defaultValue;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:ParserMinimalBase.java


示例17: getValueAsLong

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
@Override
public long getValueAsLong(long defaultValue) throws IOException
{
    JsonToken t = _currToken;
    if ((t == JsonToken.VALUE_NUMBER_INT) || (t == JsonToken.VALUE_NUMBER_FLOAT)) {
        return getLongValue();
    }
    if (t != null) {
        switch (t.id()) {
        case ID_STRING:
            String str = getText();
            if (_hasTextualNull(str)) {
                return 0L;
            }
            return NumberInput.parseAsLong(str, defaultValue);
        case ID_TRUE:
            return 1L;
        case ID_FALSE:
        case ID_NULL:
            return 0L;
        case ID_EMBEDDED_OBJECT:
            Object value = getEmbeddedObject();
            if (value instanceof Number) {
                return ((Number) value).longValue();
            }
        }
    }
    return defaultValue;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:ParserMinimalBase.java


示例18: getValueAsDouble

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
@Override
public double getValueAsDouble(double defaultValue) throws IOException
{
    JsonToken t = _currToken;
    if (t != null) {
        switch (t.id()) {
        case ID_STRING:
            String str = getText();
            if (_hasTextualNull(str)) {
                return 0L;
            }
            return NumberInput.parseAsDouble(str, defaultValue);
        case ID_NUMBER_INT:
        case ID_NUMBER_FLOAT:
            return getDoubleValue();
        case ID_TRUE:
            return 1.0;
        case ID_FALSE:
        case ID_NULL:
            return 0.0;
        case ID_EMBEDDED_OBJECT:
            Object value = this.getEmbeddedObject();
            if (value instanceof Number) {
                return ((Number) value).doubleValue();
            }
        }
    }
    return defaultValue;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:ParserMinimalBase.java


示例19: contentsAsInt

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
/**
 * Specialized convenience method that will decode a 32-bit int,
 * of at most 9 digits (and possible leading minus sign).
 *
 * @param neg Whether contents start with a minus sign
 *
 * @since 2.9
 */
public int contentsAsInt(boolean neg) {
    if ((_inputStart >= 0) && (_inputBuffer != null)) {
        if (neg) {
            return -NumberInput.parseInt(_inputBuffer, _inputStart+1, _inputLen-1);
        }
        return NumberInput.parseInt(_inputBuffer, _inputStart, _inputLen);
    }
    if (neg) {
        return -NumberInput.parseInt(_currentSegment, 1, _currentSize-1);
    }
    return NumberInput.parseInt(_currentSegment, 0, _currentSize);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:TextBuffer.java


示例20: contentsAsLong

import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
/**
 * Specialized convenience method that will decode a 64-bit int,
 * of at most 18 digits (and possible leading minus sign).
 *
 * @param neg Whether contents start with a minus sign
 *
 * @since 2.9
 */
public long contentsAsLong(boolean neg) {
    if ((_inputStart >= 0) && (_inputBuffer != null)) {
        if (neg) {
            return -NumberInput.parseLong(_inputBuffer, _inputStart+1, _inputLen-1);
        }
        return NumberInput.parseLong(_inputBuffer, _inputStart, _inputLen);
    }
    if (neg) {
        return -NumberInput.parseLong(_currentSegment, 1, _currentSize-1);
    }
    return NumberInput.parseLong(_currentSegment, 0, _currentSize);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:TextBuffer.java



注:本文中的com.fasterxml.jackson.core.io.NumberInput类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RemoveDefaultAclResponseProto类代码示例发布时间:2022-05-22
下一篇:
Java JMod类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap