Java Code Examples for io.vertx.core.json.JsonObject#getFloat()

The following examples show how to use io.vertx.core.json.JsonObject#getFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Aggregation.java    From vertx-elasticsearch-service with Apache License 2.0 6 votes vote down vote up
public Aggregation(JsonObject jsonObject) {
    this.index = jsonObject.getString(JSON_FIELD_INDEX);
    this.type = jsonObject.getString(JSON_FIELD_TYPE);
    this.id = jsonObject.getString(JSON_FIELD_ID);
    this.score = jsonObject.getFloat(JSON_FIELD_SCORE);
    this.version = jsonObject.getLong(JSON_FIELD_VERSION);
    this.source = jsonObject.getJsonObject(JSON_FIELD_SOURCE);

    final JsonObject jsonFields = jsonObject.getJsonObject(JSON_FIELD_FIELDS);
    if (jsonFields != null) {
        for (String fieldName : jsonFields.fieldNames()) {
            final List<Object> fieldValues = new LinkedList<>();
            jsonFields.getJsonArray(fieldName).stream().forEach(e -> fieldValues.add(e));
            this.fields.put(fieldName, fieldValues);
        }
    }
}
 
Example 2
Source File: Hit.java    From vertx-elasticsearch-service with Apache License 2.0 6 votes vote down vote up
public Hit(JsonObject jsonObject) {
    this.index = jsonObject.getString(JSON_FIELD_INDEX);
    this.type = jsonObject.getString(JSON_FIELD_TYPE);
    this.id = jsonObject.getString(JSON_FIELD_ID);
    this.score = jsonObject.getFloat(JSON_FIELD_SCORE);
    this.version = jsonObject.getLong(JSON_FIELD_VERSION);
    this.source = jsonObject.getJsonObject(JSON_FIELD_SOURCE);

    final JsonObject jsonFields = jsonObject.getJsonObject(JSON_FIELD_FIELDS);
    if (jsonFields != null) {
        for (String fieldName : jsonFields.fieldNames()) {
            final List<Object> fieldValues = new LinkedList<>();
            jsonFields.getJsonArray(fieldName).stream().forEach(e -> fieldValues.add(e));
            this.fields.put(fieldName, fieldValues);
        }
    }
}
 
Example 3
Source File: DataObjectWithValues.java    From vertx-codegen with Apache License 2.0 6 votes vote down vote up
public DataObjectWithValues(JsonObject json) {
  booleanValue = json.getBoolean("booleanValue", false);
  shortValue = (short)(int)json.getInteger("shortValue", -1);
  intValue = json.getInteger("intValue", -1);
  longValue = json.getLong("longValue", -1L);
  floatValue = json.getFloat("floatValue", -1f);
  doubleValue = json.getDouble("doubleValue", -1d);
  boxedBooleanValue = json.getBoolean("boxedBooleanValue", null);
  boxedShortValue = json.getInteger("boxedShortValue") != null ? (short)(int)json.getInteger("boxedShortValue") : null;
  boxedIntValue = json.getInteger("boxedIntValue", null);
  boxedLongValue = json.getLong("boxedLongValue", null);
  boxedFloatValue = json.getFloat("boxedFloatValue", null);
  boxedDoubleValue = json.getDouble("boxedDoubleValue", null);
  stringValue = json.getString("stringValue");
  instantValue = json.getInstant("instantValue");
  jsonObjectValue = json.getJsonObject("jsonObjectValue");
  jsonArrayValue = json.getJsonArray("jsonArrayValue");
  dataObjectValue = json.getJsonObject("dataObjectValue") != null ? new TestDataObject(json.getJsonObject("dataObjectValue")) : null;
  enumValue = json.getString("enumValue") != null ? TestEnum.valueOf(json.getString("enumValue")) : null;
  genEnumValue = json.getString("genEnumValue") != null ? TestGenEnum.valueOf(json.getString("genEnumValue")) : null;
}
 
Example 4
Source File: Hits.java    From vertx-elasticsearch-service with Apache License 2.0 5 votes vote down vote up
public Hits(JsonObject jsonObject) {
    this.total = jsonObject.getLong(JSON_FIELD_TOTAL);
    this.maxScore = jsonObject.getFloat(JSON_FIELD_MAX_SCORE);

    final JsonArray jsonHits = jsonObject.getJsonArray(JSON_FIELD_HITS);
    if(jsonHits != null) {
        for (int i=0;i<jsonHits.size();i++) {
            hits.add(new Hit(jsonHits.getJsonObject(i)));
        }
    }
}
 
Example 5
Source File: DeleteByQueryOptions.java    From vertx-elasticsearch-service with Apache License 2.0 5 votes vote down vote up
public DeleteByQueryOptions(JsonObject json) {
    super(json);

    maxRetries = json.getInteger(JSON_FIELD_MAX_RETRIES);
    slices = json.getInteger(JSON_FIELD_SLICES);
    conflicts = Optional.ofNullable(json.getString(JSON_FIELD_CONFLICTS, null)).map(Conflicts::valueOf).orElse(null);
    waitForActiveShards = json.getInteger(JSON_FIELD_WAIT_FOR_ACTIVE_SHARDS);
    requestsPerSecond = json.getFloat(JSON_FIELD_REQUESTS_PER_SECOND);
}
 
