for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (source.get(i).equals(target.get(j))) { c[i+1][j+1] = ((c[i][j]) & ~1) + 3; if (i == 0) { j--; builder.add(path + '/' + j, target.get(j)); } else if (j == 0) { i--; if (f > g) { j--; builder.add(path + '/' + j, target.get(j)); } else if (f < g) { i--; } else { // f == g) { i--; j--; diff(path + '/' + i, source.get(i), target.get(j));
/** * Returns an array of RoleInfo corresponding to the JSON serialization returned * by {@link QueueControl#listMessageCounterHistory()}. */ public static DayCounterInfo[] fromJSON(final String jsonString) { JsonObject json = JsonUtil.readJsonObject(jsonString); JsonArray dayCounters = json.getJsonArray("dayCounters"); DayCounterInfo[] infos = new DayCounterInfo[dayCounters.size()]; for (int i = 0; i < dayCounters.size(); i++) { JsonObject counter = (JsonObject) dayCounters.get(i); JsonArray hour = counter.getJsonArray("counters"); long[] hourCounters = new long[24]; for (int j = 0; j < 24; j++) { hourCounters[j] = hour.getInt(j); } DayCounterInfo info = new DayCounterInfo(counter.getString("date"), hourCounters); infos[i] = info; } return infos; }
Address address = new Address(); JsonObject result = (JsonObject) results.get(0); JsonArray components = result.getJsonArray("address_components");
addComma = true; if (ValueType.STRING == array.get(x).getValueType()) { sb.append(array.getString(x)); } else {
@Override public JsonValue get() { if (!contains()) { throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size())); } return array.get(index); }
Object val = jsonArray.get(i);
value = array.get(index);
private void diffArray(String path, JsonArray source, JsonArray target) { /* The array c keeps track of length of the subsequence. To avoid * computing the equality of array elements again, we * left shift its value by 1, and use the low order bit to mark * that two items are equal. */ int m = source.size(); int n = target.size(); int [][] c = new int[m+1][n+1]; for (int i = 0; i < m+1; i++) c[i][0] = 0; for (int i = 0; i < n+1; i++) c[0][i] = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (source.get(i).equals(target.get(j))) { c[i+1][j+1] = ((c[i][j]) & ~1) + 3; // 3 = (1 << 1) | 1; } else { c[i+1][j+1] = Math.max(c[i+1][j], c[i][j+1]) & ~1; } } } emit(path, source, target, c, m, n); }
@Override public JsonValue get() { if (!contains()) { throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size())); } return array.get(index); }
if (j > 0) { emit(path, source, target, c, i, j - 1); builder.add(path + '/' + (j - 1), target.get(j - 1)); if (f > g) { emit(path, source, target, c, i, j - 1); builder.add(path + '/' + (j - 1), target.get(j - 1)); } else if (f < g) { builder.remove(path + '/' + (i - 1)); emit(path, source, target, c, i - 1, j); } else { // f == g) { diff(path + '/' + (i - 1), source.get(i - 1), target.get(j - 1)); emit(path, source, target, c, i - 1, j - 1);
Address address = new Address(); JsonObject result = (JsonObject) results.get(0);
JsonValue jsonValue = vo.get(i); if (jsonValue.getValueType() != JsonValue.ValueType.OBJECT) { throw new ChaincodeCollectionConfigurationException(format("Expected object type in Nof but got %s", jsonValue.getValueType().name()));
Collection.CollectionConfigPackage parse(JsonArray jsonConfig) throws ChaincodeCollectionConfigurationException { Collection.CollectionConfigPackage.Builder colcofbuilder = Collection.CollectionConfigPackage.newBuilder(); for (int i = jsonConfig.size() - 1; i > -1; --i) { Collection.StaticCollectionConfig.Builder ssc = Collection.StaticCollectionConfig.newBuilder(); JsonValue j = jsonConfig.get(i); if (j.getValueType() != JsonValue.ValueType.OBJECT) { throw new ChaincodeCollectionConfigurationException(format("Expected StaticCollectionConfig to be Object type but got: %s", j.getValueType().name())); } JsonObject jsonObject = j.asJsonObject(); JsonObject scf = getJsonObject(jsonObject, "StaticCollectionConfig"); // oneof .. may have different values in the future ssc.setName(getJsonString(scf, "name")) .setBlockToLive(getJsonLong(scf, "blockToLive")) .setMaximumPeerCount(getJsonInt(scf, "maximumPeerCount")) .setMemberOrgsPolicy(Collection.CollectionPolicyConfig.newBuilder() .setSignaturePolicy(parseSignaturePolicyEnvelope(scf)).build()) .setRequiredPeerCount(getJsonInt(scf, "requiredPeerCount")); colcofbuilder.addConfig(Collection.CollectionConfig.newBuilder().setStaticCollectionConfig(ssc).build()); } return colcofbuilder.build(); }
value = array.get(index);
@Override public void endField(DatasetField f) { JsonObjectBuilder jsonField = objectStack.pop(); JsonArray jsonValues = valueArrStack.pop().build(); if (!jsonValues.isEmpty()) { jsonField.add("value", f.getDatasetFieldType().isAllowMultiples() ? jsonValues : jsonValues.get(0)); valueArrStack.peek().add(jsonField); } }
@GET @Path("version") public Response getInfo() { String versionStr = systemConfig.getVersion(true); String[] comps = versionStr.split("build",2); String version = comps[0].trim(); JsonValue build = comps.length > 1 ? Json.createArrayBuilder().add(comps[1].trim()).build().get(0) : JsonValue.NULL; return allowCors(response( req -> ok( Json.createObjectBuilder().add("version", version) .add("build", build)))); }
private TypeIdentifier analyzeInternal(final JsonArray jsonArray) { final TypeIdentifier containedIdentifier = jsonArray.isEmpty() ? TypeIdentifier.ofType(Types.OBJECT) : analyzeInternal(jsonArray.get(0)); final TypeRepresentation containedRepresentation = typeRepresentations.getOrDefault(containedIdentifier, TypeRepresentation.ofConcrete(containedIdentifier)); final TypeIdentifier existingCollection = findExistingCollection(containedRepresentation); if (existingCollection != null) { return existingCollection; } final TypeIdentifier identifier = TypeIdentifier.ofDynamic(); typeRepresentations.put(identifier, TypeRepresentation.ofCollection(identifier, containedRepresentation)); return identifier; }
@Test public void testPostAndGetBooks() { testPostSimpleJsonObject(); final Response r = createWebClient("/bookstore/books").get(); assertEquals(Status.OK.getStatusCode(), r.getStatus()); final JsonArray obj = r.readEntity(JsonArray.class); assertThat(obj.size(), equalTo(1)); assertThat(obj.get(0), instanceOf(JsonObject.class)); assertThat(((JsonObject)obj.get(0)).getInt("id"), equalTo(1)); assertThat(((JsonObject)obj.get(0)).getString("name"), equalTo("Book 1")); }
@Override public JsonValue get() { if (!contains()) { throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size())); } return array.get(index); }
@Test public void testGetRoutingTypesAsJSON() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); session.createAddress(address, RoutingType.ANYCAST, false); AddressControl addressControl = createManagementControl(address); JsonArray jsonArray = JsonUtil.readJsonArray(addressControl.getRoutingTypesAsJSON()); assertEquals(1, jsonArray.size()); assertEquals(RoutingType.ANYCAST.toString(), ((JsonString) jsonArray.get(0)).getString()); }