Map (Foundation class)
From Axaptapedia
Map (Foundation class) consist of a data set that contains a key and a corresponding value, where the key is unique. The key and the value need not be from the same data type.
A Map is alway sorted on the key value.
Contents |
[edit]
How to use
[edit]
Define
Map m = new Map(Types::STRING, Types::INTEGER);
[edit]
Insert a value
m.insert("Wassini", 37); m.insert("Eric", 102);
[edit]
Exists value
To see if a value already is added, use the exists method:
if (m.exists("Wassini")) print "Yes!"; else print "No!";
[edit]
Getting values
There are several ways to get the values in the map.
- Using a MapIterator
- Using a direct method
[edit]
MapIterator
The MapIterator loops throug the complete map:
MapIterator mi; mi = new MapIterator(m); while (mi.more()) { print mi.key(); print mi.value(); mi.next(); }
[edit]
Direct method
It is possible to get find a specific value from the key:
print m.lookup("Wassini");
[edit]
Removing values
Just use the remove method to remove the active key/value pair.
m.remove("Wassini");
[edit]
Updating values
It is not possible to update a value directly:
int age; str keyid = "Wassini"; age = m.lookup(keyid); m.remove(keyid); m.insert(keyid, age + 1);
[edit]
Other methods
// Get number of elements: print m.elements(); // Get the used types: print m.definitionString(); // Dump the whole map as a string: print m.toString();
[edit]