public class ValueMap
extends java.lang.Object
implements java.util.Map<java.lang.String,java.lang.Object>
Map to expose value type functionality. All Map methods will simply be forwarded to a delegate map. This class is meant to
subclassed and provide methods to access values in keys.
Library users won't need to create instances of this class, they can use plain old Map
instead, and our library will handle serializing them.
Although it lets you use custom objects for values, note that type information is lost during
serialization. You should use one of the coercion methods instead to get objects of a concrete
type.| Constructor and Description |
|---|
ValueMap() |
ValueMap(int initialCapacity) |
ValueMap(java.util.Map<java.lang.String,java.lang.Object> map) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> |
entrySet() |
boolean |
equals(java.lang.Object object) |
java.lang.Object |
get(java.lang.Object key) |
boolean |
getBoolean(java.lang.String key,
boolean defaultValue)
Returns the value mapped by
key if it exists and is a boolean or can be coerced to a
boolean. |
char |
getChar(java.lang.String key,
char defaultValue)
Returns the value mapped by
key if it exists and is a char or can be coerced to a
char. |
double |
getDouble(java.lang.String key,
double defaultValue)
Returns the value mapped by
key if it exists and is a double or can be coerced to a
double. |
<T extends java.lang.Enum<T>> |
getEnum(java.lang.Class<T> enumType,
java.lang.String key)
Returns the value mapped by
key if it exists and is a enum or can be coerced to an
enum. |
float |
getFloat(java.lang.String key,
float defaultValue)
Returns the value mapped by
key if it exists and is a float or can be coerced to a
float. |
int |
getInt(java.lang.String key,
int defaultValue)
Returns the value mapped by
key if it exists and is a integer or can be coerced to a
integer. |
<T extends ValueMap> |
getList(java.lang.Object key,
java.lang.Class<T> clazz)
Returns the value mapped by
key if it exists and is a List of T. |
long |
getLong(java.lang.String key,
long defaultValue)
Returns the value mapped by
key if it exists and is a long or can be coerced to a
long. |
java.lang.String |
getString(java.lang.String key)
Returns the value mapped by
key if it exists and is a string or can be coerced to a
string. |
ValueMap |
getValueMap(java.lang.Object key)
Returns the value mapped by
key if it exists and is a ValueMap. |
<T extends ValueMap> |
getValueMap(java.lang.String key,
java.lang.Class<T> clazz)
Returns the value mapped by
key if it exists and if it can be coerced to the given
type. |
int |
hashCode() |
boolean |
isEmpty() |
java.util.Set<java.lang.String> |
keySet() |
java.lang.Object |
put(java.lang.String key,
java.lang.Object value) |
void |
putAll(java.util.Map<? extends java.lang.String,?> map) |
ValueMap |
putValue(java.lang.String key,
java.lang.Object value)
Helper method to be able to chain put methods.
|
java.lang.Object |
remove(java.lang.Object key) |
int |
size() |
org.json.JSONObject |
toJsonObject()
Return a copy of the contents of this map as a
JSONObject. |
java.lang.String |
toString() |
java.util.Map<java.lang.String,java.lang.String> |
toStringMap()
Return a copy of the contents of this map as a
Map<String, String>. |
java.util.Collection<java.lang.Object> |
values() |
public ValueMap()
public ValueMap(int initialCapacity)
public ValueMap(java.util.Map<java.lang.String,java.lang.Object> map)
public void clear()
clear in interface java.util.Map<java.lang.String,java.lang.Object>public boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Map<java.lang.String,java.lang.Object>public boolean containsValue(java.lang.Object value)
containsValue in interface java.util.Map<java.lang.String,java.lang.Object>public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
entrySet in interface java.util.Map<java.lang.String,java.lang.Object>public java.lang.Object get(java.lang.Object key)
get in interface java.util.Map<java.lang.String,java.lang.Object>public boolean isEmpty()
isEmpty in interface java.util.Map<java.lang.String,java.lang.Object>public java.util.Set<java.lang.String> keySet()
keySet in interface java.util.Map<java.lang.String,java.lang.Object>public java.lang.Object put(java.lang.String key,
java.lang.Object value)
put in interface java.util.Map<java.lang.String,java.lang.Object>public void putAll(java.util.Map<? extends java.lang.String,?> map)
putAll in interface java.util.Map<java.lang.String,java.lang.Object>public java.lang.Object remove(java.lang.Object key)
remove in interface java.util.Map<java.lang.String,java.lang.Object>public int size()
size in interface java.util.Map<java.lang.String,java.lang.Object>public java.util.Collection<java.lang.Object> values()
values in interface java.util.Map<java.lang.String,java.lang.Object>public boolean equals(java.lang.Object object)
equals in interface java.util.Map<java.lang.String,java.lang.Object>equals in class java.lang.Objectpublic int hashCode()
hashCode in interface java.util.Map<java.lang.String,java.lang.Object>hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic ValueMap putValue(java.lang.String key, java.lang.Object value)
public int getInt(java.lang.String key,
int defaultValue)
key if it exists and is a integer or can be coerced to a
integer. Returns defaultValue otherwise.public long getLong(java.lang.String key,
long defaultValue)
key if it exists and is a long or can be coerced to a
long.
Returns defaultValue otherwise.public float getFloat(java.lang.String key,
float defaultValue)
key if it exists and is a float or can be coerced to a
float. Returns defaultValue otherwise.public double getDouble(java.lang.String key,
double defaultValue)
key if it exists and is a double or can be coerced to a
double. Returns defaultValue otherwise.public char getChar(java.lang.String key,
char defaultValue)
key if it exists and is a char or can be coerced to a
char.
Returns defaultValue otherwise.public java.lang.String getString(java.lang.String key)
key if it exists and is a string or can be coerced to a
string. Returns null otherwise.
This will return null only if the value does not exist, since all types can have a String
representation.public boolean getBoolean(java.lang.String key,
boolean defaultValue)
key if it exists and is a boolean or can be coerced to a
boolean. Returns defaultValue otherwise.public <T extends java.lang.Enum<T>> T getEnum(java.lang.Class<T> enumType,
java.lang.String key)
key if it exists and is a enum or can be coerced to an
enum. Returns null otherwise.public ValueMap getValueMap(java.lang.Object key)
key if it exists and is a ValueMap. Returns null
otherwise.public <T extends ValueMap> T getValueMap(java.lang.String key, java.lang.Class<T> clazz)
key if it exists and if it can be coerced to the given
type. The expected subclass MUST have a constructor that accepts a Map.public <T extends ValueMap> java.util.List<T> getList(java.lang.Object key, java.lang.Class<T> clazz)
key if it exists and is a List of T. Returns null
otherwise.public org.json.JSONObject toJsonObject()
JSONObject.public java.util.Map<java.lang.String,java.lang.String> toStringMap()
Map<String, String>.