Java Code Examples for javax.json.JsonArray#getJsonArray()

The following examples show how to use javax.json.JsonArray#getJsonArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonMetadataExporterTest.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void exportByMetricNameWithOneMetricMultipleTags() {
    JsonMetadataExporter exporter = new JsonMetadataExporter();
    MetricRegistry applicationRegistry = MetricRegistries.get(MetricRegistry.Type.APPLICATION);
    applicationRegistry.counter("counter1",
            new Tag("key1", "value1"),
            new Tag("color", "blue"));

    String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "counter1").toString();
    JsonObject json = Json.createReader(new StringReader(result)).read().asJsonObject();

    JsonArray outerTagsArray = json.getJsonObject("counter1").getJsonArray("tags");
    assertEquals(1, outerTagsArray.size());
    JsonArray innerArray = outerTagsArray.getJsonArray(0);
    assertEquals(2, innerArray.size());
    assertEquals("color=blue", innerArray.getString(0));
    assertEquals("key1=value1", innerArray.getString(1));
}
 
Example 2
Source File: JsonMetadataExporterTest.java    From smallrye-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void exportByMetricNameWithMultipleMetrics() {
    JsonMetadataExporter exporter = new JsonMetadataExporter();
    MetricRegistry applicationRegistry = MetricRegistries.get(MetricRegistry.Type.APPLICATION);
    applicationRegistry.counter("counter1", new Tag("key1", "value1"));
    applicationRegistry.counter("counter1", new Tag("key1", "value2"));
    applicationRegistry.counter("counter1", new Tag("key1", "value3"));

    String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "counter1").toString();
    JsonObject json = Json.createReader(new StringReader(result)).read().asJsonObject();

    JsonArray outerTagsArray = json.getJsonObject("counter1").getJsonArray("tags");
    assertEquals(3, outerTagsArray.size());

    JsonArray innerArray1 = outerTagsArray.getJsonArray(0);
    assertEquals(1, innerArray1.size());
    assertEquals("key1=value1", innerArray1.getString(0));

    JsonArray innerArray2 = outerTagsArray.getJsonArray(1);
    assertEquals(1, innerArray2.size());
    assertEquals("key1=value2", innerArray2.getString(0));

    JsonArray innerArray3 = outerTagsArray.getJsonArray(2);
    assertEquals(1, innerArray3.size());
    assertEquals("key1=value3", innerArray3.getString(0));
}
 
Example 3
Source File: JsonMetadataExporterTest.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
@Test
public void exportByMetricNameWithOneMetricSingleTag() {
    JsonMetadataExporter exporter = new JsonMetadataExporter();
    MetricRegistry applicationRegistry = MetricRegistries.get(MetricRegistry.Type.APPLICATION);
    applicationRegistry.counter("counter1", new Tag("key1", "value1"));

    String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "counter1").toString();

    JsonObject json = Json.createReader(new StringReader(result)).read().asJsonObject();
    JsonArray outerTagsArray = json.getJsonObject("counter1").getJsonArray("tags");
    assertEquals(1, outerTagsArray.size());
    JsonArray innerArray = outerTagsArray.getJsonArray(0);
    assertEquals(1, innerArray.size());
    assertEquals("key1=value1", innerArray.getString(0));
}
 
Example 4
Source File: JsonMetadataExporterTest.java    From smallrye-metrics with Apache License 2.0 5 votes vote down vote up
@Test
public void exportByScopeWithMultipleMetrics() {
    JsonMetadataExporter exporter = new JsonMetadataExporter();
    MetricRegistry applicationRegistry = MetricRegistries.get(MetricRegistry.Type.APPLICATION);
    applicationRegistry.counter("counter1", new Tag("key1", "value1"));
    applicationRegistry.counter("counter1", new Tag("key1", "value2"));
    applicationRegistry.counter("counter2", new Tag("color", "red"));

    String result = exporter.exportOneScope(MetricRegistry.Type.APPLICATION).toString();
    JsonObject json = Json.createReader(new StringReader(result)).read().asJsonObject();

    // check items for counter1
    JsonArray outerTagsArray = json.getJsonObject("counter1").getJsonArray("tags");
    assertEquals(2, outerTagsArray.size());

    JsonArray innerArray1 = outerTagsArray.getJsonArray(0);
    assertEquals(1, innerArray1.size());
    assertEquals("key1=value1", innerArray1.getString(0));

    JsonArray innerArray2 = outerTagsArray.getJsonArray(1);
    assertEquals(1, innerArray2.size());
    assertEquals("key1=value2", innerArray2.getString(0));

    // check items for counter2
    outerTagsArray = json.getJsonObject("counter2").getJsonArray("tags");
    assertEquals(1, outerTagsArray.size());

    innerArray1 = outerTagsArray.getJsonArray(0);
    assertEquals(1, innerArray1.size());
    assertEquals("color=red", innerArray1.getString(0));
}
 
Example 5
Source File: BattleDto.java    From logbook with MIT License 4 votes vote down vote up
/**
 * コンストラクター
 */
public BattleDto(JsonObject object) {

    String dockId;

    if (object.containsKey("api_dock_id")) {
        dockId = object.get("api_dock_id").toString();
    } else {
        dockId = object.get("api_deck_id").toString();
    }
    this.friends.add(GlobalContext.getDock(dockId));

    if (object.containsKey("api_fParam_combined")) {
        this.friends.add(GlobalContext.getDock("2"));
    }

    JsonArray shipKe = object.getJsonArray("api_ship_ke");
    for (int i = 1; i < shipKe.size(); i++) {
        long id = shipKe.getJsonNumber(i).longValue();
        ShipInfoDto dto = Ship.get(Long.toString(id));
        if (dto != null) {
            this.enemy.add(dto);
        }
    }

    JsonArray eSlots = object.getJsonArray("api_eSlot");
    for (int i = 0; i < eSlots.size(); i++) {
        JsonArray eSlot = eSlots.getJsonArray(i);
        ItemDto[] slot = new ItemDto[5];
        for (int j = 0; j < eSlot.size(); j++) {
            slot[j] = Item.get(eSlot.getInt(j));
        }
        this.enemySlot.add(slot);
    }

    JsonArray nowhps = object.getJsonArray("api_nowhps");
    for (int i = 1; i < nowhps.size(); i++) {
        if (i <= 6) {
            this.nowFriendHp[i - 1] = nowhps.getJsonNumber(i).intValue();
        } else {
            this.nowEnemyHp[i - 1 - 6] = nowhps.getJsonNumber(i).intValue();
        }
    }

    JsonArray maxhps = object.getJsonArray("api_maxhps");
    for (int i = 1; i < maxhps.size(); i++) {
        if (i <= 6) {
            this.maxFriendHp[i - 1] = maxhps.getJsonNumber(i).intValue();
        } else {
            this.maxEnemyHp[i - 1 - 6] = maxhps.getJsonNumber(i).intValue();
        }
    }

    if (object.containsKey("api_formation")) {
        JsonArray formation = object.getJsonArray("api_formation");
        // 味方陣形
        switch (formation.get(0).getValueType()) {
        case NUMBER:
            this.friendFormation = toFormation(formation.getInt(0));
            break;
        default:
            this.friendFormation = toFormation(Integer.parseInt(formation.getString(0)));
        }
        // 敵陣形
        switch (formation.get(1).getValueType()) {
        case NUMBER:
            this.enemyFormation = toFormation(formation.getInt(1));
            break;
        default:
            this.enemyFormation = toFormation(Integer.parseInt(formation.getString(1)));
        }
        // 艦隊行動
        switch (formation.get(2).getValueType()) {
        case NUMBER:
            this.intercept = toIntercept(formation.getInt(2));
            break;
        default:
            this.intercept = toIntercept(Integer.parseInt(formation.getString(2)));
        }
    } else {
        this.friendFormation = "陣形不明";
        this.enemyFormation = "陣形不明";
        this.intercept = "不明";
    }
}