MapEnumerator Class
The MapEnumerator class allows you to traverse through the elements within a map.
class MapEnumerator extends Object
|
Method |
Description |
|---|---|
|
Obsolete; use MapEnumerator.currentKey instead. | |
|
Returns the key from the (key, value) pair that is currently pointed to by the enumerator. | |
|
Returns the value from the (key, value) pair that is currently pointed to by the enumerator. | |
|
Returns a description of the enumerator. | |
|
Determines whether the enumerator points to a valid map element. | |
|
Creates an enumerator for a map. | |
|
Moves the enumerator to point to just before the first element in the map. | |
|
Returns a description of the content of the element in the map that the enumerator is currently pointing to. |
Map enumerators start before the first element in the list. You must call the MapEnumerator.moveNext method to make it point to the first element in the list.
It is a best practice to use the MapEnumerator class instead of the MapIterator class, because enumerators are automatically created on the same tier as the map (when calling the Map.getEnumerator method). Using the MapIterator class avoids a potential problem in code marked as Called from, where the iterator and map can end up on separate tiers. In addition, because map enumerators require less code than map iterators, they perform slightly better. The only situation where you have to use a map iterator, is when you want to delete items from a list (use the MapIterator.delete method).
The following example creates a map for the tables contained within a project. An enumerator is created for the map, and the MapEnumerator.moveNext method is used to iterate over the tables. The MapEnumerator.currentKey method is used to add the name of each table in the original map as the key for each element in a new map, and a DictTable object is created as the value for each element in the new map. (DictTable allows you to access information about a table.)
{
Map map = Map::create(
SysUmlDataModel::getProjectTablesClient(projectNode));
MapEnumerator enum = map.getEnumerator();
TableName tableName;
;
while (enum.moveNext())
{
tableName = enum.currentKey();
map.insert(tableName, new DictTable(tablename2id(tableName)));
}
return map;
}