Example 6
Source File: DeleteByQueryResponse.java    From vertx-elasticsearch-service with Apache License 2.0 5 votes vote down vote up
public DeleteByQueryResponse(JsonObject json) {
    super(json);

    this.tookMillis = json.getLong(JSON_FIELD_TOOK_MILLIS);
    this.timedOut = json.getBoolean(JSON_FIELD_TIMED_OUT);
    this.deleted = json.getLong(JSON_FIELD_DELETED);
    this.batches = json.getInteger(JSON_FIELD_BATCHES);
    this.versionConflicts = json.getLong(JSON_FIELD_VERSION_CONFLICTS);
    this.retries = Optional.ofNullable(json.getJsonObject(JSON_FIELD_RETRIES)).map(Retries::new).orElse(null);
    this.throttledMillis = json.getLong(JSON_FIELD_THROTTLED_MILLIS);
    this.requestsPerSecond = json.getFloat(JSON_FIELD_REQUESTS_PER_SECOND);
    this.throttledUntilMillis = json.getLong(JSON_FIELD_THROTTLED_UNTIL_MILLIS);
    this.total = json.getLong(JSON_FIELD_TOTAL);
    this.failures = json.getJsonArray(JSON_FIELD_FAILURES);
}
 
Example 7
Source File: AbstractSearchOptions.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
public AbstractSearchOptions(JsonObject json) {

        types = json.getJsonArray(JSON_FIELD_TYPES, new JsonArray()).getList();
        scroll = json.getString(JSON_FIELD_SCROLL);
        timeoutInMillis = json.getLong(JSON_FIELD_TIMEOUT_IN_MILLIS);
        terminateAfter = json.getInteger(JSON_FIELD_TERMINATE_AFTER);
        routing = json.getString(JSON_FIELD_ROUTING);
        preference = json.getString(JSON_FIELD_PREFERENCE);
        query = json.getJsonObject(JSON_FIELD_QUERY);
        postFilter = json.getJsonObject(JSON_FIELD_POST_FILTER);
        minScore = json.getFloat(JSON_FIELD_MIN_SCORE);
        size = json.getInteger(JSON_FIELD_SIZE);
        from = json.getInteger(JSON_FIELD_FROM);
        explain = json.getBoolean(JSON_FIELD_EXPLAIN);
        version = json.getBoolean(JSON_FIELD_VERSION);
        fetchSource = json.getBoolean(JSON_FIELD_FETCH_SOURCE);
        sourceIncludes = json.getJsonArray(JSON_FIELD_SOURCE_INCLUDES, new JsonArray()).getList();
        sourceExcludes = json.getJsonArray(JSON_FIELD_SOURCE_EXCLUDES, new JsonArray()).getList();
        trackScores = json.getBoolean(JSON_FIELD_TRACK_SCORES);
        storedFields = json.getJsonArray(JSON_FIELD_STORED_FIELDS, new JsonArray()).getList();
        indicesOptions = Optional.ofNullable(json.getJsonObject(JSON_FIELD_INDICES_OPTIONS)).map(IndicesOptions::new).orElse(null);

        JsonArray aggregationsJson = json.getJsonArray(JSON_FIELD_AGGREGATIONS);
        if (aggregationsJson != null) {
            for (int i = 0; i < aggregationsJson.size(); i++) {
                aggregations.add(new AggregationOption(aggregationsJson.getJsonObject(i)));
            }
        }

        searchType = Optional.ofNullable(json.getString(JSON_FIELD_SEARCH_TYPE)).map(SearchType::valueOf).orElse(null);
        JsonArray fieldSortOptionsJson = json.getJsonArray(JSON_FIELD_SORTS);
        if (fieldSortOptionsJson != null) {
            for (int i = 0; i < fieldSortOptionsJson.size(); i++) {
                sorts.add(BaseSortOption.parseJson(fieldSortOptionsJson.getJsonObject(i)));
            }
        }

        JsonObject scriptFieldOptionsJson = json.getJsonObject(JSON_FIELD_SCRIPT_FIELDS);
        if (scriptFieldOptionsJson != null) {
            for (String scriptFieldName : scriptFieldOptionsJson.fieldNames()) {
                scriptFields.put(scriptFieldName, new ScriptFieldOption(scriptFieldOptionsJson.getJsonObject(scriptFieldName)));
            }
        }

        final JsonObject suggestOptionsJson = json.getJsonObject(JSON_FIELD_SUGGESTIONS);
        if (suggestOptionsJson != null) {
            for (String suggestionName : suggestOptionsJson.fieldNames()) {
                suggestions.put(suggestionName, BaseSuggestOption.parseJson(suggestOptionsJson.getJsonObject(suggestionName)));
            }
        }
    }
 
Example 8
Source File: SuggestionEntryOption.java    From vertx-elasticsearch-service with Apache License 2.0 4 votes vote down vote up
public SuggestionEntryOption(JsonObject jsonObject) {
    this.text = jsonObject.getString(JSON_FIELD_TEXT);
    this.highlight = jsonObject.getString(JSON_FIELD_HIGHLIGHT);
    this.score = jsonObject.getFloat(JSON_FIELD_SCORE);
}
 
Example 9
Source File: JsObject.java    From vertx-codetrans with Apache License 2.0 4 votes vote down vote up
@CodeTranslate
public void getFloatFromIdentifier() throws Exception {
  JsonObject obj = new JsonObject().put("port", 8080f);
  JsonTest.o = obj.getFloat("port");
}