Module jakarta.json
Package jakarta.json

Class EmptyArray

All Implemented Interfaces:
JsonArray, JsonStructure, JsonValue, Serializable, Iterable<JsonValue>, Collection<JsonValue>, List<JsonValue>, RandomAccess, SequencedCollection<JsonValue>

final class EmptyArray extends AbstractList<JsonValue> implements JsonArray, Serializable, RandomAccess
Private implementation of immutable JsonArray.
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      for serialization
      See Also:
  • Constructor Details

    • EmptyArray

      EmptyArray()
      Default constructor.
  • Method Details

    • get

      public JsonValue get(int index)
      Specified by:
      get in interface List<JsonValue>
      Specified by:
      get in class AbstractList<JsonValue>
    • size

      public int size()
      Specified by:
      size in interface Collection<JsonValue>
      Specified by:
      size in interface List<JsonValue>
      Specified by:
      size in class AbstractCollection<JsonValue>
    • getJsonObject

      public JsonObject getJsonObject(int index)
      Description copied from interface: JsonArray
      Returns the object value at the specified position in this array. This is a convenience method for (JsonObject)get(index).
      Specified by:
      getJsonObject in interface JsonArray
      Parameters:
      index - index of the value to be returned
      Returns:
      the value at the specified position in this array
    • getJsonArray

      public JsonArray getJsonArray(int index)
      Description copied from interface: JsonArray
      Returns the array value at the specified position in this array. This is a convenience method for (JsonArray)get(index).
      Specified by:
      getJsonArray in interface JsonArray
      Parameters:
      index - index of the value to be returned
      Returns:
      the value at the specified position in this array
    • getJsonNumber

      public JsonNumber getJsonNumber(int index)
      Description copied from interface: JsonArray
      Returns the number value at the specified position in this array. This is a convenience method for (JsonNumber)get(index).
      Specified by:
      getJsonNumber in interface JsonArray
      Parameters:
      index - index of the value to be returned
      Returns:
      the value at the specified position in this array
    • getJsonString

      public JsonString getJsonString(int index)
      Description copied from interface: JsonArray
      Returns the string value at ths specified position in this array. This is a convenience method for (JsonString)get(index).
      Specified by:
      getJsonString in interface JsonArray
      Parameters:
      index - index of the value to be returned
      Returns:
      the value at the specified position in this array
    • getValuesAs

      public <T extends JsonValue> List<T> getValuesAs(Class<T> clazz)
      Description copied from interface: JsonArray
      Returns a list view of the specified type for the array. This method does not verify if there is a value of wrong type in the array. Providing this typesafe view dynamically may cause a program fail with a ClassCastException, if there is a value of wrong type in this array. Unfortunately, the exception can occur at any time after this method returns.
      Specified by:
      getValuesAs in interface JsonArray
      Type Parameters:
      T - The type of the List for the array
      Parameters:
      clazz - a JsonValue type
      Returns:
      a list view of the specified type
    • getString

      public String getString(int index)
      Description copied from interface: JsonArray
      A convenience method for getJsonString(index).getString().
      Specified by:
      getString in interface JsonArray
      Parameters:
      index - index of the JsonString value
      Returns:
      the String value at the specified position
    • getString

      public String getString(int index, String defaultValue)
      Description copied from interface: JsonArray
      Returns the String value of JsonString at the specified position in this JSON array values. If JsonString is found, its JsonString.getString() is returned. Otherwise, the specified default value is returned.
      Specified by:
      getString in interface JsonArray
      Parameters:
      index - index of the JsonString value
      defaultValue - the String to return if the JsonValue at the specified position is not a JsonString
      Returns:
      the String value at the specified position in this array, or the specified default value
    • getInt

      public int getInt(int index)
      Description copied from interface: JsonArray
      A convenience method for getJsonNumber(index).intValue().
      Specified by:
      getInt in interface JsonArray
      Parameters:
      index - index of the JsonNumber value
      Returns:
      the int value at the specified position
    • getInt

      public int getInt(int index, int defaultValue)
      Description copied from interface: JsonArray
      Returns the int value of the JsonNumber at the specified position. If the value at that position is a JsonNumber, this method returns JsonNumber.intValue(). Otherwise this method returns the specified default value.
      Specified by:
      getInt in interface JsonArray
      Parameters:
      index - index of the JsonNumber value
      defaultValue - the int value to return if the JsonValue at the specified position is not a JsonNumber
      Returns:
      the int value at the specified position in this array, or the specified default value
    • getBoolean

      public boolean getBoolean(int index)
      Description copied from interface: JsonArray
      Returns the boolean value at the specified position. If the value at the specified position is JsonValue.TRUE this method returns true. If the value at the specified position is JsonValue.FALSE this method returns false.
      Specified by:
      getBoolean in interface JsonArray
      Parameters:
      index - index of the JSON boolean value
      Returns:
      the boolean value at the specified position
    • getBoolean

      public boolean getBoolean(int index, boolean defaultValue)
      Description copied from interface: JsonArray
      Returns the boolean value at the specified position. If the value at the specified position is JsonValue.TRUE this method returns true. If the value at the specified position is JsonValue.FALSE this method returns false. Otherwise this method returns the specified default value.
      Specified by:
      getBoolean in interface JsonArray
      Parameters:
      index - index of the JSON boolean value
      defaultValue - the boolean value to return if the JsonValue at the specified position is neither TRUE nor FALSE
      Returns:
      the boolean value at the specified position, or the specified default value
    • isNull

      public boolean isNull(int index)
      Description copied from interface: JsonArray
      Returns true if the value at the specified location in this array is JsonValue.NULL.
      Specified by:
      isNull in interface JsonArray
      Parameters:
      index - index of the JSON null value
      Returns:
      return true if the value at the specified location is JsonValue.NULL, otherwise false
    • getValueType

      public JsonValue.ValueType getValueType()
      Description copied from interface: JsonValue
      Returns the value type of this JSON value.
      Specified by:
      getValueType in interface JsonValue
      Returns:
      JSON value type
    • readResolve

      private Object readResolve()
      Preserves singleton property
      Returns:
      JsonValue.EMPTY_JSON_ARRAY