in.srain.binpack
Class BinList

java.lang.Object
  extended by in.srain.binpack.BinList

public class BinList
extends java.lang.Object

A Collection wrapper for data access.

Author:
http://www.liaohuqiu.net

Constructor Summary
BinList(byte[] bs, java.lang.String charsetName)
           
BinList(java.util.Collection copyFrom)
           
 
Method Summary
 boolean equals(java.lang.Object o)
           
 java.lang.Object get(int index)
          Returns the value at index.
 boolean getBoolean(int index)
          Returns the value at index if it exists and is a boolean or can be coerced to a boolean.
 byte getByte(int index)
          Returns the value at index if it exists and is a byte or can be coerced to an byte.
 BinDict getDict(int index)
           
 double getDouble(int index)
          Returns the value at index if it exists and is a double or can be coerced to a double.
 int getInt(int index)
          Returns the value at index if it exists and is an int or can be coerced to an int.
 BinList getList(int index)
          Returns the value at index if it exists and is a BinList.
 long getLong(int index)
          Returns the value at index if it exists and is a long or can be coerced to a long.
 short getShort(int index)
          Returns the value at index if it exists and is a short or can be coerced to an byte.
 java.lang.String getString(int index)
          Returns the value at index if it exists, coercing it if necessary.
 int hashCode()
           
 boolean isNull(int index)
          Returns true if this array has no value at index, or if its value is the null reference or BinDict.NULL.
 int length()
          Returns the number of values in this array.
 java.lang.Object opt(int index)
          Returns the value at index, or null if the array has no value at index.
 boolean optBoolean(int index)
          Returns the value at index if it exists and is a boolean or can be coerced to a boolean.
 boolean optBoolean(int index, boolean fallback)
          Returns the value at index if it exists and is a boolean or can be coerced to a boolean.
 byte optByte(int index)
          Returns the value at index if it exists and is a byte or can be coerced to a byte.
 byte optByte(int index, byte fallback)
          Returns the value at index if it exists and is a byte or can be coerced to a byte.
 BinDict optDict(int index)
           
 double optDouble(int index)
          Returns the value at index if it exists and is a double or can be coerced to a double.
 double optDouble(int index, double fallback)
          Returns the value at index if it exists and is a double or can be coerced to a double.
 int optInt(int index)
          Returns the value at index if it exists and is an int or can be coerced to an int.
 int optInt(int index, int fallback)
          Returns the value at index if it exists and is an int or can be coerced to an int.
 BinList optList(int index)
          Returns the value at index if it exists and is a BinList.
 long optLong(int index)
          Returns the value at index if it exists and is a long or can be coerced to a long.
 long optLong(int index, long fallback)
          Returns the value at index if it exists and is a long or can be coerced to a long.
 short optShort(int index)
          Returns the value at index if it exists and is a short or can be coerced to a short.
 short optShort(int index, short fallback)
          Returns the value at index if it exists and is a short or can be coerced to a short.
 java.lang.String optString(int index)
          Returns the value at index if it exists, coercing it if necessary.
 java.lang.String optString(int index, java.lang.String fallback)
          Returns the value at index if it exists, coercing it if necessary.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BinList

public BinList(java.util.Collection copyFrom)

BinList

public BinList(byte[] bs,
               java.lang.String charsetName)
        throws BinPackException
Throws:
BinPackException
Method Detail

length

public int length()
Returns the number of values in this array.


isNull

public boolean isNull(int index)
Returns true if this array has no value at index, or if its value is the null reference or BinDict.NULL.


get

public java.lang.Object get(int index)
                     throws BinPackException
Returns the value at index.

Throws:
BinPackException - if this array has no value at index, or if that value is the null reference. This method returns normally if the value is JSONObject#NULL.

opt

public java.lang.Object opt(int index)
Returns the value at index, or null if the array has no value at index.


getBoolean

public boolean getBoolean(int index)
                   throws BinPackException
