1 package com.ubermq.kernel.chooser; 2 3 import com.ubermq.kernel.*; 4 import java.util.*; 5 6 14 abstract class AbstractOrderedChooser 15 implements Chooser 16 { 17 int size; 18 List myList; 19 20 AbstractOrderedChooser() 21 { 22 reset(); 23 } 24 25 public void reset() 26 { 27 size = 0; 28 myList = null; 29 } 30 31 49 public Object choose(Collection objects) 50 { 51 if (!(objects instanceof List)) 52 throw new IllegalArgumentException ("Collection must implement List."); 53 54 if (myList == null) 56 { 57 myList = (List)objects; 58 size = myList.size(); 59 } 60 61 if (myList == objects) 63 { 64 return choose(); 65 } 66 else 67 { 68 throw new IllegalStateException (); 69 } 70 } 71 72 75 abstract Object choose(); 76 } 77 | Popular Tags |