ListEnumerator Class
The ListEnumerator class lets you traverse the elements in a list.
Syntax
class ListEnumerator extends Object implements Enumerator
Run On
Called
Methods
Method | Description | |
---|---|---|
cancelTimeOut | Cancels a previous method call to the setTimeOut method. (Inherited from Object.) | |
current | Retrieves the value that is pointed to by the enumerator. | |
definitionString | Returns a description of the 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 denotes a valid list element. | |
new | Initializes a new instance of the Object class. (Inherited from Object.) | |
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.) | |
reset | Moves the enumerator to the start of the list. | |
setTimeOut | Sets up the scheduled execution of a specified method. (Inherited from Object.) | |
toString | Returns a description of the content of the element in the list that the enumerator is currently pointing to. (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.) | |
wait | Pauses a process. (Inherited from Object.) | |
xml | Returns an XML string that represents the current object. (Inherited from Object.) |
Top
Remarks
List enumerators start before the first element in the list. You must call the ListEnumerator.moveNext method to make it point to the first element in the list.
It is best practice to use the ListEnumerator class instead of the ListIterator class, because enumerators are automatically created on the same tier as the list (when the list.getEnumerator method is called). This avoids a potential problem in code that is marked as Called from, where the iterator and list can be on separate tiers. In addition, list enumerators require less code than list iterators and therefore perform slightly better. The only situation where you have to use a list iterator is if you want to delete items from a list (use the ListIterator.delete method).
Examples
The following example creates a list of integers and puts some values into it. It then creates an enumerator, and then sets the enumerator to the first element in the list and then the second element in the list.
{
List list = new List(Types::Integer);
ListEnumerator enumerator;
// Add some elements to the list
list.addEnd(1);
list.addEnd(2);
list.addStart(3);
// Set the enumerator
enumerator = list.getEnumerator();
// Print a description of the list
print enumerator.definitionString();
// Go to beginning of enumerator
enumerator.reset();
//Go to the first element in the List
enumerator.moveNext();
// Print contents of first and second elements
// First element is 3 as this was added to start of list
print enumerator.toString();
enumerator.moveNext();
print enumerator.toString();
pause;
}
Inheritance Hierarchy
Object Class
ListEnumerator Class