com.google.gson.JsonElement.getAsDouble()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(203)

本文整理了Java中com.google.gson.JsonElement.getAsDouble()方法的一些代码示例,展示了JsonElement.getAsDouble()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonElement.getAsDouble()方法的具体详情如下:
包路径:com.google.gson.JsonElement
类名称:JsonElement
方法名:getAsDouble

JsonElement.getAsDouble介绍

[英]convenience method to get this element as a primitive double value.
[中]将此元素作为基元双精度值获取的简便方法。

代码示例

代码示例来源:origin: apache/incubator-gobblin

@Override
Object convertField(JsonElement value) {
 return value.getAsDouble();
}

代码示例来源:origin: pinterest/secor

public void convert(JsonElement value, ColumnVector vect, int row) {
    if (value == null || value.isJsonNull()) {
      vect.noNulls = false;
      vect.isNull[row] = true;
    } else {
      DoubleColumnVector vector = (DoubleColumnVector) vect;
      vector.vector[row] = value.getAsDouble();
    }
  }
}

代码示例来源:origin: searchbox-io/Jest

private void parseSource(JsonObject source) {
  for (Map.Entry<String, JsonElement> entry : source.entrySet()) {
    if (!(Double.isNaN(entry.getValue().getAsDouble()))) {
      percentileRanks.put(entry.getKey(), entry.getValue().getAsDouble());
    }
  }
}

代码示例来源:origin: searchbox-io/Jest

private void parseSource(JsonObject source) {
  for (Map.Entry<String, JsonElement> entry : source.entrySet()) {
    if(!(Double.isNaN(entry.getValue().getAsDouble()))) {
      percentiles.put(entry.getKey(), entry.getValue().getAsDouble());
    }
  }
}

代码示例来源:origin: searchbox-io/Jest

public GeoBoundsAggregation(String name, JsonObject geoBoundsAggregation) {
  super(name, geoBoundsAggregation);
  if (geoBoundsAggregation.has(String.valueOf(BOUNDS))) {
    JsonObject bounds = geoBoundsAggregation.getAsJsonObject(String.valueOf(BOUNDS));
    JsonObject topLeft = bounds.getAsJsonObject(String.valueOf(TOP_LEFT));
    JsonObject bottomRight = bounds.getAsJsonObject(String.valueOf(BOTTOM_RIGHT));
    topLeftLat = topLeft.get(String.valueOf(LAT)).getAsDouble();
    topLeftLon = topLeft.get(String.valueOf(LON)).getAsDouble();
    bottomRightLat = bottomRight.get(String.valueOf(LAT)).getAsDouble();
    bottomRightLon = bottomRight.get(String.valueOf(LON)).getAsDouble();
  }
}

代码示例来源:origin: EngineHub/WorldEdit

@Override
  public Vector3 deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonArray jsonArray = json.getAsJsonArray();
    if (jsonArray.size() != 3) {
      throw new JsonParseException("Expected array of 3 length for Vector3");
    }

    double x = jsonArray.get(0).getAsDouble();
    double y = jsonArray.get(1).getAsDouble();
    double z = jsonArray.get(2).getAsDouble();

    return Vector3.at(x, y, z);
  }
}

代码示例来源:origin: searchbox-io/Jest

public ExtendedStatsAggregation(String name, JsonObject extendedStatsAggregation) {
  super(name, extendedStatsAggregation);
  this.sumOfSquares = !extendedStatsAggregation.has(String.valueOf(SUM_OF_SQUARES)) || extendedStatsAggregation.get(String.valueOf(SUM_OF_SQUARES)).isJsonNull() ?
      null : extendedStatsAggregation.get(String.valueOf(SUM_OF_SQUARES)).getAsDouble();
  this.variance = !extendedStatsAggregation.has(String.valueOf(VARIANCE)) || extendedStatsAggregation.get(String.valueOf(VARIANCE)).isJsonNull() ?
      null : extendedStatsAggregation.get(String.valueOf(VARIANCE)).getAsDouble();
  this.stdDeviation = !extendedStatsAggregation.has(String.valueOf(STD_DEVIATION)) || extendedStatsAggregation.get(String.valueOf(STD_DEVIATION)).isJsonNull() ?
      null : extendedStatsAggregation.get(String.valueOf(STD_DEVIATION)).getAsDouble();
}

代码示例来源:origin: searchbox-io/Jest

public StatsAggregation(String name, JsonObject statsAggregation) {
  super(name, statsAggregation);
  this.count = statsAggregation.get(String.valueOf(COUNT)).getAsLong();
  this.min = !statsAggregation.has(String.valueOf(MIN)) || statsAggregation.get(String.valueOf(MIN)).isJsonNull() ?
    null : statsAggregation.get(String.valueOf(MIN)).getAsDouble();
  this.max = !statsAggregation.has(String.valueOf(MAX)) || statsAggregation.get(String.valueOf(MAX)).isJsonNull() ?
      null : statsAggregation.get(String.valueOf(MAX)).getAsDouble();
  this.avg = !statsAggregation.has(String.valueOf(AVG)) || statsAggregation.get(String.valueOf(AVG)).isJsonNull() ?
      null : statsAggregation.get(String.valueOf(AVG)).getAsDouble();
  this.sum = !statsAggregation.has(String.valueOf(SUM)) || statsAggregation.get(String.valueOf(SUM)).isJsonNull() ?
      null : statsAggregation.get(String.valueOf(SUM)).getAsDouble();
}

