org.apache.wink.json4j
Class JSONArray

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList
              extended by org.apache.wink.json4j.JSONArray
All Implemented Interfaces:
Serializable, Cloneable, Iterable, Collection, List, RandomAccess, JSONArtifact

public class JSONArray
extends ArrayList
implements JSONArtifact

Extension of ArrayList that only allows values which are JSON-able. See JSONObject for a list of valid values. Instances of this class are not thread-safe.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
JSONArray()
          Create a new instance of this class.
JSONArray(Collection col)
          Create a new instance of this class based off the contents of the passed in collection
JSONArray(Collection col, boolean includeSuperclass)
          Create a new instance of this class based off the contents of the passed in collection
JSONArray(InputStream is)
          Create a new instance of this class from the data provided from the input stream.
JSONArray(InputStream is, boolean strict)
          Create a new instance of this class from the data provided from the input stream.
JSONArray(int initialCapacity)
          Create a new instance of this class with the specified initial capacity.
JSONArray(Object[] elems)
          Create a new instance of this class based off the contents of the passed object array.
JSONArray(Object[] elems, boolean includeSuperclass)
          Create a new instance of this class based off the contents of the passed object array.
JSONArray(Reader rdr)
          Create a new instance of this class from the data provided from the reader.
JSONArray(Reader rdr, boolean strict)
          Create a new instance of this class from the data provided from the reader.
JSONArray(String str)
          Create a new instance of this class from the provided JSON object string.
JSONArray(String str, boolean strict)
          Create a new instance of this class from the provided JSON object string.
 
