Figure 1. This class is the helper for our examples. It is a simple read-only Java DB for our favourite Movies. Feel free to add your personal favourites!package pods.podloaders;
import java.util.Collection;
import java.util.TreeMap;
/** Simple read-only Java DB for a movie collection */
public class MoviesDB {
private TreeMap<Integer, Movie> allMovies;
/** Constructor */
public MoviesDB() {
allMovies = new TreeMap<Integer, Movie>();
allMovies.put(1, new MoviesDB.Movie(1,"The Dark Knight", "action",
2008, "Christopher Nolan", "Christian Bale", 1));
allMovies.put(2, new MoviesDB.Movie(2,"Casablanca", "romance",
1942, "Michael Curtiz", "Humphrey Bogart", 3));
allMovies.put(3, new MoviesDB.Movie(3,"Schindler's List", "drama",
1993, "Steven Spielberg", "Liam Neeson", 7));
allMovies.put(4, new MoviesDB.Movie(4,"Alien", "horror",
1979, "Ridley Scott", "Sigourney Weaver", 1));
allMovies.put(5, new MoviesDB.Movie(1, "The GodFather, Part II",
"drama", 1974, "Francis Ford Coppola", "Marlon Brando", 6));
allMovies.put(5, new MoviesDB.Movie(1, "Toy Story 3",
"comedy", 2010, "Lee Unkrich", "Tom Hanks", 2));
allMovies.put(6, new MoviesDB.Movie(6, "Toy Story 2",
"comedy", 1999, "John Lasseter", "Tom Hanks", 0));
}
/** Return all movies as a Collection */
public Collection<MoviesDB.Movie> getAllMovies(){
Collection<MoviesDB.Movie> movieCollection =
this.allMovies.values();
return movieCollection;
}
/** Return a movie by its Id */
public Movie getMovieById(Integer id) {
return allMovies.get(id);
}
class Movie {
public int id,year,oscars;
public String title, genre, director, leadrole, url;
public Movie(int id,String title,String genre,
int year,String director,String leadrole, int oscars){
this.id = id;
this.title = title;
this.genre = genre;
this.year = year;
this.director = director;
this.leadrole = leadrole;
this.oscars = oscars;
}
}
}