KickJava   Java API By Example, From Geeks To Geeks.

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


1 package uk.co.jezuk.mango.algorithms;
2
3 /**
4  * Searchs the sequence travesed by the Iterator for the given value.
5  * Returns the <code>Object</code>, or <code>null</code> if the value
6  * is not found. The iterator will have been advanced to the next object
7  * in the sequence.
8  * The objects in the sequence and <code>value</code> must be comparable using
9  * <code>Object.equals</code> (unless <code>value</code> is <code>null</code>).
10  * @see FindIf
11  * @see FindNotIf
12  * @version $Id: Find.java 93 2004-05-25 20:34:19Z jez $
13  */

14 public class Find
15 {
16   static public Object JavaDoc execute(java.util.Iterator JavaDoc iterator, Object JavaDoc value)
17   {
18     if((iterator == null) || (value == null))
19       return null;
20
21     while(iterator.hasNext())
22     {
23       Object JavaDoc obj = iterator.next();
24       if(value.equals(obj))
25     return obj;
26     } // while ...
27

28     return null;
29   } // execute
30

31   private Find() { }
32 } // Find
33
Popular Tags