Java Code Examples for io.vertx.core.json.JsonObject#getDouble()
The following examples show how to use
io.vertx.core.json.JsonObject#getDouble() .
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: IndexOptions.java From vertx-mongo-client with Apache License 2.0 | 6 votes |
/** * Constructor from JSON * * @param options the JSON */ public IndexOptions(JsonObject options) { background = options.getBoolean("background", DEFAULT_BACKGROUD); unique = options.getBoolean("unique", DEFAULT_UNIQUE); name = options.getString("name"); sparse = options.getBoolean("sparse", DEFAULT_SPARSE); expireAfterSeconds = options.getLong("expireAfterSeconds"); version = options.getInteger("version"); weights = options.getJsonObject("weights"); defaultLanguage = options.getString("defaultLanguage"); languageOverride = options.getString("languageOverride"); textVersion = options.getInteger("textVersion"); sphereVersion = options.getInteger("sphereVersion"); bits = options.getInteger("bits"); min = options.getDouble("min"); max = options.getDouble("max"); bucketSize = options.getDouble("bucketSize"); storageEngine = options.getJsonObject("storageEngine"); partialFilterExpression = options.getJsonObject("partialFilterExpression"); }
Example 2
Source File: DataObjectWithValues.java From vertx-codegen with Apache License 2.0 | 6 votes |
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 3
Source File: MarketDataVerticle.java From vertx-microservices-workshop with Apache License 2.0 | 6 votes |
/** * Read the configuration and set the initial values. * @param config the configuration */ void init(JsonObject config) { period = config.getLong("period", 3000L); variation = config.getInteger("variation", 100); name = config.getString("name"); Objects.requireNonNull(name); symbol = config.getString("symbol", name); stocks = config.getInteger("volume", 10000); price = config.getDouble("price", 100.0); value = price; ask = price + random.nextInt(variation / 2); bid = price + random.nextInt(variation / 2); share = stocks / 2; }
Example 4
Source File: MarketDataVerticle.java From vertx-kubernetes-workshop with Apache License 2.0 | 6 votes |
/** * Read the configuration and set the initial values. * @param config the configuration */ void init(JsonObject config) { period = config.getLong("period", 3000L); variation = config.getInteger("variation", 100); name = config.getString("name"); Objects.requireNonNull(name); symbol = config.getString("symbol", name); stocks = config.getInteger("volume", 10000); price = config.getDouble("price", 100.0); value = price; ask = price + random.nextInt(variation / 2); bid = price + random.nextInt(variation / 2); share = stocks / 2; System.out.println("Initialized " + name); }
Example 5
Source File: MarketDataVerticle.java From vertx-kubernetes-workshop with Apache License 2.0 | 6 votes |
/** * Read the configuration and set the initial values. * @param config the configuration */ void init(JsonObject config) { period = config.getLong("period", 3000L); variation = config.getInteger("variation", 100); name = config.getString("name"); Objects.requireNonNull(name); symbol = config.getString("symbol", name); stocks = config.getInteger("volume", 10000); price = config.getDouble("price", 100.0); value = price; ask = price + random.nextInt(variation / 2); bid = price + random.nextInt(variation / 2); share = stocks / 2; System.out.println("Initialized " + name); }
Example 6
Source File: MarketDataVerticle.java From microtrader with MIT License | 6 votes |
/** * Read the configuration and set the initial values. * @param config the configuration */ void init(JsonObject config) { period = config.getLong("period", 3000L); variation = config.getInteger("variation", 100); name = config.getString("name"); Objects.requireNonNull(name); symbol = config.getString("symbol", name); stocks = config.getInteger("volume", 10000); price = config.getDouble("price", 100.0); value = price; ask = price + random.nextInt(variation / 2); bid = price + random.nextInt(variation / 2); share = stocks / 2; }
Example 7
Source File: UI.java From demo-mesh-arena with Apache License 2.0 | 6 votes |
boolean mergeWithJson(JsonObject json) { lastCheck = System.currentTimeMillis(); boolean changed = false; if (json.containsKey("style")) { String style = json.getString("style"); changed = !style.equals(this.style); this.style = style; } if (json.containsKey("text")) { String text = json.getString("text"); changed |= !text.equals(this.text); this.text = text; } if (json.containsKey("x")) { Double x = json.getDouble("x"); changed |= !x.equals(this.x); this.x = x; } if (json.containsKey("y")) { Double y = json.getDouble("y"); changed |= !y.equals(this.y); this.y = y; } return changed; }
Example 8
Source File: PortfolioServiceImpl.java From microtrader with MIT License | 5 votes |
@Override public void sell(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) { if (amount <= 0) { resultHandler.handle(Future.failedFuture("Cannot sell " + quote.getString("name") + " - the amount must be " + "greater than 0")); return; } double price = amount * quote.getDouble("bid"); String name = quote.getString("name"); int current = portfolio.getAmount(name); // 1) do we have enough stocks if (current >= amount) { // Yes, sell it int newAmount = current - amount; if (newAmount == 0) { portfolio.getShares().remove(name); } else { portfolio.getShares().put(name, newAmount); } portfolio.setCash(portfolio.getCash() + price); sendActionOnTheEventBus("SELL", amount, quote, newAmount); resultHandler.handle(Future.succeededFuture(portfolio)); } else { resultHandler.handle(Future.failedFuture("Cannot sell " + amount + " of " + name + " - " + "not enough stocks " + "in portfolio")); } }
Example 9
Source File: PortfolioServiceImpl.java From vertx-microservices-workshop with Apache License 2.0 | 5 votes |
@Override public void sell(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) { if (amount <= 0) { resultHandler.handle(Future.failedFuture("Cannot sell " + quote.getString("name") + " - the amount must be " + "greater than 0")); } double price = amount * quote.getDouble("bid"); String name = quote.getString("name"); int current = portfolio.getAmount(name); // 1) do we have enough stocks if (current >= amount) { // Yes, sell it int newAmount = current - amount; if (newAmount == 0) { portfolio.getShares().remove(name); } else { portfolio.getShares().put(name, newAmount); } portfolio.setCash(portfolio.getCash() + price); sendActionOnTheEventBus("SELL", amount, quote, newAmount); resultHandler.handle(Future.succeededFuture(portfolio)); } else { resultHandler.handle(Future.failedFuture("Cannot sell " + amount + " of " + name + " - " + "not enough stocks " + "in portfolio")); } }
Example 10
Source File: PortfolioServiceImpl.java From vertx-microservices-workshop with Apache License 2.0 | 5 votes |
@Override public void buy(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) { if (amount <= 0) { resultHandler.handle(Future.failedFuture("Cannot buy " + quote.getString("name") + " - the amount must be " + "greater than 0")); } if (quote.getInteger("shares") < amount) { resultHandler.handle(Future.failedFuture("Cannot buy " + amount + " - not enough " + "stocks on the market (" + quote.getInteger("shares") + ")")); } double price = amount * quote.getDouble("ask"); String name = quote.getString("name"); // 1) do we have enough money if (portfolio.getCash() >= price) { // Yes, buy it portfolio.setCash(portfolio.getCash() - price); int current = portfolio.getAmount(name); int newAmount = current + amount; portfolio.getShares().put(name, newAmount); sendActionOnTheEventBus("BUY", amount, quote, newAmount); resultHandler.handle(Future.succeededFuture(portfolio)); } else { resultHandler.handle(Future.failedFuture("Cannot buy " + amount + " of " + name + " - " + "not enough money, " + "need " + price + ", has " + portfolio.getCash())); } }
Example 11
Source File: PortfolioServiceImpl.java From vertx-microservices-workshop with Apache License 2.0 | 5 votes |
@Override public void sell(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) { if (amount <= 0) { resultHandler.handle(Future.failedFuture("Cannot sell " + quote.getString("name") + " - the amount must be " + "greater than 0")); return; } double price = amount * quote.getDouble("bid"); String name = quote.getString("name"); int current = portfolio.getAmount(name); // 1) do we have enough stocks if (current >= amount) { // Yes, sell it int newAmount = current - amount; if (newAmount == 0) { portfolio.getShares().remove(name); } else { portfolio.getShares().put(name, newAmount); } portfolio.setCash(portfolio.getCash() + price); sendActionOnTheEventBus("SELL", amount, quote, newAmount); resultHandler.handle(Future.succeededFuture(portfolio)); } else { resultHandler.handle(Future.failedFuture("Cannot sell " + amount + " of " + name + " - " + "not enough stocks " + "in portfolio")); } }
Example 12
Source File: PortfolioServiceImpl.java From vertx-microservices-workshop with Apache License 2.0 | 5 votes |
@Override public void buy(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) { if (amount <= 0) { resultHandler.handle(Future.failedFuture("Cannot buy " + quote.getString("name") + " - the amount must be " + "greater than 0")); return; } if (quote.getInteger("shares") < amount) { resultHandler.handle(Future.failedFuture("Cannot buy " + amount + " - not enough " + "stocks on the market (" + quote.getInteger("shares") + ")")); return; } double price = amount * quote.getDouble("ask"); String name = quote.getString("name"); // 1) do we have enough money if (portfolio.getCash() >= price) { // Yes, buy it portfolio.setCash(portfolio.getCash() - price); int current = portfolio.getAmount(name); int newAmount = current + amount; portfolio.getShares().put(name, newAmount); sendActionOnTheEventBus("BUY", amount, quote, newAmount); resultHandler.handle(Future.succeededFuture(portfolio)); } else { resultHandler.handle(Future.failedFuture("Cannot buy " + amount + " of " + name + " - " + "not enough money, " + "need " + price + ", has " + portfolio.getCash())); } }
Example 13
Source File: CurrencyService.java From vertx-kubernetes-workshop with Apache License 2.0 | 5 votes |
private void handle(RoutingContext rc) { @Nullable JsonObject json = rc.getBodyAsJson(); if (json == null || json.getDouble("amount") == null) { System.out.println("No content or no amount"); rc.fail(400); return; } double amount = json.getDouble("amount"); String target = json.getString("currency"); if (target == null) { target = "EUR"; } double rate = getRate(target); if (rate == -1) { System.out.println("Unknown currency: " + target); rc.fail(400); } int i = random.nextInt(10); if (i < 5) { rc.response().end(new JsonObject() .put("amount", convert(amount, rate)) .put("currency", target).encode() ); } else if (i < 8) { // Failure rc.fail(500); } // Timeout, we don't write the response. }
Example 14
Source File: PortfolioServiceImpl.java From vertx-kubernetes-workshop with Apache License 2.0 | 5 votes |
@Override public void sell(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) { if (amount <= 0) { resultHandler.handle(Future.failedFuture("Cannot sell " + quote.getString("name") + " - the amount must be " + "greater than 0")); return; } double price = amount * quote.getDouble("bid"); String name = quote.getString("name"); int current = portfolio.getAmount(name); // 1) do we have enough stocks if (current >= amount) { // Yes, sell it int newAmount = current - amount; if (newAmount == 0) { portfolio.getShares().remove(name); } else { portfolio.getShares().put(name, newAmount); } portfolio.setCash(portfolio.getCash() + price); sendActionOnTheEventBus("SELL", amount, quote, newAmount); resultHandler.handle(Future.succeededFuture(portfolio)); } else { resultHandler.handle(Future.failedFuture("Cannot sell " + amount + " of " + name + " - " + "not enough stocks " + "in portfolio")); } }
Example 15
Source File: PortfolioServiceImpl.java From vertx-kubernetes-workshop with Apache License 2.0 | 5 votes |
@Override public void buy(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) { if (amount <= 0) { resultHandler.handle(Future.failedFuture("Cannot buy " + quote.getString("name") + " - the amount must be " + "greater than 0")); return; } if (quote.getInteger("shares") < amount) { resultHandler.handle(Future.failedFuture("Cannot buy " + amount + " - not enough " + "stocks on the market (" + quote.getInteger("shares") + ")")); return; } double price = amount * quote.getDouble("ask"); String name = quote.getString("name"); // 1) do we have enough money if (portfolio.getCash() >= price) { // Yes, buy it portfolio.setCash(portfolio.getCash() - price); int current = portfolio.getAmount(name); int newAmount = current + amount; portfolio.getShares().put(name, newAmount); sendActionOnTheEventBus("BUY", amount, quote, newAmount); resultHandler.handle(Future.succeededFuture(portfolio)); } else { resultHandler.handle(Future.failedFuture("Cannot buy " + amount + " of " + name + " - " + "not enough money, " + "need " + price + ", has " + portfolio.getCash())); } }
Example 16
Source File: PortfolioServiceImpl.java From vertx-kubernetes-workshop with Apache License 2.0 | 5 votes |
@Override public void sell(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) { if (amount <= 0) { resultHandler.handle(Future.failedFuture("Cannot sell " + quote.getString("name") + " - the amount must be " + "greater than 0")); return; } double price = amount * quote.getDouble("bid"); String name = quote.getString("name"); int current = portfolio.getAmount(name); // 1) do we have enough stocks if (current >= amount) { // Yes, sell it int newAmount = current - amount; if (newAmount == 0) { portfolio.getShares().remove(name); } else { portfolio.getShares().put(name, newAmount); } portfolio.setCash(portfolio.getCash() + price); sendActionOnTheEventBus("SELL", amount, quote, newAmount); resultHandler.handle(Future.succeededFuture(portfolio)); } else { resultHandler.handle(Future.failedFuture("Cannot sell " + amount + " of " + name + " - " + "not enough stocks " + "in portfolio")); } }
Example 17
Source File: PortfolioServiceImpl.java From vertx-kubernetes-workshop with Apache License 2.0 | 5 votes |
@Override public void buy(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) { if (amount <= 0) { resultHandler.handle(Future.failedFuture("Cannot buy " + quote.getString("name") + " - the amount must be " + "greater than 0")); return; } if (quote.getInteger("shares") < amount) { resultHandler.handle(Future.failedFuture("Cannot buy " + amount + " - not enough " + "stocks on the market (" + quote.getInteger("shares") + ")")); return; } double price = amount * quote.getDouble("ask"); String name = quote.getString("name"); // 1) do we have enough money if (portfolio.getCash() >= price) { // Yes, buy it portfolio.setCash(portfolio.getCash() - price); int current = portfolio.getAmount(name); int newAmount = current + amount; portfolio.getShares().put(name, newAmount); sendActionOnTheEventBus("BUY", amount, quote, newAmount); resultHandler.handle(Future.succeededFuture(portfolio)); } else { resultHandler.handle(Future.failedFuture("Cannot buy " + amount + " of " + name + " - " + "not enough money, " + "need " + price + ", has " + portfolio.getCash())); } }
Example 18
Source File: JsObject.java From vertx-codetrans with Apache License 2.0 | 4 votes |
@CodeTranslate public void getDoubleFromIdentifier() throws Exception { JsonObject obj = new JsonObject().put("port", 8080d); JsonTest.o = obj.getDouble("port"); }
Example 19
Source File: TestDataObject.java From vertx-codegen with Apache License 2.0 | 4 votes |
public TestDataObject(JsonObject json) { this.foo = json.getString("foo", null); this.bar = json.getInteger("bar", 0); this.wibble = json.getDouble("wibble", 0d); }
Example 20
Source File: MetricsTest.java From vertx-dropwizard-metrics with Apache License 2.0 | 4 votes |
private Double getThroughput(JsonObject metric) { assertNotNull(metric); Double actual = metric.getDouble("oneSecondRate"); return actual; }