This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Provides common functionality to all Rotten Tomato clients | |
| */ | |
| public abstract class AbstractTomatoService { | |
| protected static final String ROTTENTOMATOES_API = "http://api.rottentomatoes.com/api/public/v1.0/"; | |
| protected final Logger logger = LoggerFactory.getLogger(this.getClass()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "id": 770672122, | |
| "title": "Toy Story 3", | |
| "year": 2010, | |
| "genres": ["Animation", "Kids & Family", "Science Fiction & Fantasy", "Comedy"], | |
| "mpaa_rating": "G", | |
| "runtime": 103, | |
| "critics_consensus": "", | |
| "release_dates": { | |
| "theater": "2010-06-18", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Movie { | |
| @Key | |
| private int id; | |
| @Key | |
| private String title; | |
| @Key | |
| private List<String> genres; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface MovieService { | |
| List<Movie> getBoxOfficeMovies(Locale country, int limit) | |
| throws IOException; | |
| List<Movie> getOpeningMovies(Locale country, int limit) throws IOException; | |
| List<Movie> getInThreatersMovies(Locale country, int limit, int page) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class HttpMovieService extends AbstractTomatoService implements | |
| MovieService { | |
| @Override | |
| public List<Movie> getBoxOfficeMovies(Locale country, int limit) | |
| throws IOException { | |
| String url = ROTTENTOMATOES_API + BOX_OFFICE_MOVIES; | |
| GenericUrl request = getMovieRequest(country, limit, url); | |
| HttpResponse response = executeRequest(request); | |
| MovieFeed feed = response.parseAs(MovieFeed.class); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MovieFeed { | |
| @Key("movies") | |
| public ArrayList<Movie> movies; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Abstraction to provide a Rotten Tomatoes API key at runtime | |
| * | |
| */ | |
| public interface KeyProvider { | |
| String getApiKey(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MovieServiceTest { | |
| private MovieService movieService = null; | |
| @Before | |
| public void setUp() throws IOException { | |
| if (movieService == null) { | |
| KeyProvider keyProvider = new FilesystemKeyProvider( | |
| "/Users/dimitri/dev/tomatos.properties", "key"); | |
| movieService = new HttpMovieService(keyProvider); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class EquivalenceClass { | |
| String title; | |
| long size; | |
| public EquivalenceClass(String title, long size) { | |
| this.title = title; | |
| this.size = size; | |
| } | |
| @Override | |
| public boolean equals(Object o) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class DuplicateFinder { | |
| public Map<EquivalenceClass, List<Song>> findDuplicates(List<Song> songs) { | |
| Map<EquivalenceClass, List<Song>> equivalenceClasses = new HashMap<>(); | |
| for (Song song : songs) { | |
| EquivalenceClass equivalenceClass = new EquivalenceClass(song.getTitle(), song.getMediaInfo().getSize()); | |
| List<Song> songsInClass = equivalenceClasses.get(equivalenceClass); | |
| if (songsInClass == null) { | |
| songsInClass = new ArrayList<>(); | |
| equivalenceClasses.put(equivalenceClass, songsInClass); |
OlderNewer