Interface JsonArray

All Superinterfaces:
Iterable<JsonValue>, JsonValue, JsonValueContainer<JsonValue>

public interface JsonArray extends JsonValue, JsonValueContainer<JsonValue>
Represents a JSON array. A JSON array is an ordered collection of JSON values. Duplicate values are permitted.

Implementations of this interface are required to be immutable!

  • Method Details

    • of

      static JsonArray of(String jsonArrayString)
      Creates a new JsonArray from the given string.
      Parameters:
      jsonArrayString - the string that represents the JSON array.
      Returns:
      the JSON array that has been created from the string.
      Throws:
      NullPointerException - if jsonArrayString is null.
      IllegalArgumentException - if jsonArrayString is empty.
      JsonParseException - if jsonArrayString does not represent a valid JSON array.
      See Also:
    • empty

      static JsonArray empty()
      Returns an empty JsonArray object.
      Returns:
      the empty array.
    • of

      static <T> JsonArray of(@Nullable T value, T... furtherValues)
      Returns an instance of JsonArray which contains the given values. This method tries to determine the appropriate JsonValue-counterpart for each given value.
      Type Parameters:
      T - the type of values for JsonArray
      Parameters:
      value - the mandatory value of the returned JsonArray.
      furtherValues - further optional values of the returned JsonArray.
      Returns:
      the JsonArray.
      Throws:
      NullPointerException - if furtherValues is null.
      JsonParseException - if either value or any item of furtherValues cannot be converted to JsonValue.
    • of

      static <T> JsonArray of(Iterable<T> values)
      Returns an instance of JsonArray which contains the given values. This method tries to determine the appropriate JsonValue-counterpart for each item of the specified Iterable.
      Type Parameters:
      T - the type of values for JsonArray
      Parameters:
      values - the values of the returned JsonArray. null items are
      Returns:
      the JsonArray.
      Throws:
      NullPointerException - if values is null.
      JsonParseException - if any item of values cannot be converted to JsonValue.
    • newBuilder

      static JsonArrayBuilder newBuilder()
      Returns a new mutable builder with a fluent API for a JsonArray.
      Returns:
      a new JSON array builder.
    • toBuilder

      default JsonArrayBuilder toBuilder()
      Returns a new mutable builder with a fluent API for a JsonArray. The returned builder is already initialised with the data of the this JSON array. This method is useful if an existing JSON array should be strongly modified but the amount of creating objects should be kept low at the same time.
      Returns:
      a new JSON array builder with pre-filled data of this JSON array.
    • add

      JsonArray add(int value, int... furtherValues)
      Creates a new JSON array by appending the JSON representation of the specified int value to the end of this array.
      Parameters:
      value - the int value to be added to the array.
      furtherValues - additional values to be added to the array.
      Returns:
      the a new JSON array which differs from this array by containing the specified value at its end.
      Throws:
      NullPointerException - if furtherValues is null.
    • add

      JsonArray add(long value, long... furtherValues)
      Creates a new JSON array by appending the JSON representation of the specified long value to the end of this array.
      Parameters:
      value - the long value to be added to the array.
      furtherValues - additional values to be added to the array.
      Returns:
      the a new JSON array which differs from this array by containing the specified value at its end.
      Throws:
      NullPointerException - if furtherValues is null.
    • add

      JsonArray add(double value, double... furtherValues)
      Creates a new JSON array by appending the JSON representation of the specified double value to the end of this array.
      Parameters:
      value - the double value to be added to the array.
      furtherValues - additional values to be added to the array.
      Returns:
      the a new JSON array which differs from this array by containing the specified value at its end.
      Throws:
      NullPointerException - if furtherValues is null.
    • add

      JsonArray add(boolean value, boolean... furtherValues)
      Creates a new JSON array by appending the JSON representation of the specified boolean value to the end of this array.
      Parameters:
      value - the boolean value to be added to the array.
      furtherValues - additional values to be added to the array.
      Returns:
      the a new JSON array which differs from this array by containing the specified value at its end.
      Throws:
      NullPointerException - if furtherValues is null.
    • add

      JsonArray add(String value, String... furtherValues)
      Creates a new JSON array by appending the JSON representation of the specified string value to the end of this array.
      Parameters:
      value - the string to be added to the array.
      furtherValues - additional values to be added to the array.
      Returns:
      the a new JSON array which differs from this array by containing the specified value at its end.
      Throws:
      NullPointerException - if any argument is null.
    • add

      JsonArray add(JsonValue value, JsonValue... furtherValues)
      Creates a new JSON array by appending the specified value to the end of this array.
      Parameters:
      value - the value to be added to the array.
      furtherValues - additional values to be added to the array.
      Returns:
      the a new JSON array which differs from this array by containing the specified value at its end.
      Throws:
      NullPointerException - if any argument is null.
    • get

      Optional<JsonValue> get(int index)
      Returns the JSON value at the specified position in this array.
      Parameters:
      index - the index of the array value to be returned. If the index is out of bounds an empty Optional is returned.
      Returns:
      the JSON value at the specified position.
    • contains

      boolean contains(JsonValue value)
      Indicates whether this JSON array contains the specified value.
      Parameters:
      value - the value whose presence in this array is to be tested.
      Returns:
      true if this array contains the specified value, false else.
      Throws:
      NullPointerException - if value is null.
    • indexOf

      int indexOf(JsonValue value)
      Returns the index of the first occurrence of the specified value in this array, or -1 if this array does not contain the element.
      Parameters:
      value - the value to be searched for.
      Returns:
      the index of the first occurrence of the specified value in this array, or -1 if this array does not contain the value at all.
      Throws:
      NullPointerException - if value is null.