本文整理汇总了Java中io.vertx.core.json.JsonArray.size方法的典型用法代码示例。如果您正苦于以下问题:Java JsonArray.size方法的具体用法?Java JsonArray.size怎么用?Java JsonArray.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.json.JsonArray
的用法示例。
在下文中一共展示了JsonArray.size方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processInit
import io.vertx.core.json.JsonArray; //导入方法依赖的package包/类
private Handler<Message<JsonObject>> processInit() {
return msg -> {
try{
JsonObject payload = msg.body();
JsonArray buys = payload.getJsonArray("Buys");
for(int i = 0; i<buys.size();i++){
orderBook.getBuyOrders().put(buys.getJsonObject(i).getDouble("Rate"), buys.getJsonObject(i).getDouble("Quantity"));
}
JsonArray sells = payload.getJsonArray("Sells");
for(int i = 0; i<sells.size();i++){
orderBook.getSellOrders().put(sells.getJsonObject(i).getDouble("Rate"), sells.getJsonObject(i).getDouble("Quantity"));
}
vertx.eventBus().publish(MessageDefinitions.ORDERBOOK_READY+":"+tradingPair, "ready");
} catch(Exception e){
e.printStackTrace();
System.out.println("Failed setting up Order Book");
}
};
}
示例2: fromJson
import io.vertx.core.json.JsonArray; //导入方法依赖的package包/类
@Override
public FdfsClientOptions fromJson(JsonObject json) {
super.fromJson(json);
JsonArray array = json.getJsonArray(TRACKERS);
if (array != null && array.size() > 0) {
array.forEach(object -> {
if (object instanceof JsonObject) {
JsonObject tracker = (JsonObject) object;
String host = tracker.getString(HOST, "");
int port = tracker.getInteger(PORT, -1);
if (!host.isEmpty() && port != -1) {
trackers.add(SocketAddress.inetSocketAddress(port, host));
}
}
});
}
return this;
}
示例3: zip
import io.vertx.core.json.JsonArray; //导入方法依赖的package包/类
static JsonArray zip(
final JsonArray target,
final JsonArray sources,
final String fromKey,
final String toKey
) {
final ConcurrentMap<Integer, Object> targetMap = mapIndex(target, fromKey);
final ConcurrentMap<Object, JsonObject> sourceMap = mapZip(sources, toKey);
final ConcurrentMap<Integer, JsonObject> merged = Statute.reduce(targetMap, sourceMap);
final JsonArray results = new JsonArray();
for (int idx = 0; idx < target.size(); idx++) {
final JsonObject item = append(target.getJsonObject(idx), merged.get(idx), true);
results.add(item);
}
target.clear();
return target.addAll(results);
}
示例4: execZero
import io.vertx.core.json.JsonArray; //导入方法依赖的package包/类
/**
* @param dataArray
* @param clazz
* @param fnIt
* @param <T>
* @throws ZeroException
*/
static <T> void execZero(final JsonArray dataArray,
final Class<T> clazz,
final ZeroBiConsumer<T, Integer> fnIt)
throws ZeroException {
final int size = dataArray.size();
for (int idx = Values.IDX; idx < size; idx++) {
final Object value = dataArray.getValue(idx);
if (null != value) {
if (clazz == value.getClass()) {
final T item = (T) value;
fnIt.accept(item, idx);
}
}
}
}
示例5: deployAll
import io.vertx.core.json.JsonArray; //导入方法依赖的package包/类
/**
* Deploys the list of local and/or remote components
*
* @param future Vert.x Future object to update the status of deployment
* @see <a href="http://vertx.io/docs/apidocs/io/vertx/core/Future.html" target="_blank">Future</a>
*/
public void deployAll(Future<Void> future) {
if (null == this.vertx) {
String errMesg = "Not setup yet! Call 'setup' method first.";
logger.error(errMesg);
future.fail(new Exception(errMesg));
return;
}
JsonArray compList = this.deployConfig.getJsonArray("components");
List<DeployComponent> components = new ArrayList<>();
int listLen = compList.size();
JsonObject deployConf;
for (int idx = 0; idx < listLen; idx++) {
deployConf = compList.getJsonObject(idx);
components.add(this.setupComponent(deployConf));
}
this.deployRecords.deployAll(components, future);
}
示例6: processReceivedData
import io.vertx.core.json.JsonArray; //导入方法依赖的package包/类
/**
* This is where the data leaves the verticle onto the Bus
*
* @param receivedData
* JSON data
*/
protected void processReceivedData(final JsonArray receivedData) {
// The last element in the Array is the all over status
for (int i = 0; i < (receivedData.size() - 1); i++) {
this.processOneResult(receivedData.getJsonObject(i));
}
}
示例7: subscriptionResult
import io.vertx.core.json.JsonArray; //导入方法依赖的package包/类
private void subscriptionResult(final AsyncResult<HttpResponse<JsonArray>> ar) {
if (ar.succeeded()) {
// Process the result
this.captureCookies(ar.result().cookies());
final JsonArray receivedData = ar.result().body();
final JsonObject status = receivedData.getJsonObject(receivedData.size() - 1);
if (status.getBoolean("successful", false)) {
// If the array has only one member we didn't get new data
if (receivedData.size() > 1) {
this.processReceivedData(receivedData);
}
// Do it again eventually
if (!this.shuttingDown && !this.shutdownCompleted) {
this.subscriptionFetch();
} else {
this.shutdownCompleted = true;
}
} else {
// We won't continue
this.logger.fatal(status.encodePrettily());
this.shutdownCompleted = true;
}
} else {
// Preliminary stopping here
// needs to be handled
this.logger.fatal(ar.cause());
this.shutdownCompleted = true;
}
}
示例8: mapIndex
import io.vertx.core.json.JsonArray; //导入方法依赖的package包/类
private static ConcurrentMap<Integer, Object> mapIndex(
final JsonArray sources,
final String field
) {
final ConcurrentMap<Integer, Object> resultMap =
new ConcurrentHashMap<>();
for (int idx = Values.IDX; idx < sources.size(); idx++) {
final JsonObject item = sources.getJsonObject(idx);
final Object value = item.getValue(field);
if (null != value) {
resultMap.put(idx, value);
}
}
return resultMap;
}
示例9: getRequestParameter
import io.vertx.core.json.JsonArray; //导入方法依赖的package包/类
@Override
public String getRequestParameter(String name) {
JsonArray values = parameters.getJsonArray(name);
if (values != null && values.size() > 0) {
return values.getString(0);
}
return null;
}
示例10: apply
import io.vertx.core.json.JsonArray; //导入方法依赖的package包/类
@Override
public Object apply(Object firstParam, Options options) throws IOException {
if (options.params.length > 0) {
int index = options.param(0);
if (firstParam instanceof JsonArray) {
JsonArray array = (JsonArray) firstParam;
if (array.size() > index) {
return array.getValue(index);
}
}
}
return null;
}
示例11: setSeries
import io.vertx.core.json.JsonArray; //导入方法依赖的package包/类
private void setSeries(String name, JsonArray jsonArray){
javafx.scene.chart.XYChart.Series series = new javafx.scene.chart.XYChart.Series();
series.setName(name);
if(xScale == null) return;
for(int i=0;i<xScale.size();i++){
if(i<jsonArray.size()&&jsonArray.getValue(i)!=null) {
Object x = xScale.getValue(i);
if(xAxis instanceof CategoryAxis)
x = x.toString();
Object y = jsonArray.getValue(i);
if(y == null){
}else if(y instanceof Number)
addData(series,x,y);
else if(y instanceof JsonObject){
Object xx=null, yy=null, extra=null;
JsonObject jsonObject = (JsonObject)y;
for(String key:jsonObject.fieldNames()){
if(key.equals("x")) xx = jsonObject.getValue(key);
else if(key.equals("y")) yy = jsonObject.getValue(key);
else extra = jsonObject.getValue(key);
}
if(xx!=null&&yy!=null){
if(extra!=null) addData(series,xx,yy,extra);
else addData(series,xx,yy);
}
}
else
addData(series,x,y);
}
}
((javafx.scene.chart.XYChart)body).getData().add(series);
}
示例12: syncBatchMaterial
import io.vertx.core.json.JsonArray; //导入方法依赖的package包/类
/**
* 获取素材
* @param mediaType 素材类型
* @param offset 开始位置
* @param count 获取数量
* @return
*/
public static Material syncBatchMaterial(MediaType mediaType, Integer offset, Integer count, Account mpAccount){
String accessToken = getAccessToken(mpAccount);
String url = WxApi.getBatchMaterialUrl(accessToken);
JsonObject bodyObj = new JsonObject();
bodyObj.put("type", mediaType.toString());
bodyObj.put("offset", offset);
bodyObj.put("count", count);
String body = bodyObj.toString();
try {
JsonObject jsonObj = WxApi.httpsRequest(url, "POST", body);
if (jsonObj.containsKey("errcode")) {//获取素材失败
System.out.println(ErrCode.errMsg(jsonObj.getInteger("errcode")));
return null;
}else{
Material material = new Material();
material.setTotalCount(jsonObj.getInteger("total_count"));
material.setItemCount(jsonObj.getInteger("item_count"));
JsonArray arr = jsonObj.getJsonArray("item");
if(arr != null && arr.size() > 0){
List<MaterialItem> itemList = new ArrayList<MaterialItem>();
for(int i = 0; i < arr.size(); i++){
JsonObject item = arr.getJsonObject(i);
MaterialItem materialItem = new MaterialItem();
materialItem.setMediaId(item.getString("media_id"));
materialItem.setUpdateTime(item.getLong("update_time")*1000L);
if(item.containsKey("content")){//mediaType=news (图文消息)
JsonArray articles = item.getJsonObject("content").getJsonArray("news_item");
List<MaterialArticle> newsItems = new ArrayList<MaterialArticle>();
for(int j = 0; j < articles.size(); j++){
JsonObject article = articles.getJsonObject(j);
MaterialArticle ma = new MaterialArticle();
ma.setTitle(article.getString("title"));
ma.setThumb_media_id(article.getString("thumb_media_id"));
ma.setShow_cover_pic(article.getString("show_cover_pic"));
ma.setAuthor(article.getString("author"));
ma.setContent_source_url(article.getString("content_source_url"));
ma.setContent(article.getString("content"));
ma.setUrl(article.getString("url"));
newsItems.add(ma);
}
materialItem.setNewsItems(newsItems);
}else{
materialItem.setName(item.getString("name"));
materialItem.setUrl(item.getString("url"));
}
itemList.add(materialItem);
}
material.setItems(itemList);
}
return material;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例13: parseSubMenus
import io.vertx.core.json.JsonArray; //导入方法依赖的package包/类
protected void parseSubMenus (Menu menu, JsonArray jsonArray) {
for (int i = 0; i < jsonArray.size(); i++) {
//get json object
JsonObject entry = jsonArray.getJsonObject(i);
//get event and title
String event = entry.getString("event");
String title = entry.getString("title");
//create new menu item
MenuItem menuItem = new MenuItem(title);
//add click handler
menuItem.setOnAction(event1 -> {
System.out.println("open activitiy: " + event);
EventBus.getInstance().raiseEvent("open_activity", event);
});
menuItem.setAccelerator(new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_DOWN));
//check for shortcut
if (entry.containsKey("shortcut") && !entry.getString("shortcut").isEmpty()) {
String keys[] = entry.getString("shortcut").split("\\+");
if (keys.length > 1) {
KeyCombination.Modifier modifier = null;
if (keys[1].equals("SHIFT_DOWN")) {
modifier = KeyCombination.SHIFT_DOWN;
} else {
throw new UnsupportedOperationException("Unsupported key code: " + keys[1]);
}
//KeyCombination combination = KeyCombination.keyCombination(keys[1]);
menuItem.setAccelerator(new KeyCodeCombination(KeyCode.getKeyCode(keys[0]), modifier));
} else if (keys.length == 1) {
menuItem.setAccelerator(new KeyCodeCombination(KeyCode.getKeyCode(keys[0])));
} else {
//no shortcut is set
}
}
//add menu item to menu
menu.getItems().add(menuItem);
}
}