/** * Returns a new JSON array which is based on the given JSON array of the Minimal Json project library. * * @param values the values to base the JSON array to be created on. * @return a new JSON array. * @throws NullPointerException if {@code minimalJsonArray} is {@code null}. */ public static ImmutableJsonArray of(final List<JsonValue> values) { return new ImmutableJsonArray(values); }
@Override public ImmutableJsonArray add(final String value, final String... furtherValues) { checkValue(value); checkFurtherValues(furtherValues); return add(JsonFactory.newValue(value), Arrays.stream(furtherValues) .map(JsonFactory::newValue) .toArray(JsonValue[]::new)); }
@Override public ImmutableJsonArray add(final JsonValue value, final JsonValue... furtherValues) { checkValue(value); checkFurtherValues(furtherValues); final List<JsonValue> valuesCopy = copyValues(); valuesCopy.add(value); Collections.addAll(valuesCopy, furtherValues); return of(valuesCopy); }
@Override public ImmutableJsonArray add(final int value, final int... furtherValues) { checkFurtherValues(furtherValues); return add(JsonFactory.newValue(value), Arrays.stream(furtherValues) .mapToObj(JsonFactory::newValue) .toArray(JsonValue[]::new)); }
@Override public ImmutableJsonArray add(final JsonValue value, final JsonValue... furtherValues) { checkValue(value); checkFurtherValues(furtherValues); SoftReferencedValueList extendedValueList = valueList.add(value); for (final JsonValue furtherValue : furtherValues) { extendedValueList = extendedValueList.add(furtherValue); } return new ImmutableJsonArray(extendedValueList); }
@Override public ImmutableJsonArray add(final boolean value, final boolean... furtherValues) { checkFurtherValues(furtherValues); final List<JsonValue> valuesCopy = copyValues(); valuesCopy.add(JsonFactory.newValue(value)); for (final boolean furtherValue : furtherValues) { valuesCopy.add(JsonFactory.newValue(furtherValue)); } return of(valuesCopy); }
/** * Returns a new JSON array which is based on the given JSON array of the Minimal Json project library. * * @param values the values to base the JSON array to be created on. * @return a new JSON array. * @throws NullPointerException if {@code values} is {@code null}. */ public static ImmutableJsonArray of(final List<JsonValue> values) { return of(values, null); }
@Override public ImmutableJsonArray add(final boolean value, final boolean... furtherValues) { checkFurtherValues(furtherValues); SoftReferencedValueList extendedValueList = valueList.add(JsonValue.of(value)); for (final boolean furtherValue : furtherValues) { extendedValueList = extendedValueList.add(JsonValue.of(furtherValue)); } return new ImmutableJsonArray(extendedValueList); }
/** * Returns a new empty JSON array. * * @return a new empty JSON array. */ public static JsonArray newArray() { return ImmutableJsonArray.empty(); }
@Override public Iterator<JsonValue> iterator() { final List<JsonValue> valuesCopy = copyValues(); return valuesCopy.iterator(); }
@Override public Stream<JsonValue> stream() { return StreamSupport.stream(spliterator(), false); }
@Override public ImmutableJsonArray add(final int value, final int... furtherValues) { checkFurtherValues(furtherValues); return add(JsonValue.of(value), Arrays.stream(furtherValues) .mapToObj(JsonValue::of) .toArray(JsonValue[]::new)); }
@Override public JsonArray build() { return ImmutableJsonArray.of(values); }
@Override public ImmutableJsonArray add(final double value, final double... furtherValues) { checkFurtherValues(furtherValues); return add(JsonFactory.newValue(value), Arrays.stream(furtherValues) .mapToObj(JsonFactory::newValue) .toArray(JsonValue[]::new)); }
@Override public ImmutableJsonArray add(final String value, final String... furtherValues) { checkValue(value); checkFurtherValues(furtherValues); return add(JsonValue.of(value), Arrays.stream(furtherValues) .map(JsonValue::of) .toArray(JsonValue[]::new)); }
@Override public JsonArray build() { return ImmutableJsonArray.of(values); }
/** * Returns a new empty JSON array. * * @return a new empty JSON array. */ public static ImmutableJsonArray empty() { return new ImmutableJsonArray(Collections.emptyList()); }
@Override public ImmutableJsonArray add(final long value, final long... furtherValues) { checkFurtherValues(furtherValues); return add(JsonValue.of(value), Arrays.stream(furtherValues) .mapToObj(JsonValue::of) .toArray(JsonValue[]::new)); }
@Override public void endArray(final List<JsonValue> jsonValues) { final StringBuilder stringBuilder = stringBuilders.poll(); if (null != stringBuilder) { if (!jsonValues.isEmpty()) { stringBuilder.deleteCharAt(stringBuilder.length() - 1); } stringBuilder.append(']'); valueString = stringBuilder.toString(); } jsonValue = ImmutableJsonArray.of(jsonValues, valueString); }
/** * Returns a new JSON array which is based on the given JSON array of the Minimal Json project library. * * @param values the values to base the JSON array to be created on. * @param stringRepresentation the already known string representation of the returned array or {@code null}. * @return a new JSON array. * @throws NullPointerException if {@code values} is {@code null}. */ public static ImmutableJsonArray of(final List<JsonValue> values, @Nullable final String stringRepresentation) { requireNonNull(values, "The values of the JSON array must not be null!"); return new ImmutableJsonArray(SoftReferencedValueList.of(values, stringRepresentation)); }