com.planet_ink.coffee_mud.core
Class MiniJSON.JSONObject

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.TreeMap<java.lang.String,java.lang.Object>
          extended by com.planet_ink.coffee_mud.core.MiniJSON.JSONObject
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,java.lang.Object>, java.util.NavigableMap<java.lang.String,java.lang.Object>, java.util.SortedMap<java.lang.String,java.lang.Object>
Enclosing class:
MiniJSON

public static class MiniJSON.JSONObject
extends java.util.TreeMap<java.lang.String,java.lang.Object>

An official JSON object. Implemented as a Map, this class has numerous methods for accessing the internal keys and their mapped values in different ways, both raw, and checked.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
MiniJSON.JSONObject()
           
 
Method Summary
static void appendJSONValue(java.lang.StringBuilder value, java.lang.Object obj)
          Correctly appends the given thing to the given stringbuffer which is assumed to be in the middle of a JSON obect definition, right after the key and the colon:
 MiniJSON.JSONObject copyOf()
           
 java.lang.Object[] getCheckedArray(java.lang.String key)
          Returns a JSON Array mapped in this object by the given key.
 java.lang.Boolean getCheckedBoolean(java.lang.String key)
          Returns a Boolean mapped in this object by the given key.
 java.lang.Double getCheckedDouble(java.lang.String key)
          Returns a Double mapped in this object by the given key.
 MiniJSON.JSONObject getCheckedJSONObject(java.lang.String key)
          Returns a JSONObject mapped in THIS object by the given key.
 java.lang.Long getCheckedLong(java.lang.String key)
          Returns a Long mapped in this object by the given key.
 double getCheckedNumber(java.lang.String key)
          Returns a numeric value mapped in this object by the given key.
 java.lang.String getCheckedString(java.lang.String key)
          Returns a String mapped in this object by the given key.
 boolean isCheckedNULL(java.lang.String key)
          Checks this object for the given key, and checks if it is an official NULL or not.
 java.lang.Object jsonDeepCopy(java.lang.Object obj)
           
 java.lang.String toString()
          Returns a full JSON document representation of this JSON object
 
Methods inherited from class java.util.TreeMap
ceilingEntry, ceilingKey, clear, clone, comparator, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, get, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, navigableKeySet, pollFirstEntry, pollLastEntry, put, putAll, remove, size, subMap, subMap, tailMap, tailMap, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, isEmpty
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode, isEmpty
 

Constructor Detail

MiniJSON.JSONObject

public MiniJSON.JSONObject()
Method Detail

getCheckedJSONObject

public MiniJSON.JSONObject getCheckedJSONObject(java.lang.String key)
                                         throws MiniJSON.MJSONException
Returns a JSONObject mapped in THIS object by the given key. Throws an exception if anything goes wrong.

Parameters:
key - the key of the object
Returns:
the JSON Object mapped to by that key
Throws:
MiniJSON.MJSONException - a missing key, or not a JSON Object

getCheckedArray

public java.lang.Object[] getCheckedArray(java.lang.String key)
                                   throws MiniJSON.MJSONException
Returns a JSON Array mapped in this object by the given key. Throws an exception if anything goes wrong.

Parameters:
key - the key of the Array
Returns:
the JSON Array mapped to by that key
Throws:
MiniJSON.MJSONException - a missing key, or not a JSON Array

getCheckedString

public java.lang.String getCheckedString(java.lang.String key)
                                  throws MiniJSON.MJSONException
Returns a String mapped in this object by the given key. Throws an exception if anything goes wrong.

Parameters:
key - the key of the String
Returns:
the String mapped to by that key
Throws:
MiniJSON.MJSONException - a missing key, or not a String

getCheckedLong

public java.lang.Long getCheckedLong(java.lang.String key)
                              throws MiniJSON.MJSONException
Returns a Long mapped in this object by the given key. Throws an exception if anything goes wrong.

Parameters:
key - the key of the Long
Returns:
the Long mapped to by that key
Throws:
MiniJSON.MJSONException - a missing key, or not a Long

getCheckedDouble

public java.lang.Double getCheckedDouble(java.lang.String key)
                                  throws MiniJSON.MJSONException
Returns a Double mapped in this object by the given key. Throws an exception if anything goes wrong.

Parameters:
key - the key of the Long
Returns:
the Double mapped to by that key
Throws:
MiniJSON.MJSONException - a missing key, or not a Double

getCheckedBoolean

public java.lang.Boolean getCheckedBoolean(java.lang.String key)
                                    throws MiniJSON.MJSONException
Returns a Boolean mapped in this object by the given key. Throws an exception if anything goes wrong.

Parameters:
key - the key of the Long
Returns:
the Boolean mapped to by that key
Throws:
MiniJSON.MJSONException - a missing key, or not a Boolean

getCheckedNumber

public double getCheckedNumber(java.lang.String key)
                        throws MiniJSON.MJSONException
Returns a numeric value mapped in this object by the given key. Throws an exception if anything goes wrong.

Parameters:
key - the key of the Long
Returns:
the double value of the number mapped to by that key
Throws:
MiniJSON.MJSONException - a missing key, or not a numeric value

isCheckedNULL

public boolean isCheckedNULL(java.lang.String key)
                      throws MiniJSON.MJSONException
Checks this object for the given key, and checks if it is an official NULL or not. Throws an exception if the key is missing.

Parameters:
key - the key of the possible null
Returns:
true if the key maps to NULL or false otherwise
Throws:
MiniJSON.MJSONException - the key was missing

appendJSONValue

public static void appendJSONValue(java.lang.StringBuilder value,
                                   java.lang.Object obj)
Correctly appends the given thing to the given stringbuffer which is assumed to be in the middle of a JSON obect definition, right after the key and the colon:

Parameters:
value - the StringBuffer to append a value to
obj - the value to append -- a string, null, array, or number

toString

public java.lang.String toString()
Returns a full JSON document representation of this JSON object

Overrides:
toString in class java.util.AbstractMap<java.lang.String,java.lang.Object>

jsonDeepCopy

public java.lang.Object jsonDeepCopy(java.lang.Object obj)

copyOf

public MiniJSON.JSONObject copyOf()