Class R.lang.Iterator
Extends
R.engine.PooledObject.
Create an iterator over a R.struct.Container or Array
instance. An
iterator is a convenient object to traverse the list of objects
within the container. The benefit of using an iterator with a R.struct.Container
is
that if the container is modified, the R.lang.Iterator
will reflect these changes.
for (var itr = R.lang.Iterator.create(containerObj); itr.hasNext(); ) { // Get the next object in the container var o = itr.next(); // Do something with the object o.doSomething(); } // Destroy the iterator when done itr.destroy();The last step is important so that you're not creating a lot of objects, especially if the iterator is used repeatedly. Since the iterator is a pooled object, it will be reused.
Defined in: iterator.js.
Constructor Attributes | Constructor Name and Description |
---|---|
R.lang.Iterator(container)
Create an iterator over a collection
|
Method Attributes | Method Name and Description |
---|---|
Get the class name of this object
|
|
hasNext()
Returns true if the iterator has more elements.
|
|
next()
Get the next element from the iterator.
|
|
over(container)
Create an instance of an iterator over the given container.
|
|
release()
Release the iterator back into the object pool.
|
|
reset()
Reset the iterator to the start of the collection.
|
|
reverse()
Reverse the order of the elements in the container (non-destructive) before
iterating over them.
|
- Methods borrowed from class R.engine.PooledObject:
- clearObjectDataModel, destroy, getId, getName, getObjectDataModel, getProperties, isDestroyed, setName, setObjectDataModel, toString, toXML
Class Detail
R.lang.Iterator(container)
Create an iterator over a collection
- Parameters:
- container
- {R.struct.Container} The container to iterate over.
Method Detail
{String}
getClassName()
Get the class name of this object
- Returns:
- {String} "R.lang.Iterator"
{Boolean}
hasNext()
Returns true if the iterator has more elements.
- Returns:
- {Boolean}
{Object}
next()
Get the next element from the iterator.
- Throws:
- {Error}
- An error if called when no more elements are available
- Returns:
- {Object} The next element in the iterator
{R.lang.Iterator}
over(container)
Create an instance of an iterator over the given container.
- Parameters:
- container
- {R.struct.Container|Array} An
Array
or R.struct.Container
- Returns:
- {R.lang.Iterator} An iterator over the container
release()
Release the iterator back into the object pool.
reset()
Reset the iterator to the start of the collection.
reverse()
Reverse the order of the elements in the container (non-destructive) before
iterating over them. You cannot call this method after you have called #next,
otherwise, use #reset before calling this method.