KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > example > MovieLister


1 package example;
2
3 import java.util.List JavaDoc;
4
5 public class MovieLister {
6   private MovieFinder _finder;
7   
8   /**
9    * Sets the finder.
10    */

11   public void setFinder(MovieFinder finder)
12   {
13     _finder = finder;
14   }
15   
16   /**
17    * Returns movies by a particular director.
18    */

19   public Movie []moviesDirectedBy(String JavaDoc director)
20   {
21     List JavaDoc movies = _finder.findAll();
22
23     for (int i = movies.size() - 1; i >= 0; i--) {
24       Movie movie = (Movie) movies.get(i);
25
26       if (! director.equals(movie.getDirector()))
27     movies.remove(i);
28     }
29
30     return (Movie []) movies.toArray(new Movie[movies.size()]);
31   }
32 }
33
Popular Tags