Tabnine Logo
JSONArray.get
Code IndexAdd Tabnine to your IDE (free)

How to use
get
method
in
org.json.simple.JSONArray

Best Java code snippets using org.json.simple.JSONArray.get (Showing top 20 results out of 1,017)

origin: SonarSource/sonarqube

private boolean compareArraysByStrictOrder(JSONArray expected, JSONArray actual) {
 if (expected.size() != actual.size()) {
  return false;
 }
 for (int index = 0; index < expected.size(); index++) {
  Object expectedElt = expected.get(index);
  Object actualElt = actual.get(index);
  if (!compare(expectedElt, actualElt)) {
   return false;
  }
 }
 return true;
}
origin: scouter-project/scouter

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;
}

origin: GlowstoneMC/Glowstone

String uuid = (String) ((JSONObject) json.get(0)).get("id");
return UuidUtils.fromFlatString(uuid);
origin: scouter-project/scouter

public static void process(Reader in) {
  JSONParser parser = new JSONParser();
  try {
    Object o = parser.parse(in);
    if (o instanceof JSONArray) {
      JSONArray jsonArray = (JSONArray) o;
      for (int i = 0; i <jsonArray.size(); i++) {
        Object element = jsonArray.get(i);
        if (element instanceof JSONObject) {
          process((JSONObject) element);
        }
      }
    } else if (o instanceof JSONObject) {
      process((JSONObject) o);
    } else {
      scouter.server.Logger.println("SC-8001", 30, "Incorrect body");
    }
  } catch(Throwable th) {
    scouter.server.Logger.println("SC-8000", 30, "Http body parsing error", th);
  }
}

