Interface: Map Stay organized with collections Save and categorize content based on your preferences.
rules. Map
Map type, used for simple key-value mappings.
Keys must be of typerules.String.
In addition to the methods listed below, maps have the following operators:
| Operator | Usage |
|---|---|
x == y | Compare maps x and y |
x[k] | Index operator, get value at key name k |
x.k | Get value at key name k |
k in x | Check if key k exists in map x |
Methods
diff
diff(map_to_compare) returns rules.MapDiff
Return arules.MapDiff representing the result of comparing the current Map to a comparison Map.
Parameter | |
|---|---|
map_to_compare | A Map to which the current (calling) Map will be compared. Value must not be null. |
- Returns
non-nullrules.MapDiffobject representing the result of the comparison.
get
get(key, default_value) returns value
Returns the value associated with a given search key string.
For nested Maps, involving keys andsub-keys, returns the value associated with a given sub-key string. The sub-key is identified using a list, the first item of which is a top-level key and the last item the sub-key whose value is to be looked up and returned. See the nested Map example below.
The function requires a default value to return if no match to the given search key is found.
Parameter | |
|---|---|
key | (non-nullrules.String or non-nullrules.List) Either a key specified as a string, or for nested Maps, a sub-key specified using list syntax. |
default_value | default_value Value to return if the Map does not contain the given search key. Can be any Rules language type. |
- Returns
valueValue corresponding to the givenkey, or the default return value specified bydefault_valueif no match to the given key is found. Since Map contents are user-defined, the data type of the returnedvaluecan be any Rules language type.
Example
// "c" is not a key in the supplied Map, returns default value 7.{"a":3,"b":2}.get("c",7) ==7// Default result can be any type, e.g. a list such as [1, 1].{"a":[2,7],"b":[9,12]}.get("c",[1,1]) ==[1,1]// Return a list on a successful match.{"a":[2,7],"b":[9,12]}.get("b",[1,1]) ==[9,12]// For nested Maps, use list ["a", "b"] to specify lookup on sub-key "b".{"a":{"b":1},"c":2}.get(["a","b"],7) ==1keys
keys() returns rules.List
Get the list of keys in the map.
- Returns
non-nullrules.Listlist of keys.
size
size() returns rules.Integer
Get the number of entries in the map.
- Returns
non-nullrules.Integernumber of entries.
values
values() returns rules.List
Get the list of values in the map.
- Returns
non-nullrules.Listlist of values.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-03-04 UTC.