API Docs - v5.0.3
Tested Siddhi Core version: 5.0.2
It could also support other Siddhi Core minor versions.
Map
create (Function)
Function creates a map pairing the keys and their corresponding values.
Syntax<OBJECT> map:create(<OBJECT|INT|LONG|FLOAT|DOUBLE|FLOAT|BOOL|STRING> key1, <OBJECT|INT|LONG|FLOAT|DOUBLE|FLOAT|BOOL|STRING> value1)
<OBJECT> map:create(<OBJECT|INT|LONG|FLOAT|DOUBLE|FLOAT|BOOL|STRING> key1, <OBJECT|INT|LONG|FLOAT|DOUBLE|FLOAT|BOOL|STRING> value1, <OBJECT|INT|LONG|FLOAT|DOUBLE|FLOAT|BOOL|STRING> ...)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
key1 | Key 1 | OBJECT INT LONG FLOAT DOUBLE FLOAT BOOL STRING |
No | Yes | |
value1 | Value 1 | OBJECT INT LONG FLOAT DOUBLE FLOAT BOOL STRING |
No | Yes |
Examples EXAMPLE 1
map:create(1, 'one', 2, 'two', 3, 'three')
This returns a map with keys 1
, 2
, 3
mapped with their corresponding values, one
, two
, three
.
createFromJSON (Function)
Function returns the map created by pairing the keys with their corresponding values given in the JSON string.
Syntax<OBJECT> map:createFromJSON(<STRING> json.string)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
json.string | JSON as a string, which is used to create the map. | STRING | No | Yes |
Examples EXAMPLE 1
map:createFromJSON("{?symbol' : 'IBM', 'price' : 200, 'volume' : 100}")
This returns a map with the keys symbol
, price
, and volume
, and their values, IBM
, 200
and 100
respectively.
createFromXML (Function)
Function returns the map created by pairing the keys with their corresponding values,given as an XML string.
Syntax<OBJECT> map:createFromXML(<STRING> xml.string)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
xml.string | The XML string, which is used to create the map. | STRING | No | Yes |
Examples EXAMPLE 1
map:createFromXML("<stock>
<symbol>IBM</symbol>
<price>200</price>
<volume>100</volume>
</stock>")
This returns a map with the keys symbol
, price
, volume
, and with their values IBM
, 200
and 100
respectively.
get (Function)
Function returns the value corresponding to the given key from the map.
Syntax<OBJECT> map:get(<OBJECT> map, <OBJECT|INT|LONG|FLOAT|DOUBLE|FLOAT|BOOL|STRING> key)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
map | The map from where the value should be obtained. | OBJECT | No | Yes | |
key | The key to fetch the value. | OBJECT INT LONG FLOAT DOUBLE FLOAT BOOL STRING |
No | Yes |
Examples EXAMPLE 1
map:get(companyMap, 1)
If the companyMap has key 1
and value ABC
in it's set of key value pairs. The function returns ABC
.
EXAMPLE 2
map:get(companyMap, 2)
If the companyMap does not have any value for key 2
then the function returns null
.
isMap (Function)
Function checks if the object is type of a map.
Syntax<BOOL> map:isMap(<OBJECT|INT|LONG|FLOAT|DOUBLE|FLOAT|BOOL|STRING> arg)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
arg | The argument the need to be determined whether it's a map or not. | OBJECT INT LONG FLOAT DOUBLE FLOAT BOOL STRING |
No | Yes |
Examples EXAMPLE 1
map:isMap(students)
Returns 'true' if the students is and an instance of java.util.Map
else it returns false
.
put (Function)
Function returns the updated map after adding the given key-value pair. If the key already exist in the map the key is updated with the new value.
Syntax<OBJECT> map:put(<OBJECT> map, <OBJECT|INT|LONG|FLOAT|DOUBLE|FLOAT|BOOL|STRING> key, <OBJECT|INT|LONG|FLOAT|DOUBLE|FLOAT|BOOL|STRING> value)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
map | The map to which the value should be added. | OBJECT | No | Yes | |
key | The key to be added. | OBJECT INT LONG FLOAT DOUBLE FLOAT BOOL STRING |
No | Yes | |
value | The value to be added. | OBJECT INT LONG FLOAT DOUBLE FLOAT BOOL STRING |
No | Yes |
Examples EXAMPLE 1
map:put(students , 1234 , 'sam')
Function returns the updated map named students after adding the value sam
with the key 1234
.
putAll (Function)
Function returns the updated map after adding all the key-value pairs from another map. If there are duplicate keys, the key will be assigned new values from the map that's being copied.
Syntax<OBJECT> map:putAll(<OBJECT> to.map, <OBJECT> from.map)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
to.map | The map into which the key-values need to copied. | OBJECT | No | Yes | |
from.map | The map from which the key-values are copied. | OBJECT | No | Yes |
Examples EXAMPLE 1
map:putAll(toMap, fromMap)
If toMap
contains key-value pairs ('symbol': 'wso2'), ('volume' : 100), and if fromMap
contains key-value pairs ('symbol': 'IBM'), ('price' : 12), then the function returns updated toMap
with key-value pairs ('symbol': 'IBM'), ('price' : 12), ('volume' : 100).
remove (Function)
Function returns the updated map after removing the element with the specified key.
Syntax<OBJECT> map:remove(<OBJECT> map, <OBJECT|INT|LONG|FLOAT|DOUBLE|FLOAT|BOOL|STRING> key)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
map | The map that needs to be updated. | OBJECT | No | Yes | |
key | The key of the element that needs to removed. | OBJECT INT LONG FLOAT DOUBLE FLOAT BOOL STRING |
No | Yes |
Examples EXAMPLE 1
map:remove(students, 1234)
This returns the updated map, students after removing the key-value pair corresponding to the key 1234
.
toJSON (Function)
Function converts a map into a JSON object and returns the JSON as a string.
Syntax<STRING> map:toJSON(<OBJECT> map)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
map | The map that needs to be converted to JSON | OBJECT | No | Yes |
Examples EXAMPLE 1
map:toJSON(company)
If company
is a map with key-value pairs, ('symbol': 'wso2'),('volume' : 100), and ('price', 200), it returns the JSON string {"symbol" : "wso2", "volume" : 100 , "price" : 200}
.
toXML (Function)
Function returns the map as an XML string.
Syntax<STRING> map:toXML(<OBJECT> map)
<STRING> map:toXML(<OBJECT> map, <OBJECT|STRING> root.element.name)
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
map | The map that needs to be converted to XML. | OBJECT | No | Yes | |
root.element.name | The root element of the map. | The XML root element will be ignored | OBJECT STRING |
Yes | Yes |
Examples EXAMPLE 1
toXML(company, 'abcCompany')
If company
is a map with key-value pairs, ('symbol' : 'wso2'), ('volume' : 100), and ('price' : 200), this function returns XML as a string, <abcCompany><symbol>wso2</symbol><volume><100></volume><price>200</price></abcCompany>
.
EXAMPLE 2
toXML(company)
If company
is a map with key-value pairs, ('symbol' : 'wso2'), ('volume' : 100), and ('price' : 200), this function returns XML without root element as a string, <symbol>wso2</symbol><volume><100></volume><price>200</price>
.