MapIterator Class
The MapIterator class is used to iterate over the elements in a map.
Syntax
class MapIterator extends Object
Run On
Called
Methods
Method | Description | |
---|---|---|
begin | Moves the iterator to the start of the map. | |
cancelTimeOut | Cancels a previous method call to the setTimeOut method. (Inherited from Object.) | |
definitionString | Retrieves a textual representation of the iterator type, for example, the "[int -> str] iterator". | |
delete | Removes the element that is pointed to by the iterator from the map. | |
domainValue | Returns the value of the key in the (key, value) pair that is referred to by the iterator. | |
end | Moves the iterator past the last element in the map. | |
equal | Determines whether the specified object is equal to the current one. (Inherited from Object.) | |
find | Searches for the specified key value. | |
getTimeOutTimerHandle | Returns the timer handle for the object. (Inherited from Object.) | |
handle | Retrieves the handle of the class of the object. (Inherited from Object.) | |
key | Returns the key from the (key, value) pair that is referred to by the iterator. | |
more | Determines whether the iterator finds a valid (key, value) pair. | |
new | Creates a new iterator for a map that allows you to traverse through the elements in the map. (Overrides the new Method.) | |
next | Moves the iterator to the next (key, value) pair. | |
notify | Releases the hold on an object that has called the wait method on this object. (Inherited from Object.) | |
notifyAll | Releases a lock on the object that was issued by the 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.) | |
rangeValue | Returns the value of the "value" in the (key, value) pair referred to by the iterator. | |
setTimeOut | Sets up the scheduled execution of a specified method. (Inherited from Object.) | |
toString | Retrieves a textual representation of the iterator. (Overrides the toString Method.) | |
usageCount | Returns the current number of references, that is, the value of the reference counter, that the object has. (Inherited from Object.) | |
value | Returns the value from the (key, value) pair referred to by the iterator. | |
valuePair | Retrieves a container that contains the key and the value. | |
wait | Pauses a process. (Inherited from Object.) | |
xml | Returns an XML string that represents the current object. (Inherited from Object.) |
Top
Remarks
Map iterators are used to iterate over the elements in a map. They can be viewed as simple pointers into the maps over which they iterate. Functionality is available to start the iteratation, to determine whether more (key, value) pairs are available, and to fetch the element pointed to by the iterator.
It is better to use than MapIterator. Map iterators and the maps over which they iterate must be on the same Client/Server side. If you use MapIterator, and code is marked as Called from, it is possible that the map and the iterator will end up on different tiers, and the code will fail. If you use MapEnumerator, the enumerator is automatically created on the same tier as the map. Also, to move to the next item in a map you must explicitly call the more and next methods if you are using a map iterator. If you use MapEnumerator, you only have to call moveNext method.
The sequence in which the elements are inserted does not determine the order in which they occur. The order is defined by the ordering of the elements. Elements with lower keys appear before elements with higher keys. The usual ordering for the types is used. However, if the keys are objects, the addresses of the objects are used to supply the ordering and no specific ordering may consequently be inferred. The addresses of the objects are transient by nature.
Examples
The following example creates a map and adds three key, value pairs. It then iterates through the map, printing out information about each map element.
{
Map iim = new Map(Types::Integer, Types::Class);
MapIterator it;
// Add some elements into the map
iim.insert(1, new query());
iim.insert(2, new query());
iim.insert(4, new query());
// Create a map iterator
it = new MapIterator (iim);
// Print "[int -> class] iterator"
print it.definitionString();
// Go on for as long as elements are found in the map
while (it.more())
{
// Print each key (1, 2, 4)
print it.key();
// Print text representation of each value
print it.value().toString();
// Fetch next element in map
it.next();
}
pause;
}
Inheritance Hierarchy
Object Class
MapIterator Class