|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--edu.ull.cgunay.utils.Iteration
Allows iterating on the Collections of JAVA 2 SDK with a high level interface.
In summary, a given Task is executed for all items
in a given Collection when an appropriate
loop() method is invoked.
This scheme allows
generalizing commonly used iterations in template classes.
This is a vast improvement allowing object oriented
control over the primitive looping constructs
for and while.
This file contains alternative methods for iteration.
The collection on which to iterate can be chosen either at
the constructor or at the loop() function for the non-static use.
It is left to the
user to decide if the class is made to iterate on a single collection or if it is rather
a generic iteration facility that can be applied to many collections at different times.
On the other hand, static methods allow iterating without
requiring an instance of this class. However, in this case an
instance of the Task class has to be provided in calls to the
loop(Collection,Task) method.
See the examples below for details on use.
Note: The loop() methods of this class throws
BreakOutOfIterationException to enable the user to have control
on the iteration. If this is undesired, the subclass UninterruptedIteration
should be used instead.
Example of static use:
Iteration.loop(collection, new Task() {
public void job(Object o) {
// do something on o here
}
});
Example of non-static repeatedly use of same task on different collections:
new Iteration() {
public void job(Object o) {
// do something on o here
}
}.loop(collection);
Example of non-static repeatedly use of same task with same collection:
new Iteration(collection) {
public void job(Object o) {
// do something on o here
}
}.loop();
Created: Sat Nov 25 04:18:32 2000
Collection,
Iterator,
Task,
Serialized Form| Field Summary | |
(package private) Collection |
collection
Collection to be iterated on for non-static loop() function. |
| Constructor Summary | |
Iteration()
Dummy. |
|
Iteration(Collection collection)
Sets the collection to be iterated on (for the non-static loop()). |
|
| Method Summary | |
void |
loop()
Iterates on collection set by the constructor. |
void |
loop(Collection c)
Iterates on c with the Task given in this class. |
static void |
loop(Collection c,
Task t)
Convenience method with Collection parameter, calls another
loop() method. |
static void |
loop(Iterator i,
Task t)
Loop on Iterator values calling Task. |
void |
loop(Object[] array)
Convenience method with Collection parameter, calls another
loop() method. |
static void |
loop(Object[] array,
Task t)
Loop on Object[] values calling Task. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface edu.ull.cgunay.utils.Task |
job |
| Field Detail |
Collection collection
loop()| Constructor Detail |
public Iteration()
public Iteration(Collection collection)
loop()).
collection - a Collection valueloop()| Method Detail |
public void loop()
throws BreakOutOfIterationException
BreakOutOfIterationException - if received from given Task instanceIteration(Collection)
public void loop(Collection c)
throws BreakOutOfIterationException
c with the Task given in this class.
c - a Collection value
BreakOutOfIterationException - if received from given Task instanceTask,
loop()
public static void loop(Iterator i,
Task t)
throws BreakOutOfIterationException
Iterator values calling Task.
i - an Iterator valuet - a Task value
BreakOutOfIterationException - if received from given Task instanceTask.job(java.lang.Object)
public static void loop(Object[] array,
Task t)
throws BreakOutOfIterationException
Object[] values calling Task.
array - an Object[] valuet - a Task value
BreakOutOfIterationException - if an error occurs
public void loop(Object[] array)
throws BreakOutOfIterationException
Collection parameter, calls another
loop() method.
array - an Object[] value
BreakOutOfIterationException - if an error occurs
public static void loop(Collection c,
Task t)
throws BreakOutOfIterationException
Collection parameter, calls another
loop() method.
c - a Collection valuet - a Task value
BreakOutOfIterationException - if received from given Task instanceloop(Iterator,Task)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||