List of usage examples for com.google.gson JsonArray size
public int size()
From source file:ca.ualberta.cmput301w14t08.geochan.json.ThreadCommentOfflineJsonConverter.java
License:Apache License
private void recursiveDeserialize(JsonObject object, String id, ArrayList<Comment> list) { JsonParser parser = new JsonParser(); JsonArray array = parser.parse(object.get(id).getAsString()).getAsJsonArray(); for (int i = 0; i < array.size(); ++i) { list.add(GsonHelper.getOfflineGson().fromJson(array.get(i), Comment.class)); }// ww w .j a v a2s .c o m for (Comment comment : list) { ArrayList<Comment> childList = new ArrayList<Comment>(); recursiveDeserialize(object, comment.getId(), childList); comment.setChildren(childList); } }
From source file:ca.uhn.fhir.jpa.util.jsonpatch.CopyOperation.java
License:Apache License
@Override public JsonElement apply(JsonElement original) { JsonElement result = duplicate(original); JsonElement item = path.head().navigate(result); JsonElement data = mySourcePath.head().navigate(original); if (item.isJsonObject()) { item.getAsJsonObject().add(path.tail(), data); } else if (item.isJsonArray()) { JsonArray array = item.getAsJsonArray(); int index = (path.tail().equals("-")) ? array.size() : Integer.valueOf(path.tail()); List<JsonElement> temp = new ArrayList<JsonElement>(); Iterator<JsonElement> iter = array.iterator(); while (iter.hasNext()) { JsonElement stuff = iter.next(); iter.remove();/*from ww w. jav a 2 s .c o m*/ temp.add(stuff); } temp.add(index, data); for (JsonElement stuff : temp) { array.add(stuff); } } return result; }
From source file:catalog.CloudantUtil.java
License:Apache License
/** * Only keep _id and _rev for each document in the JSON array. */// w w w .jav a2 s. c o m public static JsonArray updateDocsWithOnlyIdAndRev(JsonArray docs) { for (int i = 0; i < docs.size(); i++) { JsonElement id = docs.get(i).getAsJsonObject().get("id"); JsonElement rev = docs.get(i).getAsJsonObject().get("rev"); docs.get(i).getAsJsonObject().add("_id", id); docs.get(i).getAsJsonObject().add("_rev", rev); } return docs; }
From source file:catalog.CloudantUtil.java
License:Apache License
public static JsonArray addDeletedPropertyToDocs(JsonArray docs) { for (int i = 0; i < docs.size(); i++) { JsonElement id = docs.get(i).getAsJsonObject().get("id"); JsonElement rev = docs.get(i).getAsJsonObject().get("rev"); docs.get(i).getAsJsonObject().add("_id", id); docs.get(i).getAsJsonObject().add("_rev", rev); docs.get(i).getAsJsonObject().addProperty("_deleted", true); }// ww w . j a v a 2 s . co m return docs; }
From source file:ccm.pay2spawn.util.JsonNBTHelper.java
License:Open Source License
public static NBTTagByteArray parseJSONByteArray(String value) { JsonArray in = JSON_PARSER.parse(value).getAsJsonArray(); byte[] out = new byte[in.size()]; for (int i = 0; i < in.size(); i++) out[i] = in.get(i).getAsByte();//from w w w. j a v a 2 s . c o m return new NBTTagByteArray(out); }
From source file:ccm.pay2spawn.util.JsonNBTHelper.java
License:Open Source License
public static NBTTagIntArray parseJSONIntArray(String value) { JsonArray in = JSON_PARSER.parse(value).getAsJsonArray(); int[] out = new int[in.size()]; for (int i = 0; i < in.size(); i++) out[i] = in.get(i).getAsInt();//from www . ja v a 2 s.co m return new NBTTagIntArray(out); }
From source file:ch.cern.db.flume.source.deserializer.RecoveryManagerDeserializer.java
License:GNU General Public License
/** * Reads a line from a file and returns an event * //from w w w .j ava2 s . c o m * @return Event containing parsed line * @throws IOException */ @Override public Event readEvent() throws IOException { ensureOpen(); in.mark(); if (in.read() == -1) return null; in.reset(); RecoveryManagerLogFile rman_log = new RecoveryManagerLogFile(in, maxLineLength); JSONEvent event = new JSONEvent(); event.addProperty("startTimestamp", rman_log.getStartTimestamp()); event.addProperty("backupType", rman_log.getBackupType()); event.addProperty("destination", rman_log.getBackupDestination()); event.addProperty("entityName", rman_log.getEntityName()); //Process properties like (name = value) for (Pair<String, String> property : rman_log.getProperties()) event.addProperty(property.getFirst(), property.getSecond()); String v_params = rman_log.getVParams(); event.addProperty("v_params", v_params != null ? new JsonParser().parse(v_params).getAsJsonObject() : null); JsonArray mountPointNASRegexResult = rman_log.getMountPointNASRegexResult(); event.addProperty("mountPointNASRegexResult", mountPointNASRegexResult); JsonArray volInfoBackuptoDiskFinalResult = rman_log.getVolInfoBackuptoDiskFinalResult(); event.addProperty("volInfoBackuptoDiskFinalResult", volInfoBackuptoDiskFinalResult); JsonArray valuesOfFilesystems = rman_log.getValuesOfFilesystems(); event.addProperty("valuesOfFilesystems", valuesOfFilesystems); List<RecoveryManagerReport> recoveryManagerReports = rman_log.getRecoveryManagerReports(); JsonArray recoveryManagerReportsJson = recoveryManagerReportsToJSON(recoveryManagerReports); event.addProperty("recoveryManagerReports", recoveryManagerReportsJson); int recoveryManagerReportsSize = recoveryManagerReportsJson.size(); if (recoveryManagerReportsSize > 0) { JsonObject lastReport = (JsonObject) recoveryManagerReportsJson.get(recoveryManagerReportsSize - 1); event.addProperty("finishTime", lastReport.get("finishTime")); event.addProperty("finalStatus", lastReport.get("status")); } else { event.addProperty("finishTime", null); event.addProperty("finalStatus", null); } return event; }
From source file:ch.jamiete.hilda.admin.AdminPlugin.java
License:Apache License
@Override public void onLoad() { final Configuration servcfg = this.getHilda().getConfigurationManager().getConfiguration(this, "allowedservers"); final JsonArray servarr = servcfg.get().getAsJsonArray("servers"); if (servarr != null) { for (final JsonElement elem : servarr) { this.getHilda().addAllowedServer(elem.getAsString()); }// w w w . j av a 2 s . co m Hilda.getLogger().info("Allowed " + servarr.size() + " server IDs."); } }
From source file:ch.jamiete.hilda.admin.AdminPlugin.java
License:Apache License
@Override public void onEnable() { this.getHilda().getCommandManager().registerChannelCommand(new AdminBaseCommand(this.getHilda(), this)); this.getHilda().getCommandManager().registerChannelCommand(new ReportCommand(this.getHilda(), this)); this.getHilda().getCommandManager().registerChannelCommand(new SetupCommand(this.getHilda(), this)); this.getHilda().getBot().addEventListener(new ServerJoinListener(this)); this.getHilda().getExecutor().scheduleWithFixedDelay(new MemoryMonitor(this), 1, 1, TimeUnit.MINUTES); final Configuration config = this.getHilda().getConfigurationManager().getConfiguration(this); if (config.get().get("role") == null) { config.get().addProperty("role", ""); Hilda.getLogger().warning("No role specified."); }/*w w w .ja v a2s. c o m*/ if (config.get().get("log") == null) { config.get().addProperty("log", ""); Hilda.getLogger().warning("No log specified."); } config.save(); final String cfg_role = config.get().get("role").getAsString(); if (cfg_role.isEmpty()) { Hilda.getLogger().warning("No role specified."); } else { this.role = this.getHilda().getBot().getRoleById(cfg_role); } final String cfg_log = config.get().get("log").getAsString(); if (cfg_log.isEmpty()) { Hilda.getLogger().warning("No log specified."); } else { this.channel = this.getHilda().getBot().getTextChannelById(cfg_log); } if (this.role == null || this.channel == null) { Hilda.getLogger().warning("Not currently configured correctly."); } final Logger global = Logger.getLogger(""); for (final Handler h : global.getHandlers()) { if (h instanceof LogReporter) { h.close(); global.removeHandler(h); } } this.reporter = new LogReporter(this.channel); global.addHandler(this.reporter); final Configuration cfg = this.getHilda().getConfigurationManager().getConfiguration(this, "ignoredusers"); final JsonArray array = cfg.get().getAsJsonArray("users"); if (array != null) { for (final JsonElement anArray : array) { this.getHilda().getCommandManager().addIgnoredUser(anArray.getAsString()); } Hilda.getLogger().info("Ignored " + array.size() + " naughty users."); } if (this.channel != null) { this.channel .sendMessage( "Hello! " + this.getHilda().getBot().getSelfUser().getName() + " has just started.") .queue(); } }
From source file:ch.jamiete.hilda.moderatortools.ModeratorToolsPlugin.java
License:Apache License
@Override public void onEnable() { this.getHilda().getCommandManager().registerChannelCommand(new ArchiveCommand(this.getHilda())); this.getHilda().getCommandManager().registerChannelCommand(new BlankRoleCommand(this.getHilda())); this.getHilda().getCommandManager().registerChannelCommand(new CheckRolesCommand(this.getHilda())); this.getHilda().getCommandManager().registerChannelCommand(new ClearCommand(this.getHilda())); this.getHilda().getCommandManager().registerChannelCommand(new FlowCommand(this.getHilda(), this)); this.getHilda().getCommandManager().registerChannelCommand(new IgnoreCommand(this.getHilda(), this)); this.getHilda().getCommandManager().registerChannelCommand(new MuteCommand(this.getHilda())); this.getHilda().getCommandManager().registerChannelCommand(new MuteListCommand(this.getHilda())); this.getHilda().getCommandManager().registerChannelCommand(new PurgeCommand(this.getHilda())); this.getHilda().getCommandManager().registerChannelCommand(new ServerinfoCommand(this.getHilda())); this.getHilda().getCommandManager().registerChannelCommand(new UserinfoCommand(this.getHilda())); this.getHilda().getBot().addEventListener(new AnnouncementsListener()); this.getHilda().getBot().addEventListener(new FlowListener(this.getHilda(), this)); final long first = Util.getNextMidnightInMillis("UTC") - System.currentTimeMillis(); this.getHilda().getExecutor().scheduleAtFixedRate(new ChannelDeletionOverseerTask(this.getHilda()), first, 86400000, TimeUnit.MILLISECONDS); // At midnight then every 24 hours Hilda.getLogger().info("Purging channel messages in " + Util.getFriendlyTime(first)); for (final Guild guild : this.getHilda().getBot().getGuilds()) { final Configuration cfg = this.getHilda().getConfigurationManager().getConfiguration(this, "ignore-" + guild.getId()); final JsonArray array = cfg.get().getAsJsonArray("channels"); if (array != null) { final Iterator<JsonElement> iterator = array.iterator(); while (iterator.hasNext()) { this.getHilda().getCommandManager().addIgnoredChannel(iterator.next().getAsString()); }//from w w w .j a v a 2 s .c o m Hilda.getLogger().info("Ignored " + array.size() + " channels in " + guild.getName()); } this.updater.check(guild); } }