Java Code Examples for com.eclipsesource.json.JsonArray#size()
The following examples show how to use
com.eclipsesource.json.JsonArray#size() .
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: VirtualNetworkWebResourceTest.java From onos with Apache License 2.0 | 6 votes |
@Override public boolean matchesSafely(JsonArray json) { boolean itemFound = false; final int expectedAttributes = jsonFieldNames.size(); for (int jsonArrayIndex = 0; jsonArrayIndex < json.size(); jsonArrayIndex++) { final JsonObject jsonHost = json.get(jsonArrayIndex).asObject(); if (jsonHost.names().size() < expectedAttributes) { reason = "Found a virtual network with the wrong number of attributes"; return false; } if (checkKey != null && checkKey.test(vnetEntity, jsonHost)) { itemFound = true; assertThat(jsonHost, matchesVnetEntity(vnetEntity, jsonFieldNames, getValue)); } } if (!itemFound) { reason = getKey.apply(vnetEntity) + " was not found"; return false; } return true; }
Example 2
Source File: FlowsResourceTest.java From onos with Apache License 2.0 | 6 votes |
@Override public boolean matchesSafely(JsonArray json) { boolean flowFound = false; for (int jsonFlowIndex = 0; jsonFlowIndex < json.size(); jsonFlowIndex++) { final JsonObject jsonFlow = json.get(jsonFlowIndex).asObject(); final String flowId = Long.toString(flow.id().value()); final String jsonFlowId = jsonFlow.get("id").asString(); if (jsonFlowId.equals(flowId)) { flowFound = true; // We found the correct flow, check attribute values assertThat(jsonFlow, matchesFlow(flow, APP_ID.name())); } } if (!flowFound) { reason = "Flow with id " + flow.id().toString() + " not found"; return false; } else { return true; } }
Example 3
Source File: ZCashClientCaller.java From zencash-swing-wallet-ui with MIT License | 6 votes |
private void decomposeJSONValue(String name, JsonValue val, Map<String, String> map) { if (val.isObject()) { JsonObject obj = val.asObject(); for (String memberName : obj.names()) { this.decomposeJSONValue(name + "." + memberName, obj.get(memberName), map); } } else if (val.isArray()) { JsonArray arr = val.asArray(); for (int i = 0; i < arr.size(); i++) { this.decomposeJSONValue(name + "[" + i + "]", arr.get(i), map); } } else { map.put(name, val.toString()); } }
Example 4
Source File: MetersResourceTest.java From onos with Apache License 2.0 | 6 votes |
@Override protected boolean matchesSafely(JsonArray json) { boolean meterFound = false; for (int jsonMeterIndex = 0; jsonMeterIndex < json.size(); jsonMeterIndex++) { final JsonObject jsonMeter = json.get(jsonMeterIndex).asObject(); final String meterId = meter.id().toString(); final String jsonMeterId = jsonMeter.get("id").asString(); if (jsonMeterId.equals(meterId)) { meterFound = true; assertThat(jsonMeter, matchesMeter(meter)); } } if (!meterFound) { reason = "Meter with id " + meter.id().toString() + " not found"; return false; } else { return true; } }
Example 5
Source File: OpenstackNodeJsonArrayMatcher.java From onos with Apache License 2.0 | 6 votes |
@Override protected boolean matchesSafely(JsonArray json) { boolean nodeFound = false; for (int jsonNodeIndex = 0; jsonNodeIndex < json.size(); jsonNodeIndex++) { final JsonObject jsonNode = json.get(jsonNodeIndex).asObject(); final String hostname = node.hostname(); final String jsonHostname = jsonNode.get("hostname").asString(); if (jsonHostname.equals(hostname)) { nodeFound = true; } } if (!nodeFound) { reason = "Node with hostname " + node.hostname() + " not found"; return false; } else { return true; } }
Example 6
Source File: ZCashClientCaller.java From zencash-swing-wallet-ui with MIT License | 5 votes |
public synchronized String[] getWalletZAddresses() throws WalletCallException, IOException, InterruptedException { JsonArray jsonAddresses = executeCommandAndGetJsonArray("z_listaddresses", null); String strAddresses[] = new String[jsonAddresses.size()]; for (int i = 0; i < jsonAddresses.size(); i++) { strAddresses[i] = jsonAddresses.get(i).asString(); } return strAddresses; }
Example 7
Source File: BoxFolder.java From box-java-sdk with Apache License 2.0 | 5 votes |
private List<String> parseSharedLinkAccessLevels(JsonArray jsonArray) { List<String> accessLevels = new ArrayList<String>(jsonArray.size()); for (JsonValue value : jsonArray) { accessLevels.add(value.asString()); } return accessLevels; }
Example 8
Source File: VirtualNetworkWebResourceTest.java From onos with Apache License 2.0 | 5 votes |
@Override public boolean matchesSafely(JsonArray json) { for (int jsonHostIndex = 0; jsonHostIndex < json.size(); jsonHostIndex++) { JsonObject jsonHost = json.get(jsonHostIndex).asObject(); if (matchesVirtualHost(vhost).matchesSafely(jsonHost)) { return true; } } return false; }
Example 9
Source File: BoxItem.java From box-java-sdk with Apache License 2.0 | 5 votes |
private List<String> parseTags(JsonArray jsonArray) { List<String> tags = new ArrayList<String>(jsonArray.size()); for (JsonValue value : jsonArray) { tags.add(value.asString()); } return tags; }
Example 10
Source File: JsonRunner_Test.java From minimal-json with MIT License | 5 votes |
private boolean equalsIgnoreOrder(JsonArray array1, JsonValue value2) { if (!value2.isArray()) { return false; } JsonArray array2 = value2.asArray(); if (array1.size() != array2.size()) { return false; } for (int i = 0; i < array1.size(); i++) { if (!equalsIgnoreOrder(array2.get(i), array2.get(i))) { return false; } } return true; }
Example 11
Source File: DeviceKeyWebResourceTest.java From onos with Apache License 2.0 | 5 votes |
@Override public boolean matchesSafely(JsonArray json) { boolean deviceKeyFound = false; final int expectedAttributes = 5; for (int jsonDeviceKeyIndex = 0; jsonDeviceKeyIndex < json.size(); jsonDeviceKeyIndex++) { final JsonObject jsonHost = json.get(jsonDeviceKeyIndex).asObject(); // Device keys can have a variable number of attribute so we check // that there is a minimum number. if (jsonHost.names().size() < expectedAttributes) { reason = "Found a device key with the wrong number of attributes"; return false; } final String jsonDeviceKeyId = jsonHost.get(ID).asString(); if (jsonDeviceKeyId.equals(deviceKey.deviceKeyId().id().toString())) { deviceKeyFound = true; // We found the correct device key, check the device key attribute values assertThat(jsonHost, matchesDeviceKey(deviceKey)); } } if (!deviceKeyFound) { reason = "Device key with id " + deviceKey.deviceKeyId().id().toString() + " was not found"; return false; } else { return true; } }
Example 12
Source File: ControlTowerIrDatabase.java From IrScrutinizer with GNU General Public License v3.0 | 5 votes |
private Map<String, String> getMap(String urlFragment, String keyName, String valueName) throws IOException { JsonArray array = getJsonArray(urlFragment); Map<String,String> map = new HashMap<>(array.size()); for (JsonValue val : array) { JsonObject obj = val.asObject(); map.put(obj.get(keyName).asString(), obj.get(valueName).asString()); } return map; }
Example 13
Source File: MetricsTest.java From r2cloud with Apache License 2.0 | 5 votes |
private static JsonObject getById(JsonArray metrics, String id) { for (int i = 0; i < metrics.size(); i++) { JsonObject cur = (JsonObject) metrics.get(i); if (cur.getString("id", "").equals(id)) { return cur; } } return null; }
Example 14
Source File: R2ServerClient.java From r2cloud with Apache License 2.0 | 5 votes |
public void saveMetrics(JsonArray o) { if (o == null || o.size() == 0) { return; } HttpRequest request = createJsonRequest("/api/v1/metrics", o).build(); httpclient.sendAsync(request, BodyHandlers.ofString()).exceptionally(ex -> { Util.logIOException(LOG, "unable to save metrics", ex); return null; }).thenAccept(response -> { if (response != null && response.statusCode() != 200 && LOG.isErrorEnabled()) { LOG.error("unable to save metrics. response code: {}. response: {}", response.statusCode(), response.body()); } }); }
Example 15
Source File: DevicesResourceTest.java From onos with Apache License 2.0 | 5 votes |
@Override public boolean matchesSafely(JsonArray json) { final int minExpectedAttributes = 11; final int maxExpectedAttributes = 12; boolean deviceFound = false; for (int jsonDeviceIndex = 0; jsonDeviceIndex < json.size(); jsonDeviceIndex++) { JsonObject jsonDevice = json.get(jsonDeviceIndex).asObject(); if (jsonDevice.names().size() < minExpectedAttributes || jsonDevice.names().size() > maxExpectedAttributes) { reason = "Found a device with the wrong number of attributes"; return false; } String jsonDeviceId = jsonDevice.get("id").asString(); if (jsonDeviceId.equals(device.id().toString())) { deviceFound = true; // We found the correct device, check attribute values assertThat(jsonDevice, matchesDevice(device)); } } if (!deviceFound) { reason = "Device with id " + device.id().toString() + " not found"; return false; } else { return true; } }
Example 16
Source File: ZCashClientCaller.java From zencash-swing-wallet-ui with MIT License | 5 votes |
public synchronized JsonObject[] getTransactionMessagingDataForZaddress(String ZAddress) throws WalletCallException, IOException, InterruptedException { JsonArray jsonTransactions = executeCommandAndGetJsonArray( "z_listreceivedbyaddress", wrapStringParameter(ZAddress), "0"); List<JsonObject> transactions = new ArrayList<JsonObject>(); for (int i = 0; i < jsonTransactions.size(); i++) { JsonObject trans = jsonTransactions.get(i).asObject(); transactions.add(trans); } return transactions.toArray(new JsonObject[0]); }
Example 17
Source File: FixedArrayJsonRule.java From dungeon with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void validate(JsonValue value) { super.validate(value); JsonArray array = value.asArray(); if (rules.size() != array.size()) { throw new IllegalArgumentException("Array is not of the right size."); } for (int i = 0; i < rules.size(); i++) { rules.get(i).validate(array.values().get(i)); } }
Example 18
Source File: VirtualNetworkWebResourceTest.java From onos with Apache License 2.0 | 5 votes |
@Override public boolean matchesSafely(JsonArray json) { for (int jsonLinkIndex = 0; jsonLinkIndex < json.size(); jsonLinkIndex++) { JsonObject jsonLink = json.get(jsonLinkIndex).asObject(); if (matchesVirtualLink(vlink).matchesSafely(jsonLink)) { return true; } } return false; }
Example 19
Source File: FIOFlags.java From forecastio-lib-java with Eclipse Public License 1.0 | 4 votes |
private String [] toStringArray(JsonArray jsonarray){ String [] out = new String[jsonarray.size()]; for(int i=0; i<jsonarray.size(); i++) out[i] = jsonarray.get(i).asString(); return out; }
Example 20
Source File: GroupsResourceTest.java From onos with Apache License 2.0 | 4 votes |
@Override public boolean matchesSafely(JsonObject jsonGroup) { // check id final Long jsonId = jsonGroup.get("id").asLong(); final String groupId = group.id().id().toString(); if (!jsonId.equals(Long.valueOf(groupId))) { reason = "id " + group.id().id().toString(); return false; } // check application id final String jsonAppId = jsonGroup.get("appId").asString(); final String appId = group.appId().name(); if (!jsonAppId.equals(appId)) { reason = "appId " + group.appId().name(); return false; } // check device id final String jsonDeviceId = jsonGroup.get("deviceId").asString(); if (!jsonDeviceId.equals(group.deviceId().toString())) { reason = "deviceId " + group.deviceId(); return false; } // check bucket array if (group.buckets().buckets() != null) { final JsonArray jsonBuckets = jsonGroup.get("buckets").asArray(); if (group.buckets().buckets().size() != jsonBuckets.size()) { reason = "buckets array size of " + Integer.toString(group.buckets().buckets().size()); return false; } for (final GroupBucket groupBucket : group.buckets().buckets()) { boolean groupBucketFound = false; for (int groupBucketIndex = 0; groupBucketIndex < jsonBuckets.size(); groupBucketIndex++) { final String jsonType = jsonBuckets.get(groupBucketIndex).asObject().get("type").asString(); final String bucketType = groupBucket.type().name(); if (jsonType.equals(bucketType)) { groupBucketFound = true; } } if (!groupBucketFound) { reason = "group bucket " + groupBucket.toString(); return false; } } } return true; }