From 82c8b31f9f061de1290231d8c809fa50a4ebdb11 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Wed, 15 Oct 2014 09:21:25 +0100 Subject: [PATCH] Remove some magic numbers --- .../java/com/omertron/themoviedbapi/TheMovieDbApi.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index d6ebfe41d..44408519a 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -139,6 +139,9 @@ public class TheMovieDbApi { private static ObjectMapper mapper = new ObjectMapper(); // Constants private static final String MOVIE_ID = "movie_id"; + private static final int YEAR_LENGTH = 4; + private static final int RATING_MAX = 10; + private static final int POST_SUCCESS_STATUS_CODE = 12; /** * API for The Movie Db. @@ -300,7 +303,7 @@ public class TheMovieDbApi { if (isValidYear(year) && isValidYear(moviedb.getReleaseDate())) { // Compare with year - String movieYear = moviedb.getReleaseDate().substring(0, 4); + String movieYear = moviedb.getReleaseDate().substring(0, YEAR_LENGTH); if (movieYear.equals(year)) { if (compareDistance(cmpOriginalTitle, cmpTitle, maxDistance)) { return Boolean.TRUE; @@ -1268,7 +1271,7 @@ public class TheMovieDbApi { apiUrl.addArgument(PARAM_SESSION, sessionId); - if (rating < 0 || rating > 10) { + if (rating < 0 || rating > RATING_MAX) { throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Rating out of range", apiUrl.buildUrl()); } @@ -1281,7 +1284,7 @@ public class TheMovieDbApi { StatusCode status = mapper.readValue(webpage, StatusCode.class); LOG.info("Status: {}", status); int code = status.getStatusCode(); - return code == 12; + return code == POST_SUCCESS_STATUS_CODE; } catch (IOException ex) { LOG.warn("Failed to post movie rating: {}", ex.getMessage(), ex); throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, url, ex);