in.srain.binpack
Class BinDict

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

public class BinDict
extends java.lang.Object

A map wrapper to access data.

Author:
http://www.liaohuqiu.net

Field Summary
static java.lang.Object NULL
          A sentinel value used to explicitly define a name with no value.
 
Constructor Summary
BinDict(byte[] bs, java.lang.String charsetName)
           
BinDict(java.util.Map copyFrom)
           
 
Method Summary
 java.lang.Object get(java.lang.String name)
           
 boolean getBoolean(java.lang.String name)
           
 byte getByte(java.lang.String name)
          Returns the value mapped by name if it exists and is a byte or can be coerced to a byte.
 BinDict getDict(java.lang.String name)
           
 double getDouble(java.lang.String name)
           
 int getInt(java.lang.String name)
          Returns the value mapped by name if it exists and is an int or can be coerced to an int.
 BinList getList(java.lang.String name)
           
 long getLong(java.lang.String name)
          Returns the value mapped by name if it exists and is a long or can be coerced to a long.
 short getShort(java.lang.String name)
          Returns the value mapped by name if it exists and is a short or can be coerced to a short.
 java.lang.String getString(java.lang.String name)
          Returns the value mapped by name if it exists, coercing it if necessary.
 boolean has(java.lang.String name)
           
 boolean isNull(java.lang.String name)
           
 java.util.Iterator keys()
           
 java.util.ArrayList<java.lang.String> names()
          Returns an array containing the string names in this object.
 java.lang.Object opt(java.lang.String name)
           
 boolean optBoolean(java.lang.String name)
           
 boolean optBoolean(java.lang.String name, boolean fallback)
           
 byte optByte(java.lang.String index)
          Returns the value at index if it exists and is a byte or can be coerced to a byte.
 byte optByte(java.lang.String name, byte fallback)
          Returns the value mapped by name if it exists and is a byte or can be coerced to a byte.
 BinDict optDict(java.lang.String name)
           
 double optDouble(java.lang.String name)
          Returns the value mapped by name if it exists and is a double or can be coerced to a double.
 double optDouble(java.lang.String name, double fallback)
          Returns the value mapped by name if it exists and is a double or can be coerced to a double.
 int optInt(java.lang.String name)
          Returns the value mapped by name if it exists and is an int or can be coerced to an int.
 int optInt(java.lang.String name, int fallback)
          Returns the value mapped by name if it exists and is an int or can be coerced to an int.
 BinList optList(java.lang.String name)
           
 long optLong(java.lang.String name)
          Returns the value mapped by name if it exists and is a long or can be coerced to a long.
 long optLong(java.lang.String name, long fallback)
          Returns the value mapped by name if it exists and is a long or can be coerced to a long.
 short optShort(java.lang.String name)
          Returns the value mapped by name if it exists and is a short or can be coerced to a short.
 short optShort(java.lang.String name, short fallback)
          Returns the value mapped by name if it exists and is a short or can be coerced to a short Returns fallback otherwise.
 java.lang.String optString(java.lang.String name)
          Returns the value mapped by name if it exists, coercing it if necessary.
 java.lang.String optString(java.lang.String name, java.lang.String fallback)
          Returns the value mapped by name if it exists, coercing it if necessary.
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL

public static final java.lang.Object NULL
A sentinel value used to explicitly define a name with no value.

Constructor Detail

BinDict

public BinDict(java.util.Map copyFrom)

BinDict

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

isNull

public boolean isNull(java.lang.String name)

has

public boolean has(java.lang.String name)

get

public java.lang.Object get(java.lang.String name)
                     throws BinPackException
Throws:
BinPackException

opt

public java.lang.Object opt(java.lang.String name)

getBoolean

public boolean getBoolean(java.lang.String name)
                   throws BinPackException
Throws:
BinPackException

optBoolean

public boolean optBoolean(java.lang.String name)

optBoolean

public boolean optBoolean(java.lang.String name,
                          boolean fallback)

getDouble

public double getDouble(java.lang.String name)
                 throws BinPackException
Throws:
BinPackException

optDouble

public double optDouble(java.lang.String name)
Returns the value mapped by name if it exists and is a double or can be coerced to a double. Returns NaN otherwise.


optDouble

public double optDouble(java.lang.String name,
                        double fallback)
Returns the value mapped by name if it exists and is a double or can be coerced to a double. Returns fallback otherwise.


getByte

public byte getByte(java.lang.String name)
             throws BinPackException
Returns the value mapped by name if it exists and is a byte or can be coerced to a byte.

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

optByte

public byte optByte(java.lang.String 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(java.lang.String name,
                    byte fallback)
Returns the value mapped by name if it exists and is a byte or can be coerced to a byte. Returns fallback otherwise.


getShort

public short getShort(java.lang.String name)
               throws BinPackException
Returns the value mapped by name if it exists and is a short or can be coerced to a short.

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

optShort

public short optShort(java.lang.String name)
Returns the value mapped by name if it exists and is a short or can be coerced to a short. Returns 0 otherwise.


optShort

public short optShort(java.lang.String name,
                      short fallback)
Returns the value mapped by name if it exists and is a short or can be coerced to a short Returns fallback otherwise.


getInt

public int getInt(java.lang.String name)
           throws BinPackException
Returns the value mapped by name if it exists and is an int or can be coerced to an int.

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

optInt

public int optInt(java.lang.String name)
Returns the value mapped by name if it exists and is an int or can be coerced to an int. Returns 0 otherwise.


optInt

public int optInt(java.lang.String name,
                  int fallback)
Returns the value mapped by name if it exists and is an int or can be coerced to an int. Returns fallback otherwise.


getLong

public long getLong(java.lang.String name)
             throws BinPackException
Returns the value mapped by name if it exists and is a long or can be coerced to a long.

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

optLong

public long optLong(java.lang.String name)
Returns the value mapped by name if it exists and is a long or can be coerced to a long. Returns 0 otherwise.


optLong

public long optLong(java.lang.String name,
                    long fallback)
Returns the value mapped by name if it exists and is a long or can be coerced to a long. Returns fallback otherwise.


getString

public java.lang.String getString(java.lang.String name)
                           throws BinPackException
Returns the value mapped by name if it exists, coercing it if necessary.

Throws:
BinPackException - if no such mapping exists.

optString

public java.lang.String optString(java.lang.String name)
Returns the value mapped by name if it exists, coercing it if necessary. Returns the empty string if no such mapping exists.


optString

public java.lang.String optString(java.lang.String name,
                                  java.lang.String fallback)
Returns the value mapped by name if it exists, coercing it if necessary. Returns fallback if no such mapping exists.


getList

public BinList getList(java.lang.String name)
                throws BinPackException
Throws:
BinPackException

optList

public BinList optList(java.lang.String name)

getDict

public BinDict getDict(java.lang.String name)
                throws BinPackException
Throws:
BinPackException

optDict

public BinDict optDict(java.lang.String name)

keys

public java.util.Iterator keys()

size

public int size()

names

public java.util.ArrayList<java.lang.String> names()
Returns an array containing the string names in this object. This method returns null if this object contains no mappings.


toString

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


Copyright © 2014. All Rights Reserved.