當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonObject.getDouble方法代碼示例

本文整理匯總了Java中io.vertx.core.json.JsonObject.getDouble方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonObject.getDouble方法的具體用法?Java JsonObject.getDouble怎麽用?Java JsonObject.getDouble使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.vertx.core.json.JsonObject的用法示例。


在下文中一共展示了JsonObject.getDouble方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:cescoffier,項目名稱:vertx-kubernetes-workshop,代碼行數:22,代碼來源:MarketDataVerticle.java

示例2: buy

import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
@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()));
    }
}
 
開發者ID:cescoffier,項目名稱:vertx-kubernetes-workshop,代碼行數:31,代碼來源:PortfolioServiceImpl.java

示例3: sell

import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
@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"));
    }

}
 
開發者ID:cescoffier,項目名稱:vertx-kubernetes-workshop,代碼行數:30,代碼來源:PortfolioServiceImpl.java

示例4: handle

import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
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.
}
 
開發者ID:cescoffier,項目名稱:vertx-kubernetes-workshop,代碼行數:33,代碼來源:CurrencyService.java

示例5: decorateView

import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
public void decorateView(View node, JsonObject jsonObject) {
    Double x, y, width, height;
    x = jsonObject.getDouble("x");
    y = jsonObject.getDouble("y");
    width = jsonObject.getDouble("width");
    height = jsonObject.getDouble("height");
    node.setX(x == null ? 0 : x);
    node.setY(y == null ? 0 : y);
    if (width != null) node.setWidth(width);
    if (height != null) node.setHeight(height);
}
 
開發者ID:whitewoodcity,項目名稱:xbrowser,代碼行數:12,代碼來源:XmlV.java

示例6: decorateControl

import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
public void decorateControl(Control node, JsonObject jsonObject) {
    Double x, y, width, height;
    x = jsonObject.getDouble("x");
    y = jsonObject.getDouble("y");
    width = jsonObject.getDouble("width");
    height = jsonObject.getDouble("height");
    node.setX(x == null ? 0 : x);
    node.setY(y == null ? 0 : y);
    if (width != null) node.setWidth(width);
    if (height != null) node.setHeight(height);
    node.setName(jsonObject.getString("name"));
}
 
開發者ID:whitewoodcity,項目名稱:xbrowser,代碼行數:13,代碼來源:XmlV.java

示例7: decorateChart

import io.vertx.core.json.JsonObject; //導入方法依賴的package包/類
public void decorateChart(Chart node, JsonObject jsonObject) {
    Double x, y, width, height;
    x = jsonObject.getDouble("x");
    y = jsonObject.getDouble("y");
    width = jsonObject.getDouble("width");
    height = jsonObject.getDouble("height");
    node.setX(x == null ? 0 : x);
    node.setY(y == null ? 0 : y);
    if (width != null) node.setWidth(width);
    if (height != null) node.setHeight(height);
    node.setTitle(jsonObject.getString("title"));
    node.setTitleSide(jsonObject.getString("titleside"));
    node.setLegendSide(jsonObject.getString("legendside"));
}
 
開發者ID:whitewoodcity,項目名稱:xbrowser,代碼行數:15,代碼來源:XmlV.java


注:本文中的io.vertx.core.json.JsonObject.getDouble方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。