/** * Returns the <code>double</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>double</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public double getDouble(String name, double defaultValue) { JsonValue value = get(name); return value != null ? value.asDouble() : defaultValue; }
@Override public double asDouble() { return wrapped.asDouble(); }
@Override public Double read(JsonValue jsonValue) throws Exception { return jsonValue.asDouble(); }
@Override protected Double getValue(JsonValue jsonValue) throws Exception { return jsonValue.asDouble(); }
@Override protected BigDecimal getValue(JsonValue jsonValue) throws Exception { return BigDecimal.valueOf(jsonValue.asDouble()); }
@Override public BigDecimal read(JsonValue jsonValue) throws Exception { return BigDecimal.valueOf(jsonValue.asDouble()); }
/** * Returns the latitude that is setted for the request. * @return A Double number with the latitude. */ public Double getLatitude(){ return this.forecast.get("latitude").asDouble(); }
/** * Returns the timezone offset in an double * For more information refer to the API Docs: * <a href="https://developer.forecast.io">https://developer.forecast.io</a> * @return double with the offset */ public double offsetValue(){ return this.forecast.get("offset").asDouble(); }
/** * Returns the longitude that is setted for the request. * @return A Double number with the longitude. */ public Double getLongitude(){ return this.forecast.get("longitude").asDouble(); }
public static Double getDouble(JsonValue value, String name) { JsonValue result = ((JsonObject) value).get(name); if (result == null) { return null; } return result.asDouble(); }
/** * Get a value from a float metadata field. * @param path the key path in the metadata object. Must be prefixed with a "/". * @return the metadata value as a floating point number. */ public double getFloat(String path) { // @NOTE(mwiller) 2018-02-05: JS number are all 64-bit floating point, so double is the correct type to use here return this.getValue(path).asDouble(); }
/** * Returns the offset as a String with '+' or '-' sign. * For more information refer to the API Docs: * <a href="https://developer.forecast.io">https://developer.forecast.io</a> * @return String with the offset */ public String offset(){ if(this.forecast.get("offset").asDouble()<0) return ""+this.forecast.get("offset").asDouble(); else if(this.forecast.get("offset").asDouble()>0) return ""+"+"+this.forecast.get("offset").asDouble(); else return ""; }
/** * Returns the <code>double</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>double</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public double getDouble(String name, double defaultValue) { JsonValue value = get(name); return value != null ? value.asDouble() : defaultValue; }
/** * Returns the <code>double</code> value of the member with the specified name in this object. If * this object does not contain a member with this name, the given default value is returned. If * this object contains multiple members with the given name, the last one will be picked. If this * member's value does not represent a JSON number or if it cannot be interpreted as Java * <code>double</code>, an exception is thrown. * * @param name * the name of the member whose value is to be returned * @param defaultValue * the value to be returned if the requested member is missing * @return the value of the last member with the specified name, or the given default value if * this object does not contain a member with that name */ public double getDouble(String name, double defaultValue) { JsonValue value = get(name); return value != null ? value.asDouble() : defaultValue; }
public Double getAsDouble(final String field){ JsonValue value = getAsJsonValue(field); if (value == null || value.isNull()) { return null; } return value.asDouble(); }
public static Object deserialize(JsonValue v, Type type) { switch (type) { case INTEGER: return v.asLong(); case FLOAT: return v.asDouble(); case BOOLEAN: return v.asBoolean(); case OPAQUE: return Base64.decodeBase64(v.asString()); case STRING: return v.asString(); case TIME: return new Date(v.asLong()); default: throw new IllegalArgumentException(String.format("Type %s is not supported", type.name())); } } }
public static Object deserialize(JsonValue v, Type type) { switch (type) { case INTEGER: return v.asLong(); case FLOAT: return v.asDouble(); case BOOLEAN: return v.asBoolean(); case OPAQUE: return Base64.decodeBase64(v.asString()); case STRING: return v.asString(); case TIME: return new Date(v.asLong()); default: throw new IllegalArgumentException(String.format("Type %s is not supported", type.name())); } } }
public static Object ofJson(JsonValue json) { if(json.isObject()) { Iterator<JsonObject.Member> iterator = json.asObject().iterator(); Binder b = new Binder(); while (iterator.hasNext()) { JsonObject.Member m = iterator.next(); b.put(m.getName(),ofJson(m.getValue())); } return b; } else if(json.isBoolean()) { return json.asBoolean(); } else if(json.isNumber()) { return json.asDouble(); } else if(json.isString()) { return json.asString(); } else if(json.isArray()) { JsonArray ja = json.asArray(); List<Object> list = new ArrayList<>(); for(int i = 0; i < ja.size();i++) { list.add(ofJson(ja.get(i))); } return list; } return null; }
public void load() throws ConnectionException { String uuid = id.substring(3); // trims the string "28:" JsonObject root = Endpoints.AGENT_INFO.open(skype, uuid) .expect(200, "While fetching agent info") .as(JsonObject.class) .get(); JsonArray descriptions = root.get("agentDescriptions").asArray(); if (descriptions.size() > 1) { throw Skype.UNEXPECTED; } JsonObject object = descriptions.get(0).asObject(); this.displayName = Utils.getString(object, "displayName"); this.description = Utils.getString(object, "description"); this.developer = Utils.getString(object, "developer"); this.extra = Utils.getString(object, "extra"); this.userTileSmallUrl = Utils.getString(object, "userTileSmallUrl"); this.userTileMediumUrl = Utils.getString(object, "userTileMediumUrl"); this.userTileLargeUrl = Utils.getString(object, "userTileLargeUrl"); this.userTileExtraLargeUrl = Utils.getString(object, "userTileExtraLargeUrl"); this.userTileStaticUrl = Utils.getString(object, "userTileStaticUrl"); this.webpage = Utils.getString(object, "webpage"); this.tos = Utils.getString(object, "tos"); this.privacyStatement = Utils.getString(object, "privacyStatement"); this.isTrusted = object.get("isTrusted").asBoolean(); object.get("capabilities").asArray().iterator().forEachRemaining(value -> this.capabilities.add(value.asString())); object.get("supportedLocales").asArray().iterator().forEachRemaining(value -> this.supportedLocales.add(value.asString())); this.agentType = Utils.getString(object, "agentType"); this.starRating = object.get("starRating").asDouble(); }
jae.setFloatValue(v.asDouble());