Class JsonArray

java.lang.Object
com.oorian.json.JsonValue
com.oorian.json.JsonArray
All Implemented Interfaces:
Iterable<JsonValue>

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

JsonArray provides methods for storing, retrieving, and iterating over JSON array elements. It supports all JSON value types and provides convenient methods for extracting typed arrays of primitive values.

  • Constructor Details

    • JsonArray

      public JsonArray()
      Creates an empty JsonArray.
    • JsonArray

      public JsonArray(Collection c)
      Creates a JsonArray initialized with the elements from the specified collection.
      Parameters:
      c - the collection of initial elements.
  • Method Details

    • parse

      public static JsonArray parse(String json)
      Parses a JSON string into a JsonArray.
      Parameters:
      json - the JSON string to parse.
      Returns:
      the parsed JsonArray.
    • parseStrings

      public static List<String> parseStrings(String json)
      Parses a JSON array string and returns the elements as a list of Strings.
      Parameters:
      json - the JSON array string to parse.
      Returns:
      the list of String values.
    • parseInts

      public static List<Integer> parseInts(String json)
      Parses a JSON array string and returns the elements as a list of Integers.
      Parameters:
      json - the JSON array string to parse.
      Returns:
      the list of Integer values.
    • parseLongs

      public static List<Long> parseLongs(String json)
      Parses a JSON array string and returns the elements as a list of Longs.
      Parameters:
      json - the JSON array string to parse.
      Returns:
      the list of Long values.
    • parseShorts

      public static List<Short> parseShorts(String json)
      Parses a JSON array string and returns the elements as a list of Shorts.
      Parameters:
      json - the JSON array string to parse.
      Returns:
      the list of Short values.
    • parseFloats

      public static List<Float> parseFloats(String json)
      Parses a JSON array string and returns the elements as a list of Floats.
      Parameters:
      json - the JSON array string to parse.
      Returns:
      the list of Float values.
    • parseDoubles

      public static List<Double> parseDoubles(String json)
      Parses a JSON array string and returns the elements as a list of Doubles.
      Parameters:
      json - the JSON array string to parse.
      Returns:
      the list of Double values.
    • parseBooleans

      public static List<Boolean> parseBooleans(String json)
      Parses a JSON array string and returns the elements as a list of Booleans.
      Parameters:
      json - the JSON array string to parse.
      Returns:
      the list of Boolean values.
    • initialize

      public void initialize(String json)
      Replaces this array's contents by parsing a JSON string.
      Parameters:
      json - the JSON string to parse.
    • add

      public JsonArray add(Object value)
      Adds a value to this array.
      Parameters:
      value - the value to add (automatically wrapped to the appropriate JSON type).
      Returns:
      this JsonArray for method chaining.
    • addAll

      public JsonArray addAll(Collection<? extends Object> values)
      Adds all values from a collection to this array.
      Parameters:
      values - the collection of values to add.
      Returns:
      this JsonArray for method chaining.
    • size

      public int size()
      Returns the number of elements in this array.
      Returns:
      the element count.
    • isEmpty

      public boolean isEmpty()
      Returns true if this array contains no elements.
      Returns:
      true if empty.
    • clear

      public void clear()
      Removes all elements from this array.
    • getAll

      public List<JsonValue> getAll()
      Returns a copy of all elements in this array.
      Returns:
      the list of all JsonValue elements.
    • getStringArray

      public List<String> getStringArray()
      Returns all elements as a list of Strings.
      Returns:
      the list of String values.
    • getBooleanArray

      public List<Boolean> getBooleanArray()
      Returns all elements as a list of Booleans.
      Returns:
      the list of Boolean values.
    • getShortArray

      public List<Short> getShortArray()
      Returns all elements as a list of Shorts.
      Returns:
      the list of Short values.
    • getIntArray

      public List<Integer> getIntArray()
      Returns all elements as a list of Integers.
      Returns:
      the list of Integer values.
    • getLongArray

      public List<Long> getLongArray()
      Returns all elements as a list of Longs.
      Returns:
      the list of Long values.
    • getFloatArray

      public List<Float> getFloatArray()
      Returns all elements as a list of Floats.
      Returns:
      the list of Float values.
    • getDoubleArray

      public List<Double> getDoubleArray()
      Returns all elements as a list of Doubles.
      Returns:
      the list of Double values.
    • getObjectArray

      public List<JsonObject> getObjectArray()
      Returns all elements as a list of JsonObjects.
      Returns:
      the list of JsonObject values.
    • get

      public JsonValue get(int index)
      Returns the element at the specified index.
      Parameters:
      index - the zero-based index.
      Returns:
      the JsonValue at that index.
    • getAsString

      public String getAsString(int index)
      Returns the element at the specified index as a String.
      Parameters:
      index - the zero-based index.
      Returns:
      the String value.
    • getAsBoolean

      public Boolean getAsBoolean(int index)
      Returns the element at the specified index as a Boolean.
      Parameters:
      index - the zero-based index.
      Returns:
      the Boolean value.
    • getAsShort

      public short getAsShort(int index)
      Returns the element at the specified index as a short.
      Parameters:
      index - the zero-based index.
      Returns:
      the short value.
    • getAsInt

      public int getAsInt(int index)
      Returns the element at the specified index as an int.
      Parameters:
      index - the zero-based index.
      Returns:
      the int value.
    • getAsLong

      public long getAsLong(int index)
      Returns the element at the specified index as a long.
      Parameters:
      index - the zero-based index.
      Returns:
      the long value.
    • getAsFloat

      public float getAsFloat(int index)
      Returns the element at the specified index as a float.
      Parameters:
      index - the zero-based index.
      Returns:
      the float value.
    • getAsDouble

      public double getAsDouble(int index)
      Returns the element at the specified index as a double.
      Parameters:
      index - the zero-based index.
      Returns:
      the double value.
    • getAsJsonObject

      public JsonObject getAsJsonObject(int index)
      Returns the element at the specified index as a JsonObject.
      Parameters:
      index - the zero-based index.
      Returns:
      the JsonObject value.
    • getAsJsonArray

      public JsonArray getAsJsonArray(int index)
      Returns the element at the specified index as a JsonArray.
      Parameters:
      index - the zero-based index.
      Returns:
      the JsonArray value.
    • toJsonString

      public String toJsonString()
      Description copied from class: JsonValue
      Returns this value serialized as a JSON string.
      Specified by:
      toJsonString in class JsonValue
      Returns:
      the JSON string representation.
    • iterator

      public Iterator<JsonValue> iterator()
      Specified by:
      iterator in interface Iterable<JsonValue>