1. /**
  2.   * getMoviesByType, returns a filtered list of a wanted Type
  3.   * @param <T>
  4.   * @param movieList
  5.   * @param wantedType
  6.   * @return A list of ONLY the type wanted
  7.   */
  8. public <T> MovieList<T> filterMovieList (MovieList<Movie> movieList, T wantedType)
  9. {
  10. MovieList<Movie> newMovieList = new MovieList<Movie>();
  11.  
  12. for (Movie movie : movieList)
  13. {
  14. if (movie.getClass() == wantedType.getClass())//Same class instances
  15. {
  16. newMovieList.add(movie);
  17. }
  18. }
  19. return (MovieList<T>) newMovieList; //Cast to right Type
  20. }