当前位置: 首页>>代码示例>>Java>>正文


Java Token.VALUE_NUMBER属性代码示例

本文整理汇总了Java中org.elasticsearch.common.xcontent.XContentParser.Token.VALUE_NUMBER属性的典型用法代码示例。如果您正苦于以下问题:Java Token.VALUE_NUMBER属性的具体用法?Java Token.VALUE_NUMBER怎么用?Java Token.VALUE_NUMBER使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.elasticsearch.common.xcontent.XContentParser.Token的用法示例。


在下文中一共展示了Token.VALUE_NUMBER属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testParseGeoPointInvalidType

public void testParseGeoPointInvalidType() throws IOException {
    XContentBuilder json = jsonBuilder().startObject().field("foo", 5).endObject();
    XContentParser parser = createParser(json);
    while (parser.currentToken() != Token.VALUE_NUMBER) {
        parser.nextToken();
    }
    Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
    assertThat(e.getMessage(), is("geo_point expected"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:GeoUtilsTests.java

示例2: parseSinglePointOrList

protected static Collection<String> parseSinglePointOrList(XContentParser parser) throws IOException {
    Token token = parser.currentToken();
    if(token == Token.START_ARRAY) {
        token = parser.nextToken();
        // Test if value is a single point in <code>[lon, lat]</code> format
        if(token == Token.VALUE_NUMBER) {
            double lon = parser.doubleValue();
            if(parser.nextToken() == Token.VALUE_NUMBER) {
                double lat = parser.doubleValue();
                if(parser.nextToken() == Token.END_ARRAY) {
                    return Collections.singleton(GeoHashUtils.stringEncode(lon, lat));
                } else {
                    throw new ElasticsearchParseException("only two values expected");
                }
            } else {
                throw new ElasticsearchParseException("latitue must be a numeric value");
            }
        } else {
            // otherwise it's a list of locations
            ArrayList<String> result = new ArrayList<>();
            while (token != Token.END_ARRAY) {
                result.add(GeoUtils.parseGeoPoint(parser).geohash());
                token = parser.nextToken(); //infinite loop without this line
            }
            return result;
        }
    } else {
        // or a single location
        return Collections.singleton(GeoUtils.parseGeoPoint(parser).geohash());
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:31,代码来源:GeolocationContextMapping.java


注:本文中的org.elasticsearch.common.xcontent.XContentParser.Token.VALUE_NUMBER属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。