MapEnumerator Class

The MapEnumerator class allows you to traverse through the elements within a map.

class MapEnumerator extends Object implements Enumerator

Run On

Called

Methods

Method

Description

cancelTimeOut

Cancels a previous method call to the Object.setTimeOut Method. (Inherited from Object.)

current

This method is obsolete; use MapEnumerator.currentKey instead.

currentKey

Returns the key from the (key, value) pair that is currently pointed to by the enumerator.

currentValue

Returns the value from the (key, value) pair that is currently pointed to by the enumerator.

definitionString

Returns a description of the enumerator. For example, an enumerator for a map of integers to strings would return "[int -> str] enumerator".

equal

Determines whether the specified object is equal to the current one. (Inherited from Object.)

getTimeOutTimerHandle

Returns the timer handle for the object. (Inherited from Object.)

handle

Retrieves the handle of the class of the object. (Inherited from Object.)

moveNext

Determines whether the enumerator points to a valid map element.

new

Overridden. Creates an enumerator for a map.

notify

Releases the hold on an object that has called a wait method on this object. (Inherited from Object.)

notifyAll

Releases a lock on the object that was issued by a wait method on this object. (Inherited from Object.)

objectOnServer

Determines whether the object is on a server. (Inherited from Object.)

owner

Returns the instance that owns the object. (Inherited from Object.)

reset

Moves the enumerator to point to just before the first element in the map.

setTimeOut

Sets up the scheduled execution of a specified method. (Inherited from Object.)

toString

Overridden. Returns a description of the content of the element in the map the enumerator is currently pointing to.

usageCount

Returns the current number of references (the value of the reference counter) that the object has. (Inherited from Object.)

wait

Pauses a process. (Inherited from Object.)

xml

Returns an XML string that represents the current object. (Inherited from Object.)

Remarks

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).

Example

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;
}

See Also

Map Class

Map.getEnumerator Method

MapIterator Class