Klasse JsonArray

java.lang.Object
com.restfb.json.JsonValue
com.restfb.json.JsonArray
Alle implementierten Schnittstellen:
Serializable, Iterable<JsonValue>

public class JsonArray extends JsonValue implements Iterable<JsonValue>
Represents a JSON array, an ordered collection of JSON values.

Elements can be added using the add(...) methods which accept instances of JsonValue, strings, primitive numbers, and boolean values. To replace an element of an array, use the set(int, ...) methods.

Elements can be accessed by their index using get(int). This class also supports iterating over the elements in document order using an iterator() or an enhanced for loop:

 for (JsonValue value : jsonArray) {
   ...
 }
 

An equivalent List can be obtained from the method values().

Note that this class is not thread-safe. If multiple threads access a JsonArray instance concurrently, while at least one of these threads modifies the contents of this array, access to the instance must be synchronized externally. Failure to do so may lead to an inconsistent state.

This class is not supposed to be extended by clients.

Siehe auch:
  • Feldübersicht

    Von Klasse geerbte Felder com.restfb.json.JsonValue

    ARRAY_IS_NULL, NAME_IS_NULL, OBJECT_IS_NULL, STRING_IS_NULL, VALUE_IS_NULL
  • Konstruktorübersicht

    Konstruktoren
    Konstruktor
    Beschreibung
    Creates a new empty JsonArray.
    Creates a new JsonArray with the contents of the specified JSON array.
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    add(boolean value)
    Appends the JSON representation of the specified boolean value to the end of this array.
    add(double value)
    Appends the JSON representation of the specified double value to the end of this array.
    add(float value)
    Appends the JSON representation of the specified float value to the end of this array.
    add(int value)
    Appends the JSON representation of the specified int value to the end of this array.
    add(long value)
    Appends the JSON representation of the specified long value to the end of this array.
    add(JsonValue value)
    Appends the specified JSON value to the end of this array.
    add(String value)
    Appends the JSON representation of the specified string to the end of this array.
    Returns this JSON value as JsonArray, assuming that this value represents a JSON array.
    boolean
    equals(Object object)
    Indicates whether a given object is "equal to" this JsonArray.
    get(int index)
    Returns the value of the element at the specified position in this array.
    int
     
    boolean
    Detects whether this value represents a JSON array.
    boolean
    Returns true if this array contains no elements.
    Returns an iterator over the values of this array in document order.
    remove(int index)
    Removes the element at the specified index from this array.
    set(int index, boolean value)
    Replaces the element at the specified position in this array with the JSON representation of the specified boolean value.
    set(int index, double value)
    Replaces the element at the specified position in this array with the JSON representation of the specified double value.
    set(int index, float value)
    Replaces the element at the specified position in this array with the JSON representation of the specified float value.
    set(int index, int value)
    Replaces the element at the specified position in this array with the JSON representation of the specified int value.
    set(int index, long value)
    Replaces the element at the specified position in this array with the JSON representation of the specified long value.
    set(int index, JsonValue value)
    Replaces the element at the specified position in this array with the specified JSON value.
    set(int index, String value)
    Replaces the element at the specified position in this array with the JSON representation of the specified string.
    int
    Returns the number of elements in this array.
    static JsonArray
    Returns an unmodifiable wrapper for the specified JsonArray.
    Returns a list of the values in this array in document order.
     

    Von Klasse geerbte Methoden java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Von Schnittstelle geerbte Methoden java.lang.Iterable

    forEach, spliterator
  • Konstruktordetails

    • JsonArray

      public JsonArray()
      Creates a new empty JsonArray.
    • JsonArray

      public JsonArray(JsonArray array)
      Creates a new JsonArray with the contents of the specified JSON array.
      Parameter:
      array - the JsonArray to get the initial contents from, must not be null
  • Methodendetails

    • unmodifiableArray

      public static JsonArray unmodifiableArray(JsonArray array)
      Returns an unmodifiable wrapper for the specified JsonArray. This method allows to provide read-only access to a JsonArray.

      The returned JsonArray is backed by the given array and reflects subsequent changes. Attempts to modify the returned JsonArray result in an UnsupportedOperationException.

      Parameter:
      array - the JsonArray for which an unmodifiable JsonArray is to be returned
      Gibt zurück:
      an unmodifiable view of the specified JsonArray
    • add

      public JsonArray add(int value)
      Appends the JSON representation of the specified int value to the end of this array.
      Parameter:
      value - the value to add to the array
      Gibt zurück:
      the array itself, to enable method chaining
    • add

      public JsonArray add(long value)
      Appends the JSON representation of the specified long value to the end of this array.
      Parameter:
      value - the value to add to the array
      Gibt zurück:
      the array itself, to enable method chaining
    • add

      public JsonArray add(float value)
      Appends the JSON representation of the specified float value to the end of this array.
      Parameter:
      value - the value to add to the array
      Gibt zurück:
      the array itself, to enable method chaining
    • add

      public JsonArray add(double value)
      Appends the JSON representation of the specified double value to the end of this array.
      Parameter:
      value - the value to add to the array
      Gibt zurück:
      the array itself, to enable method chaining
    • add

      public JsonArray add(boolean value)
      Appends the JSON representation of the specified boolean value to the end of this array.
      Parameter:
      value - the value to add to the array
      Gibt zurück:
      the array itself, to enable method chaining
    • add

      public JsonArray add(String value)
      Appends the JSON representation of the specified string to the end of this array.
      Parameter:
      value - the string to add to the array
      Gibt zurück:
      the array itself, to enable method chaining
    • add

      public JsonArray add(JsonValue value)
      Appends the specified JSON value to the end of this array.
      Parameter:
      value - the JsonValue to add to the array, must not be null
      Gibt zurück:
      the array itself, to enable method chaining
    • set

      public JsonArray set(int index, int value)
      Replaces the element at the specified position in this array with the JSON representation of the specified int value.
      Parameter:
      index - the index of the array element to replace
      value - the value to be stored at the specified array position
      Gibt zurück:
      the array itself, to enable method chaining
      Löst aus:
      IndexOutOfBoundsException - if the index is out of range, i.e. index < 0 or index >= size
    • set

      public JsonArray set(int index, long value)
      Replaces the element at the specified position in this array with the JSON representation of the specified long value.
      Parameter:
      index - the index of the array element to replace
      value - the value to be stored at the specified array position
      Gibt zurück:
      the array itself, to enable method chaining
      Löst aus:
      IndexOutOfBoundsException - if the index is out of range, i.e. index < 0 or index >= size
    • set

      public JsonArray set(int index, float value)
      Replaces the element at the specified position in this array with the JSON representation of the specified float value.
      Parameter:
      index - the index of the array element to replace
      value - the value to be stored at the specified array position
      Gibt zurück:
      the array itself, to enable method chaining
      Löst aus:
      IndexOutOfBoundsException - if the index is out of range, i.e. index < 0 or index >= size
    • set

      public JsonArray set(int index, double value)
      Replaces the element at the specified position in this array with the JSON representation of the specified double value.
      Parameter:
      index - the index of the array element to replace
      value - the value to be stored at the specified array position
      Gibt zurück:
      the array itself, to enable method chaining
      Löst aus:
      IndexOutOfBoundsException - if the index is out of range, i.e. index < 0 or index >= size
    • set

      public JsonArray set(int index, boolean value)
      Replaces the element at the specified position in this array with the JSON representation of the specified boolean value.
      Parameter:
      index - the index of the array element to replace
      value - the value to be stored at the specified array position
      Gibt zurück:
      the array itself, to enable method chaining
      Löst aus:
      IndexOutOfBoundsException - if the index is out of range, i.e. index < 0 or index >= size
    • set

      public JsonArray set(int index, String value)
      Replaces the element at the specified position in this array with the JSON representation of the specified string.
      Parameter:
      index - the index of the array element to replace
      value - the string to be stored at the specified array position
      Gibt zurück:
      the array itself, to enable method chaining
      Löst aus:
      IndexOutOfBoundsException - if the index is out of range, i.e. index < 0 or index >= size
    • set

      public JsonArray set(int index, JsonValue value)
      Replaces the element at the specified position in this array with the specified JSON value.
      Parameter:
      index - the index of the array element to replace
      value - the value to be stored at the specified array position, must not be null
      Gibt zurück:
      the array itself, to enable method chaining
      Löst aus:
      IndexOutOfBoundsException - if the index is out of range, i.e. index < 0 or index >= size
    • remove

      public JsonArray remove(int index)
      Removes the element at the specified index from this array.
      Parameter:
      index - the index of the element to remove
      Gibt zurück:
      the array itself, to enable method chaining
      Löst aus:
      IndexOutOfBoundsException - if the index is out of range, i.e. index < 0 or index >= size
    • size

      public int size()
      Returns the number of elements in this array.
      Gibt zurück:
      the number of elements in this array
    • isEmpty

      public boolean isEmpty()
      Returns true if this array contains no elements.
      Gibt zurück:
      true if this array contains no elements
    • get

      public JsonValue get(int index)
      Returns the value of the element at the specified position in this array.
      Parameter:
      index - the index of the array element to return
      Gibt zurück:
      the value of the element at the specified position
      Löst aus:
      IndexOutOfBoundsException - if the index is out of range, i.e. index < 0 or index >= size
    • values

      public List<JsonValue> values()
      Returns a list of the values in this array in document order. The returned list is backed by this array and will reflect subsequent changes. It cannot be used to modify this array. Attempts to modify the returned list will result in an exception.
      Gibt zurück:
      a list of the values in this array
    • valueStream

    • iterator

      Returns an iterator over the values of this array in document order. The returned iterator cannot be used to modify this array.
      Angegeben von:
      iterator in Schnittstelle Iterable<JsonValue>
      Gibt zurück:
      an iterator over the values of this array
    • isArray

      public boolean isArray()
      Beschreibung aus Klasse kopiert: JsonValue
      Detects whether this value represents a JSON array. If this is the case, this value is an instance of JsonArray.
      Setzt außer Kraft:
      isArray in Klasse JsonValue
      Gibt zurück:
      true if this value is an instance of JsonArray
    • asArray

      public JsonArray asArray()
      Beschreibung aus Klasse kopiert: JsonValue
      Returns this JSON value as JsonArray, assuming that this value represents a JSON array. If this is not the case, an exception is thrown.
      Setzt außer Kraft:
      asArray in Klasse JsonValue
      Gibt zurück:
      a JSONArray for this value
    • hashCode

      public int hashCode()
      Setzt außer Kraft:
      hashCode in Klasse JsonValue
    • equals

      public boolean equals(Object object)
      Indicates whether a given object is "equal to" this JsonArray. An object is considered equal if it is also a JsonArray and both arrays contain the same list of values.

      If two JsonArrays are equal, they will also produce the same JSON output.

      Setzt außer Kraft:
      equals in Klasse JsonValue
      Parameter:
      object - the object to be compared with this JsonArray
      Gibt zurück:
      true if the specified object is equal to this JsonArray, false otherwise