代码示例来源:origin: searchbox-io/Jest

protected SingleValueAggregation(String name, JsonObject singleValueAggregation) {
  super(name, singleValueAggregation);
  if(singleValueAggregation.has(String.valueOf(VALUE)) && !singleValueAggregation.get(String.valueOf(VALUE)).isJsonNull()) {
    value = singleValueAggregation.get(String.valueOf(VALUE)).getAsDouble();
  }
}

代码示例来源:origin: searchbox-io/Jest

private void parseBuckets(JsonArray buckets) {
  //todo support keyed:true as well
  for (JsonElement bucketv : buckets) {
    JsonObject bucket = bucketv.getAsJsonObject();
    Range geoDistance = new Range(
        bucket,
        bucket.has(String.valueOf(FROM)) ? bucket.get(String.valueOf(FROM)).getAsDouble() : null,
        bucket.has(String.valueOf(TO)) ? bucket.get(String.valueOf(TO)).getAsDouble() : null,
        bucket.has(String.valueOf(DOC_COUNT)) ? bucket.get(String.valueOf(DOC_COUNT)).getAsLong() : null);
    geoDistances.add(geoDistance);
  }
}

代码示例来源:origin: kairosdb/kairosdb

@Override
public DataPoint getDataPoint(long timestamp, JsonElement json) throws IOException
{
  if (json.isJsonObject())
  {
    JsonObject object = json.getAsJsonObject();
    double real = object.get("real").getAsDouble();
    double imaginary = object.get("imaginary").getAsDouble();
    return new ComplexDataPoint(timestamp, real, imaginary);
  }
  else
    throw new IOException("JSON object is not a valid complex data point");
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public final double getAsDouble() {
  return getElement().getAsDouble();
}

代码示例来源:origin: kairosdb/kairosdb

@Override
public DataPoint getDataPoint(long timestamp, JsonElement json)
{
  double value = 0.0;
  if (!json.isJsonNull())
    value = json.getAsDouble();
  return new DoubleDataPoint(timestamp, value);
}

代码示例来源:origin: apache/incubator-gobblin

@Override
 DoubleValue convertField(JsonElement value) {
  return new DoubleValue(value.getAsDouble());
 }
}

代码示例来源:origin: chanjarster/weixin-java-tools

public static Double getAsDouble(JsonElement element) {
  return isNull(element) ? null : element.getAsDouble();
}

代码示例来源:origin: searchbox-io/Jest

public RangeAggregation(String name, JsonObject rangeAggregation) {
  super(name, rangeAggregation);
  ranges = new ArrayList<Range>();
  //todo support keyed:true as well
  for (JsonElement bucketElement : rangeAggregation.get(String.valueOf(BUCKETS)).getAsJsonArray()) {
    JsonObject bucket = bucketElement.getAsJsonObject();
    Range range = new Range(
        bucket,
        bucket.has(String.valueOf(FROM)) ? bucket.get(String.valueOf(FROM)).getAsDouble() : null,
        bucket.has(String.valueOf(TO)) ? bucket.get(String.valueOf(TO)).getAsDouble() : null,
        bucket.get(String.valueOf(DOC_COUNT)).getAsLong());
    ranges.add(range);
  }
}

代码示例来源:origin: searchbox-io/Jest

private void parseBuckets(JsonArray bucketsSource) {
  for (JsonElement bucketv : bucketsSource) {
    JsonObject bucket = bucketv.getAsJsonObject();
    SignificantTerm term = new SignificantTerm(
        bucket,
        bucket.get(String.valueOf(KEY)).getAsString(),
        bucket.get(String.valueOf(DOC_COUNT)).getAsLong(),
        bucket.get(String.valueOf(SCORE)).getAsDouble(),
        bucket.get(String.valueOf(BG_COUNT)).getAsLong()
    );
    significantTerms.add(term);
  }
}

代码示例来源:origin: searchbox-io/Jest

private void parseBuckets(JsonArray buckets) {
  //todo support keyed:true as well
  for (JsonElement bucketv : buckets) {
    JsonObject bucket = bucketv.getAsJsonObject();
    DateRange range = new DateRange(
        bucket,
        bucket.has(String.valueOf(FROM)) ? bucket.get(String.valueOf(FROM)).getAsDouble() : null,
        bucket.has(String.valueOf(TO)) ? bucket.get(String.valueOf(TO)).getAsDouble() : null,
        bucket.get(String.valueOf(DOC_COUNT)).getAsLong(),
        bucket.has(String.valueOf(FROM_AS_STRING)) ? bucket.get(String.valueOf(FROM_AS_STRING)).getAsString() : null,
        bucket.has(String.valueOf(TO_AS_STRING)) ? bucket.get(String.valueOf(TO_AS_STRING)).getAsString() : null);
    ranges.add(range);
  }
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public TDoubleList getAsDoubleArray() {
  TDoubleList result = new TDoubleArrayList(size());
  for (JsonElement element : array) {
    result.add(element.getAsDouble());
  }
  return result;
}

代码示例来源:origin: json-path/JsonPath

@Test
public void doubles_are_unwrapped() {
  final String json = "{double-property = 56.78}";
  JsonElement node =  using(GSON_CONFIGURATION).parse(json).read("$.double-property");
  Double val =  using(GSON_CONFIGURATION).parse(json).read("$.double-property", Double.class);
  assertThat(val).isEqualTo(56.78);
  assertThat(val).isEqualTo(node.getAsDouble());
}

相关文章