KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ubermq > kernel > chooser > SequentialChooser


1 package com.ubermq.kernel.chooser;
2
3 import com.ubermq.kernel.*;
4 import java.util.*;
5
6 /**
7  * Chooses an object sequentially from the
8  * given List until the end of the List,
9  * at which point the choose() method
10  * returns null.
11  */

12 public class SequentialChooser
13     extends AbstractOrderedChooser
14     implements Chooser
15 {
16     private int n;
17
18     public void reset()
19     {
20         super.reset();
21         n = 0;
22     }
23
24     /**
25      * Chooses the next object in
26      * the collection. If there are no remaining
27      * objects in the collection, null is returned.<P>
28      *
29      * @param objects a List of objects
30      * @return an Object r, such that <code>objects.contains(r)</code> is true.
31      * @throws IllegalStateException if the chooser can
32      * only operate on a single Collection object, and
33      * the Collection does not match that of the previous
34      * caller.
35      */

36     public Object JavaDoc choose()
37     {
38         if (n < size)
39             return myList.get(n++);
40         else
41             return null;
42     }
43
44 }
45
Popular Tags