Returns the value at index if it exists and is a boolean or can be coerced to a boolean.

Throws:
BinPackException - if the value at index doesn't exist or cannot be coerced to a boolean.

optBoolean

public boolean optBoolean(int index)
Returns the value at index if it exists and is a boolean or can be coerced to a boolean. Returns false otherwise.


optBoolean

public boolean optBoolean(int index,
                          boolean fallback)
Returns the value at index if it exists and is a boolean or can be coerced to a boolean. Returns fallback otherwise.


getDouble

public double getDouble(int index)
                 throws BinPackException
Returns the value at index if it exists and is a double or can be coerced to a double.

Throws:
BinPackException - if the value at index doesn't exist or cannot be coerced to a double.

optDouble

public double optDouble(int index)
Returns the value at index if it exists and is a double or can be coerced to a double. Returns NaN otherwise.


optDouble

public double optDouble(int index,
                        double fallback)
Returns the value at index if it exists and is a double or can be coerced to a double. Returns fallback otherwise.


getByte

public byte getByte(int index)
             throws BinPackException
Returns the value at index if it exists and is a byte or can be coerced to an byte.

Throws:
BinPackException - if the value at index doesn't exist or cannot be coerced to a byte.

optByte

public byte optByte(int index)
Returns the value at index if it exists and is a byte or can be coerced to a byte. Returns 0 otherwise.


optByte

public byte optByte(int index,
                    byte fallback)
Returns the value at index if it exists and is a byte or can be coerced to a byte. Returns fallback otherwise.


getShort

public short getShort(int index)
               throws BinPackException
Returns the value at index if it exists and is a short or can be coerced to an byte.

Throws:
BinPackException - if the value at index doesn't exist or cannot be coerced to a short.

optShort

public short optShort(int index)
Returns the value at index if it exists and is a short or can be coerced to a short. Returns 0 otherwise.


optShort

public short optShort(int index,
                      short fallback)
Returns the value at index if it exists and is a short or can be coerced to a short. Returns fallback otherwise.


getInt

public int getInt(int index)
           throws BinPackException
Returns the value at index if it exists and is an int or can be coerced to an int.

Throws:
BinPackException - if the value at index doesn't exist or cannot be coerced to an int.

optInt

public int optInt(int index)
Returns the value at index if it exists and is an int or can be coerced to an int. Returns 0 otherwise.


optInt

public int optInt(int index,
                  int fallback)
Returns the value at index if it exists and is an int or can be coerced to an int. Returns fallback otherwise.


getLong

public long getLong(int index)
             throws BinPackException
Returns the value at index if it exists and is a long or can be coerced to a long.

Throws:
BinPackException - if the value at index doesn't exist or cannot be coerced to a long.

optLong

public long optLong(int index)
Returns the value at index if it exists and is a long or can be coerced to a long. Returns 0 otherwise.


optLong

public long optLong(int index,
                    long fallback)
Returns the value at index if it exists and is a long or can be coerced to a long. Returns fallback otherwise.


getString

public java.lang.String getString(int index)
                           throws BinPackException
Returns the value at index if it exists, coercing it if necessary.

Throws:
BinPackException - if no such value exists.

optString

public java.lang.String optString(int index)
Returns the value at index if it exists, coercing it if necessary. Returns the empty string if no such value exists.


optString

public java.lang.String optString(int index,
                                  java.lang.String fallback)
Returns the value at index if it exists, coercing it if necessary. Returns fallback if no such value exists.


getList

public BinList getList(int index)
                throws BinPackException
Returns the value at index if it exists and is a BinList.

Throws:
BinPackException - if the value doesn't exist or is not a BinList.

optList

public BinList optList(int index)
Returns the value at index if it exists and is a BinList. Returns null otherwise.


getDict

public BinDict getDict(int index)
                throws BinPackException
Throws:
BinPackException

optDict

public BinDict optDict(int index)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object


Copyright © 2014. All Rights Reserved.