AI2 Component  (Version nb184)
com.google.appinventor.components.runtime.util.YailDictionary Class Reference
Inheritance diagram for com.google.appinventor.components.runtime.util.YailDictionary:
com.google.appinventor.components.runtime.util.YailObject< YailList >

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< YailListiterator ()
 
- Public Member Functions inherited from com.google.appinventor.components.runtime.util.YailObject< YailList >
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
 

Detailed Description

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.

Author
data1.nosp@m.013@.nosp@m.mit.e.nosp@m.du (Danny Tang)

Definition at line 32 of file YailDictionary.java.

Constructor & Destructor Documentation

◆ YailDictionary() [1/2]

com.google.appinventor.components.runtime.util.YailDictionary.YailDictionary ( )

Create an empty YailDictionary.

Definition at line 46 of file YailDictionary.java.

◆ YailDictionary() [2/2]

com.google.appinventor.components.runtime.util.YailDictionary.YailDictionary ( Map< Object, Object >  prevMap)

Definition at line 50 of file YailDictionary.java.

Member Function Documentation

◆ alistToDict()

static YailDictionary com.google.appinventor.components.runtime.util.YailDictionary.alistToDict ( YailList  alist)
static

Definition at line 159 of file YailDictionary.java.

◆ containsKey()

boolean com.google.appinventor.components.runtime.util.YailDictionary.containsKey ( Object  key)

Definition at line 500 of file YailDictionary.java.

◆ containsValue()

boolean com.google.appinventor.components.runtime.util.YailDictionary.containsValue ( Object  value)

Definition at line 508 of file YailDictionary.java.

◆ dictToAlist()

static YailList com.google.appinventor.components.runtime.util.YailDictionary.dictToAlist ( YailDictionary  dict)
static

Definition at line 227 of file YailDictionary.java.

◆ get()

Object com.google.appinventor.components.runtime.util.YailDictionary.get ( Object  key)

Definition at line 516 of file YailDictionary.java.

◆ getObject()

Object com.google.appinventor.components.runtime.util.YailDictionary.getObject ( int  index)

Definition at line 552 of file YailDictionary.java.

◆ getObjectAtKeyPath()

Object com.google.appinventor.components.runtime.util.YailDictionary.getObjectAtKeyPath ( List<?>  keysOrIndices)

Definition at line 262 of file YailDictionary.java.

◆ iterator()

Iterator<YailList> com.google.appinventor.components.runtime.util.YailDictionary.iterator ( )

Definition at line 570 of file YailDictionary.java.

◆ makeDictionary() [1/4]

static YailDictionary com.google.appinventor.components.runtime.util.YailDictionary.makeDictionary ( )
static

Create an empty YailDictionary.

Definition at line 58 of file YailDictionary.java.

◆ makeDictionary() [2/4]

static YailDictionary com.google.appinventor.components.runtime.util.YailDictionary.makeDictionary ( List< YailList pairs)
static

Construct a new dictionary from a list of pairs stored in

YailList

s.

Parameters
pairsThe list of pairs used to populate the dictionary.
Returns
A newly constructed dictionary from the pairs.
Exceptions
IndexOutOfBoundsExceptionif any of the lists isn't a pair.

Definition at line 119 of file YailDictionary.java.

◆ makeDictionary() [3/4]

static YailDictionary com.google.appinventor.components.runtime.util.YailDictionary.makeDictionary ( Map< Object, Object >  prevMap)
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.

Parameters
prevMapThe existing collection to use in the YailDictionary.
Returns
A new YailDictionary that is a shallow copy of
prevMap
.

Definition at line 71 of file YailDictionary.java.

◆ makeDictionary() [4/4]

static YailDictionary com.google.appinventor.components.runtime.util.YailDictionary.makeDictionary ( Object...  keysAndValues)
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 }

Parameters
keysAndValuesThe list of key-value pairs to be added to the YailDictionary.
Returns
A newly constructed YailDictionary object.

Definition at line 100 of file YailDictionary.java.

◆ put()

Object com.google.appinventor.components.runtime.util.YailDictionary.put ( Object  key,
Object  value 
)

Definition at line 524 of file YailDictionary.java.

◆ remove()

Object com.google.appinventor.components.runtime.util.YailDictionary.remove ( Object  key)

Definition at line 535 of file YailDictionary.java.

◆ setPair()

void com.google.appinventor.components.runtime.util.YailDictionary.setPair ( YailList  pair)

Definition at line 235 of file YailDictionary.java.

◆ setValueForKeyPath()

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.

  1. The item at a given point in the path is not a list or a dictionary
  2. The key in the path is mismatched to the data type at that location in the data structure. For example, a string is given as the key but the data structure at that point in the traversal is a list.
  3. The data structure at a given point in the traversal is a list and the key is a number, but the value is out of bounds for the list.
Parameters
keysa list of keys to traverse in the dictionary
valuethe 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.

◆ toString()

String com.google.appinventor.components.runtime.util.YailDictionary.toString ( )

Definition at line 543 of file YailDictionary.java.

◆ walkKeyPath()

static <T> List<Object> com.google.appinventor.components.runtime.util.YailDictionary.walkKeyPath ( YailObject<?>  object,
List< T >  keysOrIndices 
)
static

Definition at line 361 of file YailDictionary.java.

Member Data Documentation

◆ ALL

final Object com.google.appinventor.components.runtime.util.YailDictionary.ALL
static
Initial value:
= new Object() {
@Override
public String toString() {
return "ALL_ITEMS";
}
}

Definition at line 36 of file YailDictionary.java.


The documentation for this class was generated from the following file:
com.google.appinventor.components.runtime.util.YailDictionary.toString
String toString()
Definition: YailDictionary.java:543