Class JSONArrayImpl

java.lang.Object
org.tquadrat.foundation.jsonbuilder.internal.JSONArrayImpl
All Implemented Interfaces:
Iterable<JSONValue>, Formattable, JSONArray, JSONValue

@ClassVersion(sourceVersion="$Id: JSONArrayImpl.java 1195 2026-04-15 21:33:40Z tquadrat $") @API(status=INTERNAL, since="0.25.0") public final class JSONArrayImpl extends Object implements JSONArray

The implementation for the interface JSONArray.

Author:
Thomas Thrien (thomas.thrien@tquadrat.org)
Version:
$Id: JSONArrayImpl.java 1195 2026-04-15 21:33:40Z tquadrat $
Since:
0.25.0
UML Diagram
UML Diagram for "org.tquadrat.foundation.jsonbuilder.internal.JSONArrayImpl"

UML Diagram for "org.tquadrat.foundation.jsonbuilder.internal.JSONArrayImpl"

UML Diagram for "org.tquadrat.foundation.jsonbuilder.internal.JSONArrayImpl"
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final JSONBuilderImpl
    The reference to the JSONBuilder that was used to create this JSONObject, and that is used to create the members.
    private final List<JSONValue>
    The elements for this JSONArray instance.
  • Constructor Summary

    Constructors
    Constructor
    Description
    {summary Creates a new instance of JSONArrayImpl from the given other array.}
    Creates a new instance of JSONArrayImpl.
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    add(double value)
    Appends the given value as a new element to the end of this array.
    final void
    add(float value)
    Appends the given value as a new element to the end of this array.
    final void
    add(int value)
    Appends the given value as a new element to the end of this array.
    final void
    add(int index, double value)
    Inserts the given value as a new element to the given postion of this array and moves the other elements to a by one higher index.
    final void
    add(int index, float value)
    Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.
    final void
    add(int index, int value)
    Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.
    final void
    add(int index, long value)
    Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.
    final void
    add(int index, Double value)
    Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.
    final void
    add(int index, Float value)
    Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.
    final void
    add(int index, Integer value)
    Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.
    final void
    add(int index, Long value)
    Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.
    final void
    add(int index, String value)
    Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.
    final void
    add(int index, BigDecimal value)
    Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.
    final void
    add(int index, BigInteger value)
    Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.
    final void
    add(int index, JSONValue value)
    Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.
    final <T extends Dimension>
    void
    add(int index, DimensionedValue<T> value, T targetUnit)
    Inserts the given value as a new element to the given postion of this array and moves the other elements to a by one higher index.
    final void
    add(long value)
    Appends the given value as a new element to the end of this array.
    final void
    add(Double value)
    Appends the given value as a new element to the end of this array.
    final void
    add(Float value)
    Appends the given value as a new element to the end of this array.
    final void
    add(Integer value)
    Appends the given value as a new element to the end of this array.
    final void
    add(Long value)
    Appends the given value as a new element to the end of this array.
    final void
    add(String value)
    Appends the given value as a new element to the end of this array.
    final void
    add(BigDecimal value)
    Appends the given value as a new element to the end of this array.
    final void
    add(BigInteger value)
    Appends the given value as a new element to the end of this array.
    final void
    add(JSONValue value)
    Appends the given value as a new element to the end of this array.
    final <T extends Dimension>
    void
    add(DimensionedValue<T> value, T targetUnit)
    Appends the given value as a new element to the end of this array.
    final boolean
    Appends the given array to this one.
    final JSONArray
    Adds a new empty instance of JSONArray to this array and returns that.
    addArray(int index)
    Adds a new empty instance of JSONArray to this array at the given index and returns that.
    Adds a new empty instance of JSONObject to this array and returns that.
    addObject(int index)
    Adds a new empty instance of JSONObject to this array at the given index and returns that.
    final boolean
    void
    formatTo(Formatter formatter, int flags, int width, int precision)
    final JSONValue
    get(int index)
    Returns the value of the element at the specied index in this array.
    final int
    final boolean
    Checks whether this array has elements.
    final void
    remove(int index)
    Removes the element with the specified index from this array.
    final void
    remove(JSONValue element)
    Removes the first occurrence of the specified element from this array, if it is present.
    void
    set(int index, double value)
    Sets the value of the element with the specified index to the JSON representation of the specified double value.
    void
    set(int index, float value)
    Sets the value of the element with the specified index to the JSON representation of the specified float value.
    void
    set(int index, int value)
    Sets the value of the element with the specified index to the JSON representation of the specified int value.
    void
    set(int index, long value)
    Sets the value of the element with the specified index to the JSON representation of the specified long value.
    void
    set(int index, Double value)
    Sets the value of the element with the specified index to the JSON representation of the specified Double value.
    void
    set(int index, Float value)
    Sets the value of the element with the specified index to the JSON representation of the specified Float value.
    void
    set(int index, Integer value)
    Sets the value of the element with the specified index to the JSON representation of the specified Integer value.
    void
    set(int index, Long value)
    Sets the value of the element with the specified index to the JSON representation of the specified Long value.
    void
    set(int index, String value)
    Sets the value of the element with the specified index to the JSON representation of the specified String value.
    final void
    set(int index, BigDecimal value)
    Sets the value of the element with the specified index to the JSON representation of the specified BigDecimal value.
    void
    set(int index, BigInteger value)
    Sets the value of the element with the specified index to the JSON representation of the specified BigInteger value.
    final void
    set(int index, JSONValue value)
    Sets the value of the element with the specified index to the given JSONValue instance.
    <T extends Dimension>
    void
    set(int index, DimensionedValue<T> value, T targetUnit)
    Sets the value of the element with the specified index to the JSON representation of the specified DimensionedValue value.
    final JSONArray
    setArray(int index)
    Sets a new empty instance of JSONArray to this array at the given index and returns that.
    setObject(int index)
    Sets a new empty instance of JSONObject to this array at the given index and returns that.
    final int
    Returns the number of elements for this array.
    final String

    Methods inherited from class Object

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

    Methods inherited from interface Iterable

    forEach, spliterator
  • Field Details

  • Constructor Details

    • JSONArrayImpl

      public JSONArrayImpl(JSONBuilderImpl builder)
      Creates a new instance of JSONArrayImpl.
      Parameters:
      builder - The reference to the JSONBuilder.
    • JSONArrayImpl

      {summary Creates a new instance of JSONArrayImpl from the given other array.}

      The new array is a deep copy of the given instance.

      Parameters:
      other - The other JSON array.
  • Method Details

    • add

      public final void add(BigDecimal value)

      Appends the given value as a new element to the end of this array.

      Specified by:
      add in interface JSONArray
      Parameters:
      value - The value to add.
    • add

      public final void add(BigInteger value)

      Appends the given value as a new element to the end of this array.

      Specified by:
      add in interface JSONArray
      Parameters:
      value - The value to add.
    • add

      public final <T extends Dimension> void add(DimensionedValue<T> value, T targetUnit)

      Appends the given value as a new element to the end of this array.

      Specified by:
      add in interface JSONArray
      Type Parameters:
      T - The type of the dimension for the value.
      Parameters:
      value - The value.
      targetUnit - The dimension for the output.
      See Also:
    • add

      public final void add(double value)

      Appends the given value as a new element to the end of this array.

      Specified by:
      add in interface JSONArray
      Parameters:
      value - The value to add.
    • add

      public final void add(Double value)

      Appends the given value as a new element to the end of this array.

      Specified by:
      add in interface JSONArray
      Parameters:
      value - The value to add.
    • add

      public final void add(float value)

      Appends the given value as a new element to the end of this array.

      Specified by:
      add in interface JSONArray
      Parameters:
      value - The value to add.
    • add

      public final void add(Float value)

      Appends the given value as a new element to the end of this array.

      Specified by:
      add in interface JSONArray
      Parameters:
      value - The value to add.
    • add

      public final void add(int value)

      Appends the given value as a new element to the end of this array.

      Specified by:
      add in interface JSONArray
      Parameters:
      value - The value to add.
    • add

      public final void add(Integer value)

      Appends the given value as a new element to the end of this array.

      Specified by:
      add in interface JSONArray
      Parameters:
      value - The value to add.
    • add

      public final void add(JSONValue value)

      Appends the given value as a new element to the end of this array.

      Specified by:
      add in interface JSONArray
      Parameters:
      value - The value to add.
    • add

      public final void add(long value)

      Appends the given value as a new element to the end of this array.

      Specified by:
      add in interface JSONArray
      Parameters:
      value - The value to add.
    • add

      public final void add(Long value)

      Appends the given value as a new element to the end of this array.

      Specified by:
      add in interface JSONArray
      Parameters:
      value - The value to add.
    • add

      public final void add(String value)

      Appends the given value as a new element to the end of this array.

      Specified by:
      add in interface JSONArray
      Parameters:
      value - The value to add.
    • add

      public final void add(int index, BigDecimal value) throws IndexOutOfBoundsException

      Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.

      If index is equals to the size of the array, the element is appended to the end of the array.

      Specified by:
      add in interface JSONArray
      Parameters:
      index - The index.
      value - The value to add.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • add

      public final void add(int index, BigInteger value) throws IndexOutOfBoundsException

      Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.

      If index is equals to the size of the array, the element is appended to the end of the array.

      Specified by:
      add in interface JSONArray
      Parameters:
      index - The index.
      value - The value to add.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • add

      public final <T extends Dimension> void add(int index, DimensionedValue<T> value, T targetUnit) throws IndexOutOfBoundsException

      Inserts the given value as a new element to the given postion of this array and moves the other elements to a by one higher index.

      If index is equals to the size of the array, the element is appended to the end of the array.

      Specified by:
      add in interface JSONArray
      Type Parameters:
      T - The type of the dimension for the value.
      Parameters:
      index - The index.
      value - The value.
      targetUnit - The dimension for the output.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
      See Also:
    • add

      public final void add(int index, double value) throws IndexOutOfBoundsException

      Inserts the given value as a new element to the given postion of this array and moves the other elements to a by one higher index.

      If index is equals to the size of the array, the element is appended to the end of the array.

      Specified by:
      add in interface JSONArray
      Parameters:
      index - The index.
      value - The value to add.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • add

      public final void add(int index, Double value) throws IndexOutOfBoundsException

      Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.

      If index is equals to the size of the array, the element is appended to the end of the array.

      Specified by:
      add in interface JSONArray
      Parameters:
      index - The index.
      value - The value to add.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • add

      public final void add(int index, float value) throws IndexOutOfBoundsException

      Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.

      If index is equals to the size of the array, the element is appended to the end of the array.

      Specified by:
      add in interface JSONArray
      Parameters:
      index - The index.
      value - The value to add.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • add

      public final void add(int index, Float value) throws IndexOutOfBoundsException

      Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.

      If index is equals to the size of the array, the element is appended to the end of the array.

      Specified by:
      add in interface JSONArray
      Parameters:
      index - The index.
      value - The value to add.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • add

      public final void add(int index, int value) throws IndexOutOfBoundsException

      Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.

      If index is equals to the size of the array, the element is appended to the end of the array.

      Specified by:
      add in interface JSONArray
      Parameters:
      index - The index.
      value - The value to add.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • add

      public final void add(int index, Integer value) throws IndexOutOfBoundsException

      Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.

      If index is equals to the size of the array, the element is appended to the end of the array.

      Specified by:
      add in interface JSONArray
      Parameters:
      index - The index.
      value - The value to add.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • add

      public final void add(int index, JSONValue value) throws IndexOutOfBoundsException

      Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.

      If index is equals to the size of the array, the element is appended to the end of the array.

      Specified by:
      add in interface JSONArray
      Parameters:
      index - The index.
      value - The value to add.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • add

      public final void add(int index, long value) throws IndexOutOfBoundsException

      Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.

      If index is equals to the size of the array, the element is appended to the end of the array.

      Specified by:
      add in interface JSONArray
      Parameters:
      index - The index.
      value - The value to add.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • add

      public final void add(int index, Long value) throws IndexOutOfBoundsException

      Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.

      If index is equals to the size of the array, the element is appended to the end of the array.

      Specified by:
      add in interface JSONArray
      Parameters:
      index - The index.
      value - The value to add.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • add

      public final void add(int index, String value) throws IndexOutOfBoundsException

      Inserts the given value as a new element to the given postion this array and moves the other elements to a by one higher index.

      If index is equals to the size of the array, the element is appended to the end of the array.

      Specified by:
      add in interface JSONArray
      Parameters:
      index - The index.
      value - The value to add.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • addAll

      public final boolean addAll(JSONArray array)

      Appends the given array to this one. This mean that the elements of the given array are added to this one.

      Specified by:
      addAll in interface JSONArray
      Parameters:
      array - The other array.
      Returns:
      true if the call to this method changed this instance.
    • addArray

      public final JSONArray addArray()

      Adds a new empty instance of JSONArray to this array and returns that.

      Specified by:
      addArray in interface JSONArray
      Returns:
      The freshly created JSONArray.
    • addArray

      public JSONArray addArray(int index) throws IndexOutOfBoundsException

      Adds a new empty instance of JSONArray to this array at the given index and returns that.

      Specified by:
      addArray in interface JSONArray
      Parameters:
      index - The index.
      Returns:
      The freshly created JSONArray.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • addObject

      Adds a new empty instance of JSONObject to this array and returns that.

      Specified by:
      addObject in interface JSONArray
      Returns:
      The freshly created JSONObject.
    • addObject

      public JSONObject addObject(int index) throws IndexOutOfBoundsException

      Adds a new empty instance of JSONObject to this array at the given index and returns that.

      Specified by:
      addObject in interface JSONArray
      Parameters:
      index - The index.
      Returns:
      The freshly created JSONObject.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than the size of the array.
    • equals

      public final boolean equals(Object o)
      Overrides:
      equals in class Object
    • formatTo

      public void formatTo(Formatter formatter, int flags, int width, int precision)
      Specified by:
      formatTo in interface Formattable
      Specified by:
      formatTo in interface JSONValue
    • get

      public final JSONValue get(int index) throws IndexOutOfBoundsException

      Returns the value of the element at the specied index in this array.

      Specified by:
      get in interface JSONArray
      Parameters:
      index - The index of the element whose value is to be returned.
      Returns:
      The element; will never be null.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • isEmpty

      public final boolean isEmpty()
      Checks whether this array has elements.
      Specified by:
      isEmpty in interface JSONArray
      Returns:
      true if the object does not have any elements, false otherwise.
    • iterator

      public final Iterator<JSONValue> iterator()
      Specified by:
      iterator in interface Iterable<JSONValue>
    • remove

      public final void remove(int index) throws IndexOutOfBoundsException

      Removes the element with the specified index from this array.

      Specified by:
      remove in interface JSONArray
      Parameters:
      index - The index of the element to remove.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • remove

      public final void remove(JSONValue element) throws IndexOutOfBoundsException

      Removes the first occurrence of the specified element from this array, if it is present. If this list does not contain the element, it remains unchanged.

      More formally, this method removes the element with the lowest index i such that Objects.equals(o, get(i)) (if such an element exists).

      Specified by:
      remove in interface JSONArray
      Parameters:
      element - The element to remove.
      Throws:
      IndexOutOfBoundsException
    • set

      public final void set(int index, BigDecimal value) throws IndexOutOfBoundsException

      Sets the value of the element with the specified index to the JSON representation of the specified BigDecimal value.

      Specified by:
      set in interface JSONArray
      Parameters:
      index - The index of the element to replace.
      value - The value to set to the member.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • set

      public void set(int index, BigInteger value) throws IndexOutOfBoundsException

      Sets the value of the element with the specified index to the JSON representation of the specified BigInteger value.

      Specified by:
      set in interface JSONArray
      Parameters:
      index - The index of the element to replace.
      value - The value to set to the member.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • set

      public <T extends Dimension> void set(int index, DimensionedValue<T> value, T targetUnit) throws IndexOutOfBoundsException

      Sets the value of the element with the specified index to the JSON representation of the specified DimensionedValue value.

      Specified by:
      set in interface JSONArray
      Type Parameters:
      T - The type of the dimension for the value.
      Parameters:
      index - The index.
      value - The value.
      targetUnit - The dimension for the output.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
      See Also:
    • set

      public void set(int index, double value) throws IndexOutOfBoundsException

      Sets the value of the element with the specified index to the JSON representation of the specified double value.

      Specified by:
      set in interface JSONArray
      Parameters:
      index - The index of the element to replace.
      value - The value to set to the member.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • set

      public void set(int index, Double value) throws IndexOutOfBoundsException

      Sets the value of the element with the specified index to the JSON representation of the specified Double value.

      Specified by:
      set in interface JSONArray
      Parameters:
      index - The index of the element to replace.
      value - The value to set to the member.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • set

      public void set(int index, float value) throws IndexOutOfBoundsException

      Sets the value of the element with the specified index to the JSON representation of the specified float value.

      Specified by:
      set in interface JSONArray
      Parameters:
      index - The index of the element to replace.
      value - The value to set to the member.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • set

      public void set(int index, Float value) throws IndexOutOfBoundsException

      Sets the value of the element with the specified index to the JSON representation of the specified Float value.

      Specified by:
      set in interface JSONArray
      Parameters:
      index - The index of the element to replace.
      value - The value to set to the member.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • set

      public void set(int index, int value) throws IndexOutOfBoundsException

      Sets the value of the element with the specified index to the JSON representation of the specified int value.

      Specified by:
      set in interface JSONArray
      Parameters:
      index - The index of the element to replace.
      value - The value to set to the member.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • set

      public void set(int index, Integer value) throws IndexOutOfBoundsException

      Sets the value of the element with the specified index to the JSON representation of the specified Integer value.

      Specified by:
      set in interface JSONArray
      Parameters:
      index - The index of the element to replace.
      value - The value to set to the member.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • set

      public final void set(int index, JSONValue value) throws IndexOutOfBoundsException

      Sets the value of the element with the specified index to the given JSONValue instance.

      Specified by:
      set in interface JSONArray
      Parameters:
      index - The index of the element to replace.
      value - The value to set to the member.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • set

      public void set(int index, long value) throws IndexOutOfBoundsException

      Sets the value of the element with the specified index to the JSON representation of the specified long value.

      Specified by:
      set in interface JSONArray
      Parameters:
      index - The index of the element to replace.
      value - The value to set to the member.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • set

      public void set(int index, Long value) throws IndexOutOfBoundsException

      Sets the value of the element with the specified index to the JSON representation of the specified Long value.

      Specified by:
      set in interface JSONArray
      Parameters:
      index - The index of the element to replace.
      value - The value to set to the member.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • set

      public void set(int index, String value) throws IndexOutOfBoundsException

      Sets the value of the element with the specified index to the JSON representation of the specified String value.

      Specified by:
      set in interface JSONArray
      Parameters:
      index - The index of the element to replace.
      value - The value to set to the member.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • setArray

      public final JSONArray setArray(int index) throws IndexOutOfBoundsException

      Sets a new empty instance of JSONArray to this array at the given index and returns that.

      Specified by:
      setArray in interface JSONArray
      Parameters:
      index - The index.
      Returns:
      The freshly created JSONArray.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • setObject

      public final JSONObject setObject(int index) throws IndexOutOfBoundsException

      Sets a new empty instance of JSONObject to this array at the given index and returns that.

      Specified by:
      setObject in interface JSONArray
      Parameters:
      index - The index.
      Returns:
      The freshly created JSONObject.
      Throws:
      IndexOutOfBoundsException - The index is less than 0 or greater than or equal to the size of the array.
    • size

      public final int size()
      Returns the number of elements for this array.
      Specified by:
      size in interface JSONArray
      Returns:
      The number of members in this object.
    • toString

      public final String toString()
      Specified by:
      toString in interface JSONValue
      Overrides:
      toString in class Object