Method Summary
 void add(int index, Object element)
           
 boolean add(Object element)
           
 boolean add(Object element, boolean includeSuperclass)
           
 boolean addAll(Collection collection)
           
 boolean addAll(int index, Collection collection)
           
 boolean getBoolean(int index)
          Function to obtain a value at the specified index as a boolean.
 double getDouble(int index)
          Function to obtain a value at the specified index as a double.
 Object getIndex(int index)
          Function to get a JSONArray entry at a specified index.
 int getInt(int index)
          Function to obtain a value at the specified index as an int.
 JSONArray getJSONArray(int index)
          Utility method to obtain the specified index as a JSONArray Only values that are instances of JSONArray will be returned.
 JSONObject getJSONObject(int index)
          Utility method to obtain the specified key as a JSONObject Only values that are instances of JSONObject will be returned.
 long getLong(int index)
          Function to obtain a value at the specified index as a long.
 short getShort(int index)
          Function to obtain a value at the specified index as a short.
 String getString(int index)
          Function to obtain a value at the specified index as a string.
 boolean isNull(int index)
          Utility function for testing if an element at index 'idx' is null or not.
 String join(String str)
          Method to mimic the behavior of the JavaScript array join function
 int length()
          Utility function that maps ArrayList.size() to length, for compatibility to other JSON parsers.
 Object opt(int index)
          Method to get the object at that position, or null if outside the array range.
 Object opt(int index, Object defaultValue)
          Method to get the object at that position, or null if outside the array range.
 boolean optBoolean(int index)
          Method to obtain the value at index as an boolean, or 'false' if outside the array.
 boolean optBoolean(int index, boolean defaultValue)
          Method to obtain the value at index as an boolean, or 'defaultValue' if outside the array.
 double optDouble(int index)
          Method to obtain the value at index as a double, or Double.NaN if outside the array.
 double optDouble(int index, double defaultValue)
          Method to obtain the value at index as a double, or Double.NaN if outside the array.
 int optInt(int index)
          Method to obtain the value at index as an int, or '0' if outside the array.
 int optInt(int index, int defaultValue)
          Method to obtain the value at index as an int, or defaultValue if outside the array.
 long optLong(int index)
          Method to obtain the value at index as a long, or '0' if outside the array.
 long optLong(int index, long defaultValue)
          Method to obtain the value at index as a long, or defaultValue if outside the array.
 short optShort(int index)
          Method to obtain the value at index as a short, or '0' if outside the array.
 short optShort(int index, short defaultValue)
          Method to obtain the value at index as a short, or '0' if outside the array.
 String optString(int index)
          Method to obtain the value at index as a String, or null if outside the array.
 String optString(int index, String defaultValue)
          Method to obtain the value at index as a String, or defaultValue if outside the array.
 JSONArray put(boolean value)
          Method to place a int into the array.
 JSONArray put(Collection value)
          Method to place a map into the array.
 JSONArray put(Collection value, boolean includeSuperclass)
          Method to place a map into the array.
 JSONArray put(double value)
          Method to place a double into the array.
 JSONArray put(int value)
          Method to place a int into the array.
 JSONArray put(int index, boolean value)
          Method to place a boolean into the array.
 JSONArray put(int index, Collection value)
          Method to place a map into the array.
 JSONArray put(int index, Collection value, boolean includeSuperclass)
          Method to place a map into the array.
 JSONArray put(int index, double value)
          Method to place a double into the array.
 JSONArray put(int index, int value)
          Method to place an int into the array.
 JSONArray put(int index, long value)
          Method to place a long into the array.
 JSONArray put(int index, Map value)
          Method to place a java.util.Map instance in the array.
 JSONArray put(int index, Map value, boolean includeSuperclass)
          Method to place a java.util.Map instance in the array.
 JSONArray put(int index, Object element)
          Map of java.util.ArrayList.add(int, java.lang.Object), for compatibility to other JSON parsers.
 JSONArray put(int index, short value)
          Method to place a short into the array.
 JSONArray put(long value)
          Method to place a long into the array.
 JSONArray put(Map value)
          Method to place a map into the array.
 JSONArray put(Map value, boolean includeSuperclass)
          Method to place a map into the array.
 JSONArray put(Object element)
          Map of java.util.ArrayList.add(java.lang.Object), for compatibility to other JSON parsers.
 JSONArray put(Object element, boolean includeSuperclass)
          Map of java.util.ArrayList.add(java.lang.Object), for compatibility to other JSON parsers.
 JSONArray put(short value)
          Method to place a short into the array.
 Object set(int index, Object element)
           
 String toString()
          Over-ridden toString() method.
 String toString(int indentDepth)
          Function to return a string of JSON text with specified indention.
 String write()
          Convert this object into a String of JSON text.
 String write(boolean verbose)
          Convert this object into a String of JSON text, specifying verbosity.
 String write(int indentDepth)
          Convert this array into a String of JSON text, specifying verbosity.
 OutputStream write(OutputStream os)
          Convert this object into a stream of JSON text.
 OutputStream write(OutputStream os, boolean verbose)
          Convert this object into a stream of JSON text.
 OutputStream write(OutputStream os, int indentDepth)
          Convert this object into a String of JSON text, specifying how many spaces should be used for each indent level.
 Writer write(Writer writer)
          Convert this object into a stream of JSON text.
 Writer write(Writer writer, boolean verbose)
          Convert this object into a stream of JSON text, specifying verbosity.
 Writer write(Writer writer, int indentDepth)
          Convert this array into a stream of JSON text, specifying verbosity.
 
Methods inherited from class java.util.ArrayList
clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

JSONArray

public JSONArray()
Create a new instance of this class.


JSONArray

public JSONArray(int initialCapacity)
Create a new instance of this class with the specified initial capacity.

Parameters:
initialCapacity - The initial size to define the array as.

JSONArray

public JSONArray(Collection col)
          throws JSONException
Create a new instance of this class based off the contents of the passed in collection

Parameters:
col - The Collection of objects to add into this array.
Throws:
JSONException - Thrown when objects in the collection are not JSONable.
NullPointerException - Thrown if col is null.

JSONArray

public JSONArray(Object[] elems)
          throws JSONException
Create a new instance of this class based off the contents of the passed object array.

Parameters:
elems - The strings to add to a new JSONArray
Throws:
JSONException - Thrown when objects in the array are not JSONable.

JSONArray

public JSONArray(Object[] elems,
                 boolean includeSuperclass)
          throws JSONException
Create a new instance of this class based off the contents of the passed object array.

Parameters:
elems - The strings to add to a new JSONArray
includeSuperclass - For JavaBeans, include all superclass info.
Throws:
JSONException - Thrown when objects in the array are not JSONable.

JSONArray

public JSONArray(Collection col,
                 boolean includeSuperclass)
          throws JSONException
Create a new instance of this class based off the contents of the passed in collection

Parameters:
col - The Collection of objects to add into this array.
includeSuperclass - For JavaBeans, include all superclass info.
Throws:
JSONException - Thrown when objects in the collection are not JSONable. &throws NullPointerException Thrown if col is null.

JSONArray

public JSONArray(String str)
          throws JSONException
Create a new instance of this class from the provided JSON object string. Note: This is the same as calling new JSONArray(str, false); Parsing in non-strict mode.

Parameters:
str - The JSON array string to parse.
Throws:
JSONException - Thrown when the string passed is null, or malformed JSON..

JSONArray

public JSONArray(String str,
                 boolean strict)
          throws JSONException
Create a new instance of this class from the provided JSON object string.

Parameters:
str - The JSON array string to parse.
strict - Boolean denoting if the JSON should be parsed n strict mode, meaning unquoted strings and comments are not allowed.
Throws:
JSONException - Thrown when the string passed is null, or malformed JSON..

JSONArray

public JSONArray(Reader rdr)
          throws JSONException
Create a new instance of this class from the data provided from the reader. The reader content must be a JSON array string. Note: The reader will not be closed, that is left to the caller. Note: This is the same as calling new JSONArray(rdr, false); Parsing in non-strict mode.

Parameters:
rdr - The Reader from which to read the JSON array string to parse.
Throws:
JSONException - Thrown when the string passed is null, or malformed JSON..

JSONArray

public JSONArray(Reader rdr,
                 boolean strict)
          throws JSONException
Create a new instance of this class from the data provided from the reader. The reader content must be a JSON array string. Note: The reader will not be closed, that is left to the caller.

Parameters:
rdr - The Reader from which to read the JSON array string to parse.
strict - Boolean denoting if the JSON should be parsed n strict mode, meaning unquoted strings and comments are not allowed.
Throws:
JSONException - Thrown when the string passed is null, or malformed JSON..

JSONArray

public JSONArray(InputStream is)
          throws JSONException
Create a new instance of this class from the data provided from the input stream. The stream content must be a JSON array string. Note: The input stream content is assumed to be UTF-8 encoded. Note: The InputStream will not be closed, that is left to the caller.

Parameters:
is - The InputStream from which to read the JSON array string to parse.
Throws:
JSONException - Thrown when the string passed is null, or malformed JSON..

JSONArray

public JSONArray(InputStream is,
                 boolean strict)
          throws JSONException
Create a new instance of this class from the data provided from the input stream. The stream content must be a JSON array string. Note: The input stream content is assumed to be UTF-8 encoded. Note: The InputStream will not be closed, that is left to the caller.

Parameters:
is - The InputStream from which to read the JSON array string to parse.
strict - Boolean denoting if the JSON should be parsed n strict mode, meaning unquoted strings and comments are not allowed.
Throws:
JSONException - Thrown when the string passed is null, or malformed JSON..
Method Detail

getIndex

public Object getIndex(int index)
                throws JSONException
Function to get a JSONArray entry at a specified index.

Parameters:
index - The position in the rray to fetch the object from
Throws:
JSONException - Thrown if the index is outside the array bounds.

add

public void add(int index,
                Object element)
Specified by:
add in interface List
Overrides:
add in class ArrayList

add

public boolean add(Object element,
                   boolean includeSuperclass)

add

public boolean add(Object element)
Specified by:
add in interface Collection
Specified by:
add in interface List
Overrides:
add in class ArrayList

addAll

