Methods on Dictionary

This page provides methods available to work with a dictionary. This corresponds to the association of values to a specific key. It allows you to quickly access a value associated with a specific key.

Method Input Types Return Type Description
at(keys) Entity_ (*) Entity_ (*) Returns the values associated with keys.
atAdd(keys, values) Entity_ (*), Entity_ (*) Entity_ (*) Adds values for keys, that is creates associations key, value in the dictionary that includes both the old values and the new ones. Thus, if the keys already exist, the values are added with the existing values, otherwise the keys are created before the associations.
atPut(keys, values) Entity_ (*), Entity_ (*) Entity_ (*) Associates values to keys in a dictionary.

If values are already associated with the keys, they are replaced by the new values.

atRemove(keys, values) Entity_ (*), Entity_ (*) Entity_ (*) Removes the associations key, value.
isEmpty() - Boolean Tests if the dictionary is empty.
keyAtValue(values) Entity_ (*) Entity_ (*) Returns a key corresponding to the values, if exists.
Warning: This method is not intended for intensive use.
keys() - Entity_ (*) Returns all the keys, if not empty.
removeKey(keys) Entity_ (*) Entity_ (*) Removes the values associated with the keys.
stringAt(keys) Entity_ (*) String (*) Returns the values associated with the keys passed in parameter, if these values are strings.
stringKeys() - String (*) Returns all the keys of the dictionary, that are typed as string.
Warning: This method is not intended for intensive use.
values() - Entity_ (*) Returns all the values of a dictionary, if not empty.
Warning: This method is not intended for intensive use.
Note: (*) means list and (?) means optional.

Example of using a dictionary

To use a dictionary, you need first to define a dictionary like the following:

CLASS TestDico : Entity_;

METHOD TestDico.test() : {
  TMP dico := NEW(Dictionary);
  dict.atPut("Blue", "0000FF");
  dict.atPut("Red", "FF0000");
  dict.atAdd("Red", "F00020");
  dict.at("Red");      // "FF0000" $+ "F00020"
  dict.keyAtValue("FF0000" $+ "F00020");      // "Red"
  dict.keys;      // "Red" $+ "Blue"
  dict.values;      //  "FF0000" $+ "F00020" $+ "0000FF"
};