List of usage examples for org.json.simple JSONArray size
public int size()
From source file:com.worldline.easycukes.commons.helpers.JSONHelper.java
/** * Returns a particular property from a JSONArray * * @param jsonArray JSONArray you want to parse * @param simpleProp property you're searching for * @return An Object matching the required property *//*from w w w .j av a2 s. c o m*/ private static Object getProperty(@NonNull JSONArray jsonArray, @NonNull String simpleProp) { if (simpleProp.startsWith("[")) { final int idx2 = simpleProp.indexOf("]"); if (idx2 > 0) { final String exp = simpleProp.substring(1, idx2); if (exp.contains("=")) { final String[] expParams = exp.split("="); for (final Iterator<JSONObject> iterator = jsonArray.iterator(); iterator.hasNext();) { final JSONObject jsonObject = iterator.next(); if (getValue(jsonObject, expParams[0]).equals(expParams[1])) return jsonObject; } } else if (StringUtils.isNumeric(exp) && jsonArray.size() > Integer.parseInt(exp)) return jsonArray.get(Integer.parseInt(exp)); } } return null; }
From source file:co.mcme.animations.animations.commands.AnimationFactory.java
public static boolean saveAnimationData(Player p) { //Perform Animation integrity checks if (animationName.trim().isEmpty()) { p.sendMessage(ChatColor.RED//from w w w . j a v a 2 s. c o m + "Animation name has not been set. Use /anim name while in Animation setup mode to set up the animation name"); return false; } if ((null == animationDescription) || (animationDescription.trim().isEmpty())) { p.sendMessage(ChatColor.RED + "The animation needs a description. Use /anim description while in Animation setup mode to set up the animation description"); return false; } if (null == origin) { p.sendMessage(ChatColor.RED + "Origin has not been set. Use /anim origin while in Animation setup mode to set up the animation origin"); return false; } if (null == type) { p.sendMessage(ChatColor.RED + "Animation type has not been set. Use /anim type while in Animation setup mode to set up the animation type"); return false; } if (frames.isEmpty()) { p.sendMessage(ChatColor.RED + "The Animation doesn't contain any Frame!"); return false; } if (clips.isEmpty()) { p.sendMessage(ChatColor.RED + "The Animation doesn't contain any Clipboard!"); return false; } if (triggers.isEmpty()) { p.sendMessage(ChatColor.RED + "The Animation doesn't contain any Trigger!"); return false; } //Save all the schematics File animationFolder = new File(MCMEAnimations.MCMEAnimationsInstance.getDataFolder() + File.separator + "schematics" + File.separator + "animations" + File.separator + animationName); if (animationFolder.exists()) { try { delete(animationFolder); } catch (IOException ex) { Logger.getLogger(AnimationFactory.class.getName()).log(Level.SEVERE, null, ex); } } animationFolder.mkdirs(); for (MCMEClipboardStore cs : clips) { if (cs.getUses() > 0) { saveClipboardToFile(cs.getClip(), cs.getSchematicName(), animationFolder); } } //Save the configuration file JSONObject configuration = new JSONObject(); configuration.put("name", animationName); configuration.put("world-index", p.getWorld().getName()); JSONArray frameList = new JSONArray(); JSONArray durationList = new JSONArray(); for (int i = 0; i < frames.size(); i++) { frameList.add(frames.get(i).getSchematic().getSchematicName()); durationList.add(frames.get(i).getDuration()); } configuration.put("frames", frameList); configuration.put("durations", durationList); JSONArray originPoints = new JSONArray(); originPoints.add((int) Math.floor(origin.getX())); originPoints.add((int) Math.floor(origin.getY())); originPoints.add((int) Math.floor(origin.getZ())); configuration.put("origin", originPoints); configuration.put("type", type.toString()); JSONArray interactions = new JSONArray(); for (AnimationTrigger at : triggers) { interactions.add(at.toJSON()); } configuration.put("interactions", interactions); JSONArray animationActions = new JSONArray(); for (AnimationAction a : actions) { animationActions.add(a.toJSON()); } if (animationActions.size() > 0) { configuration.put("actions", animationActions); } configuration.put("creator", owner.getDisplayName()); configuration.put("description", animationDescription); try { FileWriter fw = new FileWriter(new File(MCMEAnimations.MCMEAnimationsInstance.getDataFolder() + File.separator + "schematics" + File.separator + "animations" + File.separator + animationName + File.separator + "conf.json")); fw.write(configuration.toJSONString()); fw.flush(); fw.close(); } catch (IOException ex) { p.sendMessage("Error saving Animation configuration file!"); return false; } p.sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "Animation " + animationName + " saved and ready to run! Use /anim reset to reload the configuration."); return true; }
From source file:Host.java
public Host(JSONArray list) { this.status = "ok"; for (int i = 0; i < list.size(); i++) { JSONObject obj = (JSONObject) list.get(i); this.list.add(obj); }// w w w. jav a2 s . co m }
From source file:edu.anu.spice.SpiceRefTupleTest.java
protected void compare(JSONArray expected, JSONArray actual) { assertEquals("Output wrong number of results", expected.size(), actual.size()); for (int i = 0; i < expectedOutput.size(); i++) { JSONObject expectedItem = (JSONObject) expected.get(i); JSONObject actualItem = (JSONObject) actual.get(i); // Image id assertEquals("Incorrect image id", expectedItem.get("image_id"), actualItem.get("image_id")); // Ref tuples JSONArray expectedRefTuples = (JSONArray) expectedItem.get("ref_tuples"); JSONArray actualRefTuples = (JSONArray) actualItem.get("ref_tuples"); compareTuples(expectedRefTuples, actualRefTuples, "ref", expectedItem.get("image_id")); }/* w w w .j av a2 s .com*/ }
From source file:edu.anu.spice.SpiceTestTupleTest.java
protected void compare(JSONArray expected, JSONArray actual) { assertEquals("Output wrong number of results", expected.size(), actual.size()); for (int i = 0; i < expectedOutput.size(); i++) { JSONObject expectedItem = (JSONObject) expected.get(i); JSONObject actualItem = (JSONObject) actual.get(i); // Image id assertEquals("Incorrect image id", expectedItem.get("image_id"), actualItem.get("image_id")); // Test tuples JSONArray expectedTestTuples = (JSONArray) expectedItem.get("test_tuples"); JSONArray actualTestTuples = (JSONArray) actualItem.get("test_tuples"); compareTuples(expectedTestTuples, actualTestTuples, "test", expectedItem.get("image_id")); }/* w w w .ja v a 2 s. c om*/ }
From source file:com.kaylerrenslow.armaDialogCreator.updater.github.ReleaseInfo.java
public ReleaseInfo(JSONObject object) throws IOException, ParseException { tagName = object.get("tag_name").toString(); releaseName = object.get("name").toString(); JSONArray assets = (JSONArray) object.get("assets"); this.assets = new ReleaseAsset[assets.size()]; int i = 0;/*from w ww .j a va2 s . c o m*/ for (Object assetObj : assets) { this.assets[i++] = new ReleaseAsset((JSONObject) assetObj); } }
From source file:edu.anu.spice.SpiceScoreTest.java
@SuppressWarnings("unchecked") protected void compare(JSONArray expected, JSONArray actual) { assertEquals("Output wrong number of results", expected.size(), actual.size()); for (int i = 0; i < expectedOutput.size(); i++) { JSONObject expectedItem = (JSONObject) expected.get(i); JSONObject actualItem = (JSONObject) actual.get(i); // Image id assertEquals("Incorrect image id", expectedItem.get("image_id"), actualItem.get("image_id")); // Scores JSONObject testScores = (JSONObject) actualItem.get("scores"); JSONObject refScores = (JSONObject) expectedItem.get("scores"); Set<Map.Entry<String, JSONObject>> entrySet = refScores.entrySet(); for (Map.Entry<String, JSONObject> e : entrySet) { assertEquals(String.format("Incorrect score for image id %s", expectedItem.get("image_id")), e.getValue(), testScores.get(e.getKey())); }//from w w w. j av a 2s . c o m } }
From source file:com.rackspacecloud.blueflood.outputs.serializers.JSONHistogramOutputSerializerTest.java
@Test public void testHistogramRollupsSerialization() throws SerializationException { final JSONHistogramOutputSerializer serializer = new JSONHistogramOutputSerializer(); final MetricData metricData = new MetricData(FakeMetricDataGenerator.generateFakeHistogramRollupPoints(), "unknown", MetricData.Type.HISTOGRAM); JSONObject metricDataJSON = serializer.transformHistogram(metricData); final JSONArray data = (JSONArray) metricDataJSON.get("values"); for (int i = 0; i < data.size(); i++) { final JSONObject dataJSON = (JSONObject) data.get(i); final Points.Point point = (Points.Point) metricData.getData().getPoints() .get(dataJSON.get("timestamp")); JSONArray hist = (JSONArray) dataJSON.get("histogram"); Assert.assertNotNull(hist);/*from www . ja v a 2 s . c o m*/ for (int j = 0; j < hist.size(); j++) { JSONObject bin = (JSONObject) hist.get(j); Assert.assertNotNull(bin.get("count")); Assert.assertNotNull(bin.get("mean")); } } }
From source file:com.endgame.binarypig.util.JsonUtil.java
public Object wrap(Object value) { if (isNestedLoadEnabled && value instanceof JSONObject) { return walkJson((JSONObject) value); } else if (isNestedLoadEnabled && value instanceof JSONArray) { JSONArray a = (JSONArray) value; DataBag mapValue = new NonSpillableDataBag(a.size()); for (int i = 0; i < a.size(); i++) { Tuple t = tupleFactory.newTuple(wrap(a.get(i))); mapValue.add(t);/* w w w .j a v a2s. c om*/ } return mapValue; } else { return value != null ? value.toString() : null; } }
From source file:com.player.mood.moodplayer.soundcloud.SoundcloudPlaylist.java
public ArrayList<SoundcloudTrack> getSongsInfo() { String id, title, artist, streamURL, locationURL = ""; Long duration;/* w w w . j a v a2 s . c om*/ ArrayList<SoundcloudTrack> result = new ArrayList<SoundcloudTrack>(); JSONArray tracks = (JSONArray) this.obj.get("tracks"); JSONObject t = null; for (int i = 0; i < tracks.size(); i++) { t = (JSONObject) tracks.get(i); id = String.valueOf(t.get("id")); title = filterTitle(t.get("title").toString()); artist = ((JSONObject) t.get("user")).get("username").toString(); streamURL = t.get("stream_url").toString(); duration = (Long) t.get("duration"); SoundcloudTrack si = new SoundcloudTrack(id, artist, title, streamURL, duration); result.add(si); } return result; }