An iterator is language michanism that facilitates successive enumeration of all the elements of a collection in some definite order. Java provides an iterator-like interface called Enumeration. The implementation model imposed by enumerations is know...
An iterator is language michanism that facilitates successive enumeration of all the elements of a collection in some definite order. Java provides an iterator-like interface called Enumeration. The implementation model imposed by enumerations is known as cursor objects. It is not a simple task, however, to develop enumerations for non-linear data structures or for those with complex control in terms of cursors because the enumeration procedure for a cursor is confined to use only simple control structures.
In this paper, a new iterator mechanism is proposed for Java in which enumeration provedures can be described as if they were ordinary traversal procedures. It is allowed to use arbitrary control structrues such as recursive calls or infinite loops when developing enumeration procedures. Iterators are defined to implement the Enumeratio interface, and thus can be used in place of ordinary enumerations. The proposed iterator mechanism was implemented experimentally using threads and a zero-sized buffer.