origin: GlowstoneMC/Glowstone

  /**
   * 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;
    }
  }
}
origin: GlowstoneMC/Glowstone

  /**
   * 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;
    }
  }
}
origin: scouter-project/scouter

JSONObject counterInfo = (JSONObject)countersArray.get(i);
String name = (String) counterInfo.get("name");
String unit = (String) counterInfo.get("unit");
JSONObject counterInfo = (JSONObject)countersArray.get(i);
String name = (String) counterInfo.get("name");
if (objectType.getCounter(name) != null) continue;
origin: rhuss/jolokia

  private Object extractValue(Object payload, String key) {
    if (payload instanceof JSONObject) {
      return ((JSONObject) payload).get(key);
    } else if (payload instanceof JSONArray) {
      return ((JSONArray) payload).get(Integer.parseInt(key));
    } else {
      return null;
    }
  }
}
origin: apache/tika

/**
 * Loads the class to
 *
 * @param stream label index stream
 * @return Map of integer -&gt; 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;
}
origin: apache/metron

private boolean replaceKeyArray(JSONObject payload, String toKey, String[] fromKeys) {
 for (String fromKey : fromKeys) {
  if (payload.containsKey(fromKey)) {
   JSONArray value = (JSONArray) payload.remove(fromKey);
   if (value != null && !value.isEmpty()) {
    payload.put(toKey, value.get(0));
    _LOG.trace("[Metron] Added {} to {}", toKey, payload);
    return true;
   }
  }
 }
 return false;
}
origin: apache/metron

@SuppressWarnings("rawtypes")
@Test
public void testFilesBroMessage() throws ParseException {
  Map rawMessageMap = (Map) jsonParser.parse(filesBroMessage);
  JSONObject rawJson = (JSONObject) rawMessageMap.get(rawMessageMap.keySet().iterator().next());
  JSONObject broJson = broParser.parse(filesBroMessage.getBytes()).get(0);
  String expectedBroTimestamp = "1425845251.334";
  Assert.assertEquals(broJson.get("bro_timestamp"), expectedBroTimestamp);
  String expectedTimestamp = "1425845251334";
  Assert.assertEquals(broJson.get("timestamp").toString(), expectedTimestamp);
  Assert.assertEquals(broJson.get("ip_src_addr").toString(), ((JSONArray)rawJson.get("tx_hosts")).get(0).toString());
  Assert.assertEquals(broJson.get("ip_dst_addr").toString(), ((JSONArray)rawJson.get("rx_hosts")).get(0).toString());
  Assert.assertTrue(broJson.get("original_string").toString().startsWith(rawMessageMap.keySet().iterator().next().toString().toUpperCase()));
  Assert.assertEquals(broJson.get("fuid").toString(), rawJson.get("fuid").toString());
  Assert.assertEquals(broJson.get("md5").toString(), rawJson.get("md5").toString());
  Assert.assertEquals(broJson.get("analyzers").toString(), rawJson.get("analyzers").toString());
  Assert.assertTrue(broJson.get("original_string").toString().startsWith("FILES"));
}
origin: apache/metron

@Test
@SuppressWarnings("unchecked")
public void testPatchNotAllowedAlert() throws ParseException {
 PatchRequest pr = new PatchRequest();
 Map<String, Object> patch = (JSONObject) new JSONParser().parse(alertPatchRequest);
 pr.setPatch(Collections.singletonList((JSONObject) ((JSONArray) patch.get("patch")).get(0)));
 assertFalse(dao.isPatchAllowed(pr));
}
origin: apache/metron

@Test
@SuppressWarnings("unchecked")
public void testPatchNotAllowedStatus() throws ParseException {
 PatchRequest pr = new PatchRequest();
 Map<String, Object> patch = (JSONObject) new JSONParser().parse(statusPatchRequest);
 pr.setPatch(Collections.singletonList((JSONObject) ((JSONArray) patch.get("patch")).get(0)));
 assertFalse(dao.isPatchAllowed(pr));
}
origin: apache/metron

@Test
@SuppressWarnings("unchecked")
public void testPatchAllowedName() throws ParseException {
 PatchRequest pr = new PatchRequest();
 Map<String, Object> patch = (JSONObject) new JSONParser().parse(namePatchRequest);
 pr.setPatch(Collections.singletonList((JSONObject) ((JSONArray) patch.get("patch")).get(0)));
 assertTrue(dao.isPatchAllowed(pr));
}
origin: rackerlabs/blueflood

@Test
public void testOutput() throws ParseException {
  List<MetricName> inputMetricNames = new ArrayList<MetricName>() {{
    add(new MetricName("foo", false));
    add(new MetricName("bar", false));
  }};
  String output = handler.getSerializedJSON(inputMetricNames);
  JSONParser jsonParser = new JSONParser();
  JSONArray tokenInfos = (JSONArray) jsonParser.parse(output);
  Assert.assertEquals("Unexpected result size", 2, tokenInfos.size());
  Set<String> expectedOutputSet = new HashSet<String>();
  for (MetricName metricName : inputMetricNames) {
    expectedOutputSet.add(metricName.getName() + "|" + metricName.isCompleteName());
  }
  Set<String> outputSet = new HashSet<String>();
  for (int i = 0; i< inputMetricNames.size(); i++) {
    JSONObject object = (JSONObject) tokenInfos.get(i);
    Iterator it = object.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry entry = (Map.Entry) it.next();
      outputSet.add(entry.getKey() + "|" + entry.getValue());
    }
  }
  Assert.assertEquals("Unexpected size", expectedOutputSet.size(), outputSet.size());
  Assert.assertTrue("Output contains no more elements than expected", expectedOutputSet.containsAll(outputSet));
  Assert.assertTrue("Output contains no less elements than expected", outputSet.containsAll(expectedOutputSet));
}
origin: rackerlabs/blueflood

@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"));
  }
}

origin: rackerlabs/blueflood

@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"));
  }
}

origin: rackerlabs/blueflood

@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.
  }
}

origin: rackerlabs/blueflood

@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"));
  }
}
origin: rackerlabs/blueflood

@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()));
  }
}

org.json.simpleJSONArrayget

Popular methods of JSONArray

  • <init>
    Constructs a JSONArray containing the elements of the specified collection, in the order they are re
  • add
  • size
  • toJSONString
  • iterator
  • addAll
  • isEmpty
  • toString
  • toArray
  • writeJSONString
  • contains
  • remove
  • contains,
  • remove,
  • set,
  • clear,
  • forEach,
  • getJsonObject,
  • listIterator,
  • subList

Popular in Java

  • Creating JSON documents from java classes using gson
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getApplicationContext (Context)
  • setScale (BigDecimal)
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now