Rich Newman

MovieLister Class – Java

package moviefindertest.springxml;

import java.util.Iterator;
import java.util.List;

public class MovieLister {
      
      private static int lastVersionID = 0;
      private final int versionID;
      
      public int getVersionID() {
            return versionID;
      }

      private MovieFinder finder;
      
    public MovieLister(MovieFinder finder) {
      this();
            this.finder = finder;
      }
    
    public MovieLister() {
            this.versionID = ++MovieLister.lastVersionID;
      }

      public MovieFinder getFinder() {
            return finder;
      }

      public void setFinder(MovieFinder finder) {
            this.finder = finder;
      }

      public Movie[] moviesDirectedBy(String arg) {
        List<Movie> allMovies = finder.findAll();
        for (Iterator<Movie> it = allMovies.iterator(); it.hasNext();) {
            Movie movie = (Movie) it.next();
            if (!movie.getDirector().equals(arg)) it.remove();
        }
        return (Movie[]) allMovies.toArray(new Movie[allMovies.size()]);
    }
}
 

Leave a Comment »

No comments yet.

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: