Interface JSONArray

All Superinterfaces:
Comparable<JSONNode>, Iterable<JSONValue<?>>, JSONListNode, JSONNode, Serializable

public interface JSONArray
extends JSONListNode
Interface holding an array of JSONValue objects
Author:
jearley
  • Method Details

    • add

      void add​(String string)
      Add a String value to the JSONArray
      Parameters:
      string - the String value.
    • add

      void add​(Boolean bool)
      Add a boolean value
      Parameters:
      bool - the boolean value
    • add

      void add​(Number number)
      Add a number value
      Parameters:
      number - the number value
    • add

      void add​(JSONArray array)
      Add a JSONArray value
      Parameters:
      array - a JSONArrray
    • add

      void add​(JSONObject obj)
      Add a JSONObject value
      Parameters:
      obj - the JSONObject
    • add

      default void add​(JSONNode node)
      Add a JSONNode instance. This will be converted to either a JSONArray or JSONObject on inspection
      Parameters:
      node - the JSONNode
    • getString

      String getString​(int index) throws JSONInvalidValueTypeException
      Get a String value
      Parameters:
      index - the JSONArray index position
      Returns:
      the String value of the array at that index
      Throws:
      JSONInvalidValueTypeException - thrown if value cannot be returned as String
    • getNumber

      Number getNumber​(int index) throws JSONInvalidValueTypeException
      Return a Number value
      Parameters:
      index - the JSONArray index position
      Returns:
      A number
      Throws:
      JSONInvalidValueTypeException - thrown if value cannot be returned as Number
    • getLong

      long getLong​(int index) throws JSONInvalidValueTypeException
      Return a long value
      Parameters:
      index - the JSONArray index position
      Returns:
      a long value
      Throws:
      JSONInvalidValueTypeException - thrown if value cannot be returned as long
    • getInt

      int getInt​(int index) throws JSONInvalidValueTypeException
      Return a integer value
      Parameters:
      index - the JSONArray index position
      Returns:
      a integer value
      Throws:
      JSONInvalidValueTypeException - thrown if value cannot be returned as integer
    • getBoolean

      boolean getBoolean​(int index) throws JSONInvalidValueTypeException
      Return a boolean value
      Parameters:
      index - the JSONArray index position
      Returns:
      a boolean value
      Throws:
      JSONInvalidValueTypeException - thrown if value cannot be returned as long
    • getJSONArray

      JSONArray getJSONArray​(int index) throws JSONInvalidValueTypeException
      Return a JSONArray value
      Parameters:
      index - the JSONArray index position
      Returns:
      a JSONArray value
      Throws:
      JSONInvalidValueTypeException - thrown if value cannot be returned as JSONArray
    • getJSONObject

      JSONObject getJSONObject​(int index) throws JSONInvalidValueTypeException
      Return a JSONOBject value
      Parameters:
      index - the JSONArray index position
      Returns:
      a JSONObject value
      Throws:
      JSONInvalidValueTypeException - thrown if value cannot be returned as JSONObject
    • getValueType

      JSONValueType getValueType​(int index)
      Return the value type for value at the specified index
      Parameters:
      index - the JSONArray index position
      Returns:
      the value type enum value
    • getValue

      default <T> T getValue​(int index)
      Return the value at the specified index
      Parameters:
      index - the JSONArray index position
      Returns:
      the casted value
    • getLastValue

      default <T> T getLastValue()
      Return the last value in the array
      Type Parameters:
      T - The value type
      Returns:
      the last value in the array, or null if the array is empty
    • getFirstValue

      default <T> T getFirstValue()
      Return the first value in the array
      Type Parameters:
      T - the value type
      Returns:
      the first value in the array, or null if the array is empty
    • merge

      default void merge​(JSONArray secondary, ArrayConflict arrayConflict, ObjectConflict objectConflict)
      Merge another JSONArray into this instance.

      HERE THERE BE DRAGONS: Once the merge happens, the original Node value is replaced. Know your data

      Parameters:
      secondary - the other JSONArray instance to merge
      arrayConflict - the Array Conflict Strategy to use
      objectConflict - the Object Conflict Strategy to use
    • mergeToCopy

      default JSONArray mergeToCopy​(JSONArray secondary, ArrayConflict arrayConflict, ObjectConflict objectConflict)
      Merge the current JSONArray instance with another and return the merged instance. The original instance is left in its original state.
      Parameters:
      secondary - the other JSONArray instance to merge
      arrayConflict - the Array Conflict Strategy to use
      objectConflict - the Object Conflict Strategy to use
      Returns: