diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index 71d25bdaf..05234d57a 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -22,14 +22,16 @@ package com.omertron.themoviedbapi.methods; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.tv.TVBasic; -import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import java.io.IOException; import java.net.URL; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.yamj.api.common.exception.ApiExceptionType; @@ -49,13 +51,20 @@ public class AbstractMethod { protected static final ObjectMapper MAPPER = new ObjectMapper(); // Logger protected static final Logger LOG = LoggerFactory.getLogger(TmdbAccount.class); - protected static final TypeReference> TR_MOVIE_BASIC = getTypeReference(MovieBasic.class); - protected static final TypeReference> TR_TV_BASIC = getTypeReference(TVBasic.class); - protected static final TypeReference> TR_USER_LIST = getTypeReference(UserList.class); - private static TypeReference getTypeReference(T Class) { - return new TypeReference>() { - }; + private static final Map TYPE_REFS = new HashMap(); + + static { + TYPE_REFS.put(MovieBasic.class, new TypeReference>() { + }); + TYPE_REFS.put(TVBasic.class, new TypeReference>() { + }); + TYPE_REFS.put(UserList.class, new TypeReference>() { + }); + } + + protected static TypeReference getTypeReference(Class aClass) { + return TYPE_REFS.get(aClass); } /** diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java index 1f6188dd6..19545d7dd 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java @@ -22,11 +22,11 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.enumeration.SortBy; -import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.StatusCode; +import com.omertron.themoviedbapi.model2.account.Account; +import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.tv.TVBasic; -import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; @@ -92,7 +92,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.ID, accountId); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.LISTS).buildUrl(parameters); - return processWrapperList(TR_USER_LIST, url, "user list"); + return processWrapperList(getTypeReference(UserList.class), url, "user list"); } /** @@ -109,7 +109,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.ID, accountId); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.FAVORITE_MOVIES).buildUrl(parameters); - return processWrapperList(TR_MOVIE_BASIC, url, "favorite movies"); + return processWrapperList(getTypeReference(MovieBasic.class), url, "favorite movies"); } /** @@ -126,7 +126,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.ID, accountId); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.FAVORITE_TV).buildUrl(parameters); - return processWrapperList(TR_TV_BASIC, url, "favorite TV shows"); + return processWrapperList(getTypeReference(TVBasic.class), url, "favorite TV shows"); } /** @@ -181,7 +181,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.RATED_MOVIES).buildUrl(parameters); - return processWrapperList(TR_MOVIE_BASIC, url, "rated movies"); + return processWrapperList(getTypeReference(MovieBasic.class), url, "rated movies"); } /** @@ -204,7 +204,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.RATED_TV).buildUrl(parameters); - return processWrapperList(TR_TV_BASIC, url, "rated TV shows"); + return processWrapperList(getTypeReference(TVBasic.class), url, "rated TV shows"); } /** @@ -227,7 +227,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.WATCHLIST_MOVIES).buildUrl(parameters); - return processWrapperList(TR_MOVIE_BASIC, url, "movie watch list"); + return processWrapperList(getTypeReference(MovieBasic.class), url, "movie watch list"); } /** @@ -250,7 +250,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.WATCHLIST_TV).buildUrl(parameters); - return processWrapperList(TR_TV_BASIC, url, "TV watch list"); + return processWrapperList(getTypeReference(TVBasic.class), url, "TV watch list"); } /** @@ -306,6 +306,6 @@ public class TmdbAccount extends AbstractMethod { } URL url = new ApiUrl(apiKey, MethodBase.GUEST_SESSION).setSubMethod(MethodSub.RATED_MOVIES_GUEST).buildUrl(parameters); - return processWrapperList(TR_MOVIE_BASIC, url, "Guest Session Movies"); + return processWrapperList(getTypeReference(MovieBasic.class), url, "Guest Session Movies"); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java index d03571ccd..bee2aa559 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java @@ -92,7 +92,7 @@ public class TmdbCompanies extends AbstractMethod { URL url = new ApiUrl(apiKey, MethodBase.COMPANY).setSubMethod(MethodSub.MOVIES).buildUrl(parameters); String webpage = httpTools.getRequest(url); - return processWrapperList(TR_MOVIE_BASIC, url, webpage); + return processWrapperList(getTypeReference(MovieBasic.class), url, webpage); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java index 44313a679..48d1e8209 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java @@ -57,7 +57,7 @@ public class TmdbDiscover extends AbstractMethod { public List getDiscoverMovies(Discover discover) throws MovieDbException { URL url = new ApiUrl(apiKey, MethodBase.DISCOVER).setSubMethod(MethodSub.MOVIE).buildUrl(discover.getParams()); String webpage = httpTools.getRequest(url); - return processWrapperList(TR_MOVIE_BASIC, url, webpage); + return processWrapperList(getTypeReference(MovieBasic.class), url, webpage); } /** @@ -70,6 +70,6 @@ public class TmdbDiscover extends AbstractMethod { public List getDiscoverTV(Discover discover) throws MovieDbException { URL url = new ApiUrl(apiKey, MethodBase.DISCOVER).setSubMethod(MethodSub.TV).buildUrl(discover.getParams()); String webpage = httpTools.getRequest(url); - return processWrapperList(TR_TV_BASIC, url, webpage); + return processWrapperList(getTypeReference(TVBasic.class), url, webpage); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java index 3937ec2cf..4c860b5df 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java @@ -122,6 +122,6 @@ public class TmdbGenres extends AbstractMethod { URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(MethodSub.MOVIES).buildUrl(parameters); String webpage = httpTools.getRequest(url); - return processWrapperList(TR_MOVIE_BASIC, url, webpage); + return processWrapperList(getTypeReference(MovieBasic.class), url, webpage); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index e8c24d0dd..6ad84b4a8 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -19,14 +19,13 @@ */ package com.omertron.themoviedbapi.methods; -import com.fasterxml.jackson.core.type.TypeReference; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.SearchType; -import com.omertron.themoviedbapi.model2.collection.Collection; -import com.omertron.themoviedbapi.model2.company.Company; -import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.person.Person; +import com.omertron.themoviedbapi.model2.collection.Collection; +import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.results.TmdbResultsList; @@ -265,8 +264,4 @@ public class TmdbSearch extends AbstractMethod { return results; } - private static TypeReference getTypeReference(T Class) { - return new TypeReference>() { - }; - } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java index 1da8fadc3..16e8bc85e 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java @@ -23,12 +23,12 @@ import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.enumeration.SortBy; -import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.StatusCode; +import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.authentication.TokenSession; +import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.tv.TVBasic; -import com.omertron.themoviedbapi.model2.list.UserList; import java.util.List; import org.junit.After; import org.junit.AfterClass; @@ -39,6 +39,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; /** @@ -78,7 +79,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetAccount() throws MovieDbException { LOG.info("getAccount"); Account result = instance.getAccount(getSessionId()); @@ -92,7 +93,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetUserLists() throws MovieDbException { LOG.info("getUserLists"); List results = instance.getUserLists(getSessionId(), getAccountId()); @@ -108,7 +109,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetFavoriteMovies() throws MovieDbException { LOG.info("getFavoriteMovies"); List results = instance.getFavoriteMovies(getSessionId(), getAccountId()); @@ -124,7 +125,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetFavoriteTv() throws MovieDbException { LOG.info("getFavoriteTv"); List results = instance.getFavoriteTv(getSessionId(), getAccountId()); @@ -140,7 +141,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testModifyFavoriteStatus() throws MovieDbException { LOG.info("modifyFavoriteStatus"); @@ -170,7 +171,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetRatedMovies() throws MovieDbException { LOG.info("getRatedMovies"); List results = instance.getRatedMovies(getSessionId(), getAccountId(), null, null, null); @@ -183,7 +184,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetRatedTV() throws MovieDbException { LOG.info("getRatedTV"); List results = instance.getRatedTV(getSessionId(), getAccountId(), null, null, null); @@ -199,7 +200,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetWatchListMovie() throws MovieDbException { LOG.info("getWatchListMovie"); List results = instance.getWatchListMovie(getSessionId(), getAccountId(), null, null, null); @@ -231,7 +232,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testModifyWatchList() throws MovieDbException { LOG.info("modifyWatchList"); @@ -261,7 +262,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetGuestRatedMovies() throws MovieDbException { LOG.info("getGuestRatedMovies");