public boolean addAll(Collection collection)
Specified by:
addAll in interface Collection
Specified by:
addAll in interface List
Overrides:
addAll in class ArrayList

addAll

public boolean addAll(int index,
                      Collection collection)
Specified by:
addAll in interface List
Overrides:
addAll in class ArrayList

set

public Object set(int index,
                  Object element)
Specified by:
set in interface List
Overrides:
set in class ArrayList

put

public JSONArray put(int index,
                     Object element)
              throws JSONException
Map of java.util.ArrayList.add(int, java.lang.Object), for compatibility to other JSON parsers.

Returns:
A reference to this array instance.
Throws:
JSONException - in the case of index out of bounds, etc.
See Also:
ArrayList.add(int, java.lang.Object)

put

public JSONArray put(Object element)
              throws JSONException
Map of java.util.ArrayList.add(java.lang.Object), for compatibility to other JSON parsers.

Returns:
A reference to this array instance.
Throws:
JSONException
See Also:
ArrayList.add(java.lang.Object)

put

public JSONArray put(Object element,
                     boolean includeSuperclass)
              throws JSONException
Map of java.util.ArrayList.add(java.lang.Object), for compatibility to other JSON parsers.

Returns:
A reference to this array instance.
Throws:
JSONException
See Also:
ArrayList.add(java.lang.Object)

put

public JSONArray put(int index,
                     Map value)
              throws JSONException
Method to place a java.util.Map instance in the array. It will convert the map to a JSONObject if necessary.

Parameters:
index - The position in the array to place the Map (or coverted map).
value - An instance of a java.util.Map to insert into the array. Will convert to JSONObject if necessary.
Returns:
A reference to this array instance.
Throws:
JSONException - Thrown if the map cannot be converted to something JSONAble or the index is out of bounds.

put

public JSONArray put(int index,
                     Map value,
                     boolean includeSuperclass)
              throws JSONException
Method to place a java.util.Map instance in the array. It will convert the map to a JSONObject if necessary.

Parameters:
index - The position in the array to place the Map (or coverted map).
value - An instance of a java.util.Map to insert into the array. Will convert to JSONObject if necessary.
Returns:
A reference to this array instance.
Throws:
JSONException - Thrown if the map cannot be converted to something JSONAble or the index is out of bounds.

put

public JSONArray put(Map value)
              throws JSONException
Method to place a map into the array. It will convert the map to a JSONObject if necessary.

Parameters:
value - An instance of a java.util.Map to insert into the array. Will convert to JSONObject if necessary.
Returns:
A reference to this array instance.
Throws:
JSONException - Thrown if the map cannot be converted to something JSONAble.

put

public JSONArray put(Map value,
                     boolean includeSuperclass)
              throws JSONException
Method to place a map into the array. It will convert the map to a JSONObject if necessary.

Parameters:
value - An instance of a java.util.Map to insert into the array. Will convert to JSONObject if necessary.
Returns:
A reference to this array instance.
Throws:
JSONException - Thrown if the map cannot be converted to something JSONAble.

put

public JSONArray put(int index,
                     Collection value)
              throws JSONException
Method to place a map into the array. It will convert the map to a JSONArray if necessary.

Parameters:
index - The position in the array to place the Collection.
value - An instance of a java.util.Collection to insert into the array. Will convert to JSONArray if necessary.
Returns:
A reference to this array instance.
Throws:
JSONException - Thrown if the collection cannot be converted to something JSONAble or the index is out of bounds.

put

public JSONArray put(int index,
                     Collection value,
                     boolean includeSuperclass)
              throws JSONException
Method to place a map into the array. It will convert the map to a JSONArray if necessary.

Parameters:
index - The position in the array to place the Collection.
value - An instance of a java.util.Collection to insert into the array. Will convert to JSONArray if necessary.
Returns:
A reference to this array instance.
Throws:
JSONException - Thrown if the collection cannot be converted to something JSONAble or the index is out of bounds.

put

public JSONArray put(Collection value)
              throws JSONException
Method to place a map into the array. It will convert the map to a JSONArray if necessary.

Parameters:
value - An instance of a java.util.Collection to insert into the array. Will convert to JSONArray if necessary.
Returns:
A reference to this array instance.
Throws:
JSONException - Thrown if the collection cannot be converted to something JSONAble.

put

public JSONArray put(Collection value,
                     boolean includeSuperclass)
              throws JSONException
Method to place a map into the array. It will convert the map to a JSONArray if necessary.

Parameters:
value - An instance of a java.util.Collection to insert into the array. Will convert to JSONArray if necessary.
Returns:
A reference to this array instance.
Throws:
JSONException - Thrown if the collection cannot be converted to something JSONAble.

put

public JSONArray put(long value)
Method to place a long into the array.

Parameters:
value - A long
Returns:
A reference to this array instance.

put

public JSONArray put(int index,
                     long value)
Method to place a long into the array.

Parameters:
index - The position in the array to place the long.
value - A long
Returns:
A reference to this array instance.

put

public JSONArray put(int value)
Method to place a int into the array.

Parameters:
value - An int
Returns:
A reference to this array instance.

put

public JSONArray put(int index,
                     int value)
Method to place an int into the array.

Parameters:
index - The position in the array to place the int.
value - An int
Returns:
A reference to this array instance.

put

public JSONArray put(short value)
Method to place a short into the array.

Parameters:
value - A short
Returns:
A reference to this array instance.

put

public JSONArray put(int index,
                     short value)
Method to place a short into the array.

Parameters:
index - The position in the array to place the short.
value - A short
Returns:
A reference to this array instance.

put

public JSONArray put(double value)
Method to place a double into the array.

Parameters:
value - A double
Returns:
A reference to this array instance.

put

public JSONArray put(int index,
                     double value)
Method to place a double into the array.

Parameters:
index - The position in the array to place the double.
value - A double
Returns:
A reference to this array instance.

put

public JSONArray put(boolean value)
Method to place a int into the array.

Parameters:
value - A boolean
Returns:
A reference to this array instance.

put

public JSONArray put(int index,
                     boolean value)
Method to place a boolean into the array.

Parameters:
index - The position in the array to place the int.
value - A boolean
Returns:
A reference to this array instance.

getBoolean

public boolean getBoolean(int index)
                   throws JSONException
Function to obtain a value at the specified index as a boolean.

Parameters:
index - The index of the item to retrieve.
Returns:
boolean value.
Throws:
JSONException - if the index is outside the range or if the type at the position was not Boolean or a string of 'true' or 'false'

getDouble

public double getDouble(int index)
                 throws JSONException
Function to obtain a value at the specified index as a double.

Parameters:
index - The index of the item to retrieve.
Returns:
double value.
Throws:
JSONException - if the index is outside the range or if the type at the position was not Number.

getLong

public long getLong(int index)
             throws JSONException
Function to obtain a value at the specified index as a long.

Parameters:
index - The index of the item to retrieve.
Returns:
long value.
Throws:
JSONException - if the index is outside the range or if the type at the position was not Number.

getInt

public int getInt(int index)
           throws JSONException
Function to obtain a value at the specified index as an int.

Parameters:
index - The index of the item to retrieve.
Returns:
int value.
Throws:
JSONException - if the index is outside the range or if the type at the position was not Number.

getShort

public short getShort(int index)
               throws JSONException
Function to obtain a value at the specified index as a short.

Parameters:
index - The index of the item to retrieve.
Returns:
short value.
Throws:
JSONException - if the index is outside the range or if the type at the position was not Number.

getString

public String getString(int index)
                 throws JSONException
Function to obtain a value at the specified index as a string.

Parameters:
index - The index of the item to retrieve.
Returns:
string value.
Throws:
JSONException - if the index is outside the range or if the type at the position was not an object with a toString() function..

getJSONObject

public JSONObject getJSONObject(int index)
                         throws JSONException
Utility method to obtain the specified key as a JSONObject Only values that are instances of JSONObject will be returned. A null will generate an exception.

Parameters:
index - The index to look up. throws JSONException Thrown when the type returned by get(key) is not a JSONObject instance.
Returns:
A JSONObject value if the value stored for key is an instance or subclass of JSONObject.
Throws:
JSONException

getJSONArray

public JSONArray getJSONArray(int index)
                       throws JSONException
Utility method to obtain the specified index as a JSONArray Only values that are instances of JSONArray will be returned. A null will generate an exception.

Parameters:
index - The index to look up. throws JSONException Thrown when the type returned by get(key) is not a Long instance, or cannot be converted to a long..
Returns:
A JSONArray value if the value stored for key is an instance or subclass of JSONArray.
Throws:
JSONException

isNull

public boolean isNull(int index)
Utility function for testing if an element at index 'idx' is null or not.

Returns:
boolean indicating if an index is null or not. Will also return true for indexes outside the size of the array.

length

public int length()
Utility function that maps ArrayList.size() to length, for compatibility to other JSON parsers.

Returns:
The number of elements in this JSONArray.

write

public OutputStream write(OutputStream os)
                   throws JSONException
Convert this object into a stream of JSON text. Same as calling write(os,false);

Specified by:
write in interface JSONArtifact
Parameters:
os - The output stream to write data to.
Returns:
The passed in OutputStream.
Throws:
JSONException - Thrown on IO errors during serialization.

write

public OutputStream write(OutputStream os,
                          boolean verbose)
                   throws JSONException
Convert this object into a stream of JSON text. Same as calling write(writer,false);

Specified by:
write in interface JSONArtifact
Parameters:
os - The output stream to write data to. Output stream characters will be serialized as UTF-8.
verbose - Whether or not to write the JSON text in a verbose format.
Returns:
The passed in OutputStream.
Throws:
JSONException - Thrown on IO errors during serialization.

write

public OutputStream write(OutputStream os,
                          int indentDepth)
                   throws JSONException
Convert this object into a String of JSON text, specifying how many spaces should be used for each indent level. Output stream characters will be serialized as UTF-8.

Specified by:
write in interface JSONArtifact
Parameters:
indentDepth - How many spaces to use for each indent level. Should be one to eight. Less than one means no intending, greater than 8 and it will just use tab.
Returns:
The passed in OutputStream.
Throws:
JSONException - Thrown on IO errors during serialization.

write

public Writer write(Writer writer)
             throws JSONException
Convert this object into a stream of JSON text. Same as calling write(writer,false);

Specified by:
write in interface JSONArtifact
Parameters:
writer - The writer which to write the JSON text to.
Returns:
The passed in writer.
Throws:
JSONException - Thrown on IO errors during serialization.

write

public Writer write(Writer writer,
                    boolean verbose)
             throws JSONException
Convert this object into a stream of JSON text, specifying verbosity.

Specified by:
write in interface JSONArtifact
Parameters:
writer - The writer which to write the JSON text to.
Returns:
The passed in writer.
Throws:
JSONException - Thrown on IO errors during serialization.

write

public Writer write(Writer writer,
                    int indentDepth)
             throws JSONException
Convert this array into a stream of JSON text, specifying verbosity.

Specified by:
write in interface JSONArtifact
Parameters:
writer - The writer which to write the JSON text to.
indentDepth - How many spaces to use for each indent level. Should be one to eight.
Returns:
The passed in writer.
Throws:
JSONException - Thrown on IO errors during serialization.

write

public String write(boolean verbose)
             throws JSONException
Convert this object into a String of JSON text, specifying verbosity.

Specified by:
write in interface JSONArtifact
Parameters:
verbose - Whether or not to write in compressed for formatted Strings.
Throws:
JSONException - Thrown on IO errors during serialization.

write

public String write(int indentDepth)
             throws JSONException
Convert this array into a String of JSON text, specifying verbosity.

Specified by:
write in interface JSONArtifact
Parameters:
indentDepth - How many spaces to use for each indent level. Should be one to eight.
Throws:
JSONException - Thrown on IO errors during serialization.

write

public String write()
             throws JSONException
Convert this object into a String of JSON text. Same as write(false);

Specified by:
write in interface JSONArtifact
Throws:
JSONException - Thrown on IO errors during serialization.

toString

public String toString()
Over-ridden toString() method. Returns the same value as write(), which is a compact JSON String. If an error occurs in the serialization, the return will be of format: JSON Generation Error: []

Overrides:
toString in class AbstractCollection

toString

public String toString(int indentDepth)
                throws JSONException
Function to return a string of JSON text with specified indention. Returns the same value as write(indentDepth). If an error occurs in the serialization, the return will be of format: JSON Generation Error: []

Throws:
JSONException - Thrown if an error occurs during JSON generation.

join

public String join(String str)
Method to mimic the behavior of the JavaScript array join function

Parameters:
str - The string delimiter to place between joined array elements in the output string.
Returns:
A string of all the elements joined together.

opt

public Object opt(int index)
Method to get the object at that position, or null if outside the array range.

Parameters:
index - the array index to get
Returns:
- value or null

opt

public Object opt(int index,
                  Object defaultValue)
Method to get the object at that position, or null if outside the array range.

Parameters:
index - the array index to get
defaultValue - the value to return if index is outside the array.
Returns:
- value or defaultValue

optBoolean

public boolean optBoolean(int index)
Method to obtain the value at index as an boolean, or 'false' if outside the array.

Parameters:
index - the array index to get
Returns:
- value or false

optBoolean

public boolean optBoolean(int index,
                          boolean defaultValue)
Method to obtain the value at index as an boolean, or 'defaultValue' if outside the array.

Parameters:
index - The array index to get.
defaultValue - the value to return if index is outside the array.
Returns:
- value or false

optInt

public int optInt(int index)
Method to obtain the value at index as an int, or '0' if outside the array.

Parameters:
index - the array index to get
Returns:
- value or 0

optInt

public int optInt(int index,
                  int defaultValue)
Method to obtain the value at index as an int, or defaultValue if outside the array.

Parameters:
index - the array index to get
defaultValue - the value to return if index is outside the array.
Returns:
- value or 0

optLong

public long optLong(int index)
Method to obtain the value at index as a long, or '0' if outside the array.

Parameters:
index - the array index to get
Returns:
- value or 0

optLong

public long optLong(int index,
                    long defaultValue)
Method to obtain the value at index as a long, or defaultValue if outside the array.

Parameters:
index - the array index to get
defaultValue - the value to return if index is outside the array. v* @return - value or defaultValue

optShort

public short optShort(int index)
Method to obtain the value at index as a short, or '0' if outside the array.

Parameters:
index - the array index to get
Returns:
- value or 0

optShort

public short optShort(int index,
                      short defaultValue)
Method to obtain the value at index as a short, or '0' if outside the array.

Parameters:
index - the array index to get
defaultValue - the value to return if index is outside the array.
Returns:
- value or defaultValue

optDouble

public double optDouble(int index)
Method to obtain the value at index as a double, or Double.NaN if outside the array.

Parameters:
index - the array index to get
Returns:
- value or Double.NaN

optDouble

public double optDouble(int index,
                        double defaultValue)
Method to obtain the value at index as a double, or Double.NaN if outside the array.

Parameters:
index - the array index to get
defaultValue - the value to return if index is outside the array.
Returns:
- value or defaultValue

optString

public String optString(int index)
Method to obtain the value at index as a String, or null if outside the array.

Parameters:
index - the array index to get
Returns:
- value or null

optString

public String optString(int index,
                        String defaultValue)
Method to obtain the value at index as a String, or defaultValue if outside the array.

Parameters:
index - the array index to get
defaultValue - the value to return if index is outside the array.
Returns:
- value or defaultValue


Copyright © 2009-2012 The Apache Software Foundation. All Rights Reserved.