public abstract class SampMap
extends java.util.AbstractMap
SampMap
, for instance Message
, Metadata
etc.
A SampMap
is-a Map
, but has some
additional useful features:
asClass
method to convert from a normal Map to the class in question
In general
any time a map-encoded object is required by a method in the toolkit,
any Map
can be used. When the toolkit provides a map-encoded
object however (as return value or callback method parameter), an object
of the more specific SampMap
type is used.
This allows maximum convenience for the application programmer, but
means that you don't have to use these additional features if you
don't want to, you can treat everything as a plain old Map
.
Modifier and Type | Field and Description |
---|---|
private java.util.Map |
baseMap_ |
static java.util.Map |
EMPTY |
Modifier | Constructor and Description |
---|---|
protected |
SampMap(java.lang.String[] knownKeys)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
check()
Checks that this object is ready for use with the SAMP toolkit.
|
void |
checkHasKeys(java.lang.String[] keys)
Checks that this map contains at least the given set of keys.
|
java.util.Set |
entrySet() |
java.util.List |
getList(java.lang.String key)
Returns the value for a given key in this map, cast to List.
|
java.util.Map |
getMap(java.lang.String key)
returns the value for a given key in this map, cast to Map.
|
java.lang.String |
getString(java.lang.String key)
Returns the value for a given key in this map, cast to String.
|
java.net.URL |
getUrl(java.lang.String key)
Returns the value for a given key in this map as a URL.
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value) |
clear, clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, toString, values
private final java.util.Map baseMap_
public static final java.util.Map EMPTY
protected SampMap(java.lang.String[] knownKeys)
knownKeys
- array of well-known keys for this classpublic java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
put
in class java.util.AbstractMap
public java.util.Set entrySet()
entrySet
in interface java.util.Map
entrySet
in class java.util.AbstractMap
public void check()
SampUtils.checkMap(java.util.Map)
(ensuring that all keys
are Strings, and all values Strings, Lists or Maps), subclass-specific
invariants may be checked. In the case that there's something wrong,
an informative DataException
will be thrown.DataException
- if this object's current state
is not suitable for SAMP usepublic void checkHasKeys(java.lang.String[] keys)
DataException
will be
thrown. Normally called by check()
.keys
- array of required keys for this mapDataException
- if this object does not contain entries
for all elements of the array keys
public java.lang.String getString(java.lang.String key)
key
public java.util.Map getMap(java.lang.String key)
key
public java.util.List getList(java.lang.String key)
key
public java.net.URL getUrl(java.lang.String key)
key