KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > co > jezuk > mango > algorithms > Partition


1 package uk.co.jezuk.mango.algorithms;
2
3 /**
4  * @version $Id: Partition.java 60 2002-06-12 13:47:08Z jez $
5  */

6 public class Partition
7 {
8   static public java.util.Collection JavaDoc execute(java.util.Iterator JavaDoc iterator, uk.co.jezuk.mango.Predicate test, java.util.Collection JavaDoc results)
9   {
10     if((iterator == null) || (test == null))
11       return results;
12
13     while(iterator.hasNext())
14     {
15       Object JavaDoc obj = iterator.next();
16       if(test.test(obj))
17             {
18                 iterator.remove();
19                 if(results != null)
20                     results.add(obj);
21             } // if ...
22
} // while ...
23

24         return results;
25   } // execute
26

27   private Partition() { }
28 } // Partition
29
Popular Tags