![]() |
AI2 Component
(Version nb184)
|
Public Member Functions | |
YailDictionary () | |
YailDictionary (Map< Object, Object > prevMap) | |
void | setPair (YailList pair) |
Object | getObjectAtKeyPath (List<?> keysOrIndices) |
void | setValueForKeyPath (List<?> keys, Object value) |
boolean | containsKey (Object key) |
boolean | containsValue (Object value) |
Object | get (Object key) |
Object | put (Object key, Object value) |
Object | remove (Object key) |
String | toString () |
Object | getObject (int index) |
Iterator< YailList > | iterator () |
![]() | |
Object | getObject (int index) |
int | size () |
boolean | isEmpty () |
Iterator< T > | iterator () |
Static Public Member Functions | |
static YailDictionary | makeDictionary () |
static YailDictionary | makeDictionary (Map< Object, Object > prevMap) |
static YailDictionary | makeDictionary (Object... keysAndValues) |
static YailDictionary | makeDictionary (List< YailList > pairs) |
static YailDictionary | alistToDict (YailList alist) |
static YailList | dictToAlist (YailDictionary dict) |
static< T > List< Object > | walkKeyPath (YailObject<?> object, List< T > keysOrIndices) |
Static Public Attributes | |
static final Object | ALL |
The YailList is a wrapper around the gnu.list.Pair class used by the Kawa framework. YailList is the main list primitive used by App Inventor components.
Definition at line 32 of file YailDictionary.java.
com.google.appinventor.components.runtime.util.YailDictionary.YailDictionary | ( | ) |
Create an empty YailDictionary.
Definition at line 46 of file YailDictionary.java.
com.google.appinventor.components.runtime.util.YailDictionary.YailDictionary | ( | Map< Object, Object > | prevMap | ) |
Definition at line 50 of file YailDictionary.java.
|
static |
Definition at line 159 of file YailDictionary.java.
boolean com.google.appinventor.components.runtime.util.YailDictionary.containsKey | ( | Object | key | ) |
Definition at line 500 of file YailDictionary.java.
boolean com.google.appinventor.components.runtime.util.YailDictionary.containsValue | ( | Object | value | ) |
Definition at line 508 of file YailDictionary.java.
|
static |
Definition at line 227 of file YailDictionary.java.
Object com.google.appinventor.components.runtime.util.YailDictionary.get | ( | Object | key | ) |
Definition at line 516 of file YailDictionary.java.
Object com.google.appinventor.components.runtime.util.YailDictionary.getObject | ( | int | index | ) |
Definition at line 552 of file YailDictionary.java.
Object com.google.appinventor.components.runtime.util.YailDictionary.getObjectAtKeyPath | ( | List<?> | keysOrIndices | ) |
Definition at line 262 of file YailDictionary.java.
Iterator<YailList> com.google.appinventor.components.runtime.util.YailDictionary.iterator | ( | ) |
Definition at line 570 of file YailDictionary.java.
|
static |
Create an empty YailDictionary.
Definition at line 58 of file YailDictionary.java.
|
static |
Construct a new dictionary from a list of pairs stored in
s.
pairs | The list of pairs used to populate the dictionary. |
IndexOutOfBoundsException | if any of the lists isn't a pair. |
Definition at line 119 of file YailDictionary.java.
|
static |
Create a YailDictionary containing the contents of the given Map. The caller is responsible for ensuring that the contents of the map are coercible to types in YAIL.
prevMap | The existing collection to use in the YailDictionary. |
Definition at line 71 of file YailDictionary.java.
|
static |
Create a YailDictionary from the given list of keys and values. The list must have an even number of entries with the key first and value second for each pair of values.
For example:
YailDictionary.makeDictionary("foo", 1, "bar", 2);
will yield a YailDictionary object equivalent to the JSON:
{ "foo": 1, "bar": 2 }
keysAndValues | The list of key-value pairs to be added to the YailDictionary. |
Definition at line 100 of file YailDictionary.java.
Object com.google.appinventor.components.runtime.util.YailDictionary.put | ( | Object | key, |
Object | value | ||
) |
Definition at line 524 of file YailDictionary.java.
Object com.google.appinventor.components.runtime.util.YailDictionary.remove | ( | Object | key | ) |
Definition at line 535 of file YailDictionary.java.
void com.google.appinventor.components.runtime.util.YailDictionary.setPair | ( | YailList | pair | ) |
Definition at line 235 of file YailDictionary.java.
void com.google.appinventor.components.runtime.util.YailDictionary.setValueForKeyPath | ( | List<?> | keys, |
Object | value | ||
) |
Sets the value for the given key path.
Key traversal occurs for both dictionaries and arrays. Consider the following JSON data structure:
{
"data": [
{
"id": 1,
"name": "Foo",
"address": {
"number": 77,
"street": "Massachusetts Avenue"
}
}, {
"id": 2,
"name": "Bar"
"address": {
"number": 32,
"street": "Vassar Street"
}
}
]
}
Calling setValueForKeyPath
with the path ["data", 1, "name"] and the value "Baz" will update name of the first value from "Foo" to "Baz". This method will work so long as the path represented by the n-1 elements in the path exist in the data structure. Following the previous example, if one used the path ["data", 1, "course"] with the value 6, the first data element would have the course field added with the value 6:
{
"id": 1,
"name": "Baz",
"address": {
"number": 77,
"street": "Massachusetts Avenue"
},
"course": 6
}
If the last item in the path is a list and the given path index is a number, the item at the given index in the list will be replaced.
There are X error conditions that can occur when performing this operation. If an error occurs, it is thrown as a DispatchableError, which will result in the Screen's ErrorOccurred event to run.
keys | a list of keys to traverse in the dictionary |
value | the value to set at the end of the key path if the first n-1 keys map to a valid object. |
Definition at line 469 of file YailDictionary.java.
String com.google.appinventor.components.runtime.util.YailDictionary.toString | ( | ) |
Definition at line 543 of file YailDictionary.java.
|
static |
Definition at line 361 of file YailDictionary.java.
|
static |
Definition at line 36 of file YailDictionary.java.