xv.json
Class JSONArray

java.lang.Object
  extended by xv.json.JSONVariant
      extended by xv.json.JSONArray
All Implemented Interfaces:
Iterable<JSONVariant>, Collection<JSONVariant>, List<JSONVariant>

public class JSONArray
extends JSONVariant
implements List<JSONVariant>

Represents a JSON array.

Author:
xv

Constructor Summary
JSONArray()
           
JSONArray(int initialCapacity)
           
 
Method Summary
 void add(int index, JSONVariant element)
           
 boolean add(JSONVariant o)
           
 boolean addAll(Collection<? extends JSONVariant> c)
           
 boolean addAll(int index, Collection<? extends JSONVariant> c)
           
 void clear()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
 boolean equals(Object o)
           
 JSONVariant get(int index)
           
 JSONArray getArray(int index)
          Gets the item at the given index as an array.
 byte getByte(int index)
          Gets the given index as a byte.
 byte getByte(int index, byte defaultValue)
          Gets the given index as a byte.
 double getDouble(int index)
          Gets the given index as a double.
 double getDouble(int index, double defaultValue)
          Gets the given index as a double.
 float getFloat(int index)
          Gets the given index as a float.
 float getFloat(int index, float defaultValue)
          Gets the given index as a float.
 int getInt(int index)
          Gets the given index as an integer.
 int getInt(int index, int defaultValue)
          Gets the given index as an integer.
 long getLong(int index)
          Gets the given index as an integer.
 long getLong(int index, long defaultValue)
          Gets the given index as an integer.
 Number getNumber(int index)
          Gets the item at the given index as a number.
 JSONObject getObject(int index)
          Gets the item at the given index as an object.
 short getShort(int index)
          Gets the given index as a short.
 short getShort(int index, short defaultValue)
          Gets the given index as a short.
 String getString(int index)
          Gets the item at the given index as a string.
 String getType()
          Returns a string description of the type - one of "array", "object", "boolean", "number", or "string".
 int hashCode()
           
 int indexOf(Object o)
           
 boolean isEmpty()
           
 Iterator<JSONVariant> iterator()
           
 int lastIndexOf(Object o)
           
 ListIterator<JSONVariant> listIterator()
           
 ListIterator<JSONVariant> listIterator(int index)
           
 JSONVariant remove(int index)
           
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
 JSONVariant set(int index, JSONVariant element)
           
 int size()
           
 List<JSONVariant> subList(int fromIndex, int toIndex)
           
 Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 
Methods inherited from class xv.json.JSONVariant
toJSON, write
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSONArray

public JSONArray()

JSONArray

public JSONArray(int initialCapacity)
Method Detail

getType

public String getType()
Description copied from class: JSONVariant
Returns a string description of the type - one of "array", "object", "boolean", "number", or "string".

Specified by:
getType in class JSONVariant
Returns:

add

public void add(int index,
                JSONVariant element)
Specified by:
add in interface List<JSONVariant>

add

public boolean add(JSONVariant o)
Specified by:
add in interface Collection<JSONVariant>
Specified by:
add in interface List<JSONVariant>

addAll

public boolean addAll(Collection<? extends JSONVariant> c)
Specified by:
addAll in interface Collection<JSONVariant>
Specified by:
addAll in interface List<JSONVariant>

addAll

public boolean addAll(int index,
                      Collection<? extends JSONVariant> c)
Specified by:
addAll in interface List<JSONVariant>

clear

public void clear()
Specified by:
clear in interface Collection<JSONVariant>
Specified by:
clear in interface List<JSONVariant>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<JSONVariant>
Specified by:
contains in interface List<JSONVariant>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<JSONVariant>
Specified by:
containsAll in interface List<JSONVariant>

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection<JSONVariant>
Specified by:
equals in interface List<JSONVariant>
Overrides:
equals in class Object

get

public JSONVariant get(int index)
Specified by:
get in interface List<JSONVariant>

getString

public String getString(int index)
Gets the item at the given index as a string. If the item isn't a string, this returns null.

Parameters:
index - the index
Returns:
the item at the given index as a string or null if it isn't a string
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getNumber

public Number getNumber(int index)
Gets the item at the given index as a number. If the item isn't a number, this returns null.

Parameters:
index - the index
Returns:
the item at the given index as an object or null if it isn't a number
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getArray

public JSONArray getArray(int index)
Gets the item at the given index as an array. If the item isn't an array, this returns null.

Parameters:
index - the index
Returns:
the item at the given index as an array or null if it isn't an array
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getObject

public JSONObject getObject(int index)
Gets the item at the given index as an object. If the item isn't an object, this returns null.

Parameters:
index - the index
Returns:
the item at the given index as an object or null if it isn't an object
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getByte

public byte getByte(int index,
                    byte defaultValue)
Gets the given index as a byte. If the item isn't a number, this returns the given default.

Parameters:
index - the 0-based index of the item to get as a byte
defaultValue - the value to return if the item at that index is not a number
Returns:
the value as a byte or the default value
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getByte

public byte getByte(int index)
Gets the given index as a byte. If the value is not a number, returns 0.

Parameters:
index - the 0-based index of the item to get as a byte
Returns:
the value as a byte or 0
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getShort

public short getShort(int index,
                      short defaultValue)
Gets the given index as a short.

Parameters:
index -
defaultValue - the value to return if the index is not a number
Returns:
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getShort

public short getShort(int index)
Gets the given index as a short. If the value is not a number, returns 0.

Parameters:
index -
Returns:
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getInt

public int getInt(int index,
                  int defaultValue)
Gets the given index as an integer.

Parameters:
index -
defaultValue - the value to return if the index is not a number
Returns:
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getInt

public int getInt(int index)
Gets the given index as an integer. If the value is not a number, returns 0.

Parameters:
index -
Returns:
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getLong

public long getLong(int index,
                    long defaultValue)
Gets the given index as an integer.

Parameters:
index -
defaultValue - the value to return if the index is not a number
Returns:
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getLong

public long getLong(int index)
Gets the given index as an integer. If the value is not a number, returns 0.

Parameters:
index -
Returns:
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getFloat

public float getFloat(int index,
                      float defaultValue)
Gets the given index as a float.

Parameters:
index -
defaultValue - the value to return if the index is not a number
Returns:
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getFloat

public float getFloat(int index)
Gets the given index as a float. If the value is not a number, returns 0.

Parameters:
index - the index to look up
Returns:
the index value as a float or 0 if it isn't a number
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getDouble

public double getDouble(int index,
                        double defaultValue)
Gets the given index as a double.

Parameters:
index -
defaultValue - the value to return if the index is not a number
Returns:
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

getDouble

public double getDouble(int index)
Gets the given index as a double. If the index does not exist or is not a number, this returns 0.

Parameters:
index - the index to look up
Returns:
the index value as a double or 0 if it isn't a number
Throws:
IndexOutOfBoundsException - if the requested index is outside the range 0 to size() - 1

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<JSONVariant>
Specified by:
hashCode in interface List<JSONVariant>
Overrides:
hashCode in class Object

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List<JSONVariant>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<JSONVariant>
Specified by:
isEmpty in interface List<JSONVariant>

iterator

public Iterator<JSONVariant> iterator()
Specified by:
iterator in interface Iterable<JSONVariant>
Specified by:
iterator in interface Collection<JSONVariant>
Specified by:
iterator in interface List<JSONVariant>

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List<JSONVariant>

listIterator

public ListIterator<JSONVariant> listIterator()
Specified by:
listIterator in interface List<JSONVariant>

listIterator

public ListIterator<JSONVariant> listIterator(int index)
Specified by:
listIterator in interface List<JSONVariant>

remove

public JSONVariant remove(int index)
Specified by:
remove in interface List<JSONVariant>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<JSONVariant>
Specified by:
remove in interface List<JSONVariant>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<JSONVariant>
Specified by:
removeAll in interface List<JSONVariant>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<JSONVariant>
Specified by:
retainAll in interface List<JSONVariant>

set

public JSONVariant set(int index,
                       JSONVariant element)
Specified by:
set in interface List<JSONVariant>

size

public int size()
Specified by:
size in interface Collection<JSONVariant>
Specified by:
size in interface List<JSONVariant>

subList

public List<JSONVariant> subList(int fromIndex,
                                 int toIndex)
Specified by:
subList in interface List<JSONVariant>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<JSONVariant>
Specified by:
toArray in interface List<JSONVariant>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Collection<JSONVariant>
Specified by:
toArray in interface List<JSONVariant>


Copyright © 2008-2011. All Rights Reserved.