Refine search
private static PerfCounterPack extractPerfCounterPack(JSONArray perfJson, String objName) { PerfCounterPack perfPack = new PerfCounterPack(); perfPack.time = System.currentTimeMillis(); perfPack.timetype = TimeTypeEnum.REALTIME; perfPack.objName = objName; for (int i = 0; i < perfJson.size(); i++) { JSONObject perf = (JSONObject) perfJson.get(i); String name = (String) perf.get("name"); Number value = (Number) perf.get("value"); perfPack.data.put(name, new FloatValue(value.floatValue())); } return perfPack; }
/** * Reads a LootItem from its JSON form. * * @param object a LootItem in JSON form */ public LootItem(JSONObject object) { defaultItem = new DefaultLootItem((JSONObject) object.get("default")); if (object.containsKey("conditions")) { JSONArray array = (JSONArray) object.get("conditions"); conditionalItems = new ConditionalLootItem[array.size()]; for (int i = 0; i < array.size(); i++) { JSONObject json = (JSONObject) array.get(i); conditionalItems[i] = new ConditionalLootItem(json); } } else { conditionalItems = NO_ITEMS; } } }
/** * Reads a GlowPlayerProfile from a JSON object. * * @param json a player profile in JSON form * @return {@code json} as a GlowPlayerProfile */ public static GlowPlayerProfile fromJson(JSONObject json) { String name = (String) json.get("name"); String id = (String) json.get("id"); JSONArray propsArray = (JSONArray) json.get("properties"); // Parse UUID UUID uuid; try { uuid = UuidUtils.fromFlatString(id); } catch (IllegalArgumentException ex) { GlowServer.logger.log(Level.SEVERE, "Returned authentication UUID invalid: " + id); return null; } // Parse properties Collection<ProfileProperty> properties = new HashSet<>(propsArray.size()); for (Object obj : propsArray) { JSONObject propJson = (JSONObject) obj; String propName = (String) propJson.get("name"); String value = (String) propJson.get("value"); String signature = (String) propJson.get("signature"); properties.add(new ProfileProperty(propName, value, signature)); } return new GlowPlayerProfile(name, uuid, properties, true); }
return null; String downloadURI = (String) json.get("downloadUri"); JSONArray msg = (JSONArray) json.get("children"); if (msg == null || msg.size() == 0) { LOG.error("Expected directory children not present"); return null; String uri = (String) newest.get("uri"); if (uri == null) { LOG.error("Expected directory uri not present");
/** * Parses a loot table from JSON. * * @param object a loot table in JSON form */ public EntityLootTable(JSONObject object) { if (object.containsKey("experience")) { // NON-NLS this.experience = new LootRandomValues((JSONObject) object.get("experience")); // NON-NLS } else { this.experience = null; } if (object.containsKey("items")) { // NON-NLS JSONArray array = (JSONArray) object.get("items"); // NON-NLS this.items = new LootItem[array.size()]; for (int i = 0; i < array.size(); i++) { JSONObject json = (JSONObject) array.get(i); this.items[i] = new LootItem(json); } } else { this.items = NO_ITEMS; } } }
securityKey = (String) payload.get("s"); // Not used by us anywhere name = (String) payload.get("n"); hostname = (String) payload.get("h"); uuid = UuidUtils.fromFlatString((String) payload.get("u")); address = new InetSocketAddress( JSONArray props = (JSONArray) payload.get("p"); properties = new ArrayList<>(props.size()); for (Object obj : props) { JSONObject prop = (JSONObject) obj; properties = new ArrayList<>(jsonProperties.size()); for (Object obj : jsonProperties) { JSONObject propJson = (JSONObject) obj;
String name = (String) json.get("name"); // NON-NLS String id = (String) json.get("id"); // NON-NLS JSONArray propsArray = (JSONArray) json.get("properties"); // NON-NLS List<ProfileProperty> properties = new ArrayList<>(propsArray.size()); for (Object obj : propsArray) { JSONObject propJson = (JSONObject) obj;
try { JSONObject json = (JSONObject) parser.parse(in); JSONObject objectInfo = (JSONObject) json.get("object"); JSONArray countersArray = (JSONArray) json.get("counters"); String objType = (String) objectInfo.get("type"); family.setName(objType + "." + (Math.random() * 100)); int counterSize = countersArray.size(); for (int i = 0; i < counterSize; i++) { JSONObject counterInfo = (JSONObject)countersArray.get(i); addObjectType.setDisplayName(objectType.getDisplayName()); int counterSize = countersArray.size(); for (int i = 0; i < counterSize; i++) { JSONObject counterInfo = (JSONObject)countersArray.get(i);
/** * Loads the class to * * @param stream label index stream * @return Map of integer -> label name * @throws IOException when the stream breaks unexpectedly * @throws ParseException when the input doesn't contain a valid JSON map */ public Map<Integer, String> loadClassIndex(InputStream stream) throws IOException, ParseException { String content = IOUtils.toString(stream); JSONObject jIndex = (JSONObject) new JSONParser().parse(content); Map<Integer, String> classMap = new HashMap<>(); for (Object key : jIndex.keySet()) { JSONArray names = (JSONArray) jIndex.get(key); classMap.put(Integer.parseInt(key.toString()), names.get(names.size() - 1).toString()); } return classMap; }
private boolean checkForFullTabularDataRepresentation(JSONObject pValue, TabularType pType) { if (pValue.containsKey("indexNames") && pValue.containsKey("values") && pValue.size() == 2) { Object jsonVal = pValue.get("indexNames"); if (!(jsonVal instanceof JSONArray)) { throw new IllegalArgumentException("Index names for tabular data must given as JSON array, not " + jsonVal.getClass()); } JSONArray indexNames = (JSONArray) jsonVal; List<String> tabularIndexNames = pType.getIndexNames(); if (indexNames.size() != tabularIndexNames.size()) { throw new IllegalArgumentException("Given array with index names must have " + tabularIndexNames.size() + " entries " + "(given: " + indexNames + ", required: " + tabularIndexNames + ")"); } for (Object index : indexNames) { if (!tabularIndexNames.contains(index.toString())) { throw new IllegalArgumentException("No index with name '" + index + "' known " + "(given: " + indexNames + ", required: " + tabularIndexNames + ")"); } } return true; } return false; }
if (response.getStatusLine().getStatusCode() == 200) { JSONObject jReply = (JSONObject) new JSONParser().parse(replyMessage); JSONArray jCaptions = (JSONArray) jReply.get("captions"); for (int i = 0; i < jCaptions.size(); i++) { JSONObject jCaption = (JSONObject) jCaptions.get(i); String sentence = (String) jCaption.get("sentence"); Double confidence = (Double) jCaption.get("confidence"); capObjs.add(new CaptionObject(sentence, LABEL_LANG, confidence));
JSONObject jsonObject = convertToJSONObject(result); JSONArray measurements = convertToJSONArray(jsonObject, "measurements"); for(int i=0; i<measurements.size(); i++){ JSONObject quantity = (JSONObject) convertToJSONObject(measurements.get(i).toString()).get("quantity"); if(quantity!=null) { if (quantity.containsKey("rawValue")) { String measurementNumber = (String) convertToJSONObject(quantity.toString()).get("rawValue"); measurementString.append(measurementNumber); measurementString.append(" "); String normalizedMeasurementNumber = convertToJSONObject(quantity.toString()).get("normalizedQuantity").toString(); normalizedMeasurementString.append(normalizedMeasurementNumber); normalizedMeasurementString.append(" ");
return null; Number status = (Number) map.get("Status"); if (status == null || status.intValue() != 0) { log("Bad status: " + status); return null; JSONArray list = (JSONArray) map.get("Answer"); if (list == null || list.isEmpty()) { log("No answer"); return null; log(list.size() + " answers"); String hostAnswer = host + '.'; for (Object o : list) { try { JSONObject a = (JSONObject) o; String data = (String) a.get("data"); if (data == null) { log("no data");
@Test public void testSets() throws Exception { final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer(); final MetricData metricData = new MetricData( FakeMetricDataGenerator.generateFakeSetRollupPoints(), "unknown"); JSONObject metricDataJSON = serializer.transformRollupData(metricData, PlotRequestParser.DEFAULT_SET); final JSONArray data = (JSONArray)metricDataJSON.get("values"); Assert.assertEquals(5, data.size()); for (int i = 0; i < data.size(); i++) { final JSONObject dataJSON = (JSONObject)data.get(i); Assert.assertNotNull(dataJSON.get("numPoints")); Assert.assertEquals(Sets.newHashSet(i, i % 2, i / 2).size(), dataJSON.get("numPoints")); } }
@Test public void setTimers() throws Exception { final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer(); final MetricData metricData = new MetricData( FakeMetricDataGenerator.generateFakeTimerRollups(), "unknown"); JSONObject metricDataJSON = serializer.transformRollupData(metricData, PlotRequestParser.DEFAULT_TIMER); final JSONArray data = (JSONArray)metricDataJSON.get("values"); Assert.assertEquals(5, data.size()); for (int i = 0; i < data.size(); i++) { final JSONObject dataJSON = (JSONObject)data.get(i); Assert.assertNotNull(dataJSON.get("numPoints")); Assert.assertNotNull(dataJSON.get("average")); Assert.assertNotNull(dataJSON.get("rate")); // bah. I'm too lazy to check equals. } }
@Test public void testCounters() throws Exception { final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer(); final MetricData metricData = new MetricData( FakeMetricDataGenerator.generateFakeCounterRollupPoints(), "unknown"); JSONObject metricDataJSON = serializer.transformRollupData(metricData, PlotRequestParser.DEFAULT_COUNTER); final JSONArray data = (JSONArray)metricDataJSON.get("values"); Assert.assertEquals(5, data.size()); for (int i = 0; i < data.size(); i++) { final JSONObject dataJSON = (JSONObject)data.get(i); Assert.assertNotNull(dataJSON.get("numPoints")); Assert.assertEquals(i+1, dataJSON.get("numPoints")); Assert.assertNotNull(dataJSON.get("sum")); Assert.assertEquals((long) (i + 1000), dataJSON.get("sum")); Assert.assertNull(dataJSON.get("rate")); } }
@Test public void testGauges() throws Exception { final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer(); final MetricData metricData = new MetricData( FakeMetricDataGenerator.generateFakeGaugeRollups(), "unknown"); JSONObject metricDataJSON = serializer.transformRollupData(metricData, PlotRequestParser.DEFAULT_GAUGE); final JSONArray data = (JSONArray)metricDataJSON.get("values"); Assert.assertEquals(5, data.size()); for (int i = 0; i < data.size(); i++) { final JSONObject dataJSON = (JSONObject)data.get(i); Assert.assertNotNull(dataJSON.get("numPoints")); Assert.assertEquals(1L, dataJSON.get("numPoints")); Assert.assertNotNull("latest"); Assert.assertEquals(i, dataJSON.get("latest")); // other fields were filtered out. Assert.assertNull(dataJSON.get(MetricStat.AVERAGE.toString())); Assert.assertNull(dataJSON.get(MetricStat.VARIANCE.toString())); Assert.assertNull(dataJSON.get(MetricStat.MIN.toString())); Assert.assertNull(dataJSON.get(MetricStat.MAX.toString())); } }
@Test public void testTransformRollupDataAtFullRes() throws Exception { final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer(); final MetricData metricData = new MetricData(FakeMetricDataGenerator.generateFakeFullResPoints(), "unknown"); JSONObject metricDataJSON = serializer.transformRollupData(metricData, filterStats); final JSONArray data = (JSONArray) metricDataJSON.get("values"); // Assert that we have some data to test Assert.assertTrue(data.size() > 0); for (int i = 0; i < data.size(); i++) { final JSONObject dataJSON = (JSONObject) data.get(i); final Points.Point<SimpleNumber> point = (Points.Point<SimpleNumber>) metricData.getData().getPoints().get(dataJSON.get("timestamp")); Assert.assertEquals(point.getData().getValue(), dataJSON.get("average")); Assert.assertEquals(point.getData().getValue(), dataJSON.get("min")); Assert.assertEquals(point.getData().getValue(), dataJSON.get("max")); // Assert that variance isn't present Assert.assertNull(dataJSON.get("variance")); // Assert numPoints isn't present Assert.assertNull(dataJSON.get("numPoints")); // Assert sum isn't present Assert.assertNull(dataJSON.get("sum")); } }
final JSONArray data = (JSONArray) metricDataJSON.get("values"); Assert.assertTrue(data.size() > 0); 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")); Assert.assertEquals(numPoints, dataJSON.get("numPoints"));