本文整理匯總了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);
}
示例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()));
}
}
示例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"));
}
}
示例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.
}
示例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);
}
示例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"));
}
示例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"));
}