From 1f1054995db77dfcd102d9230289be13bf5cec5e Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Wed, 4 Mar 2015 09:13:55 +0000 Subject: [PATCH] Sonar fixes 2 --- .../themoviedbapi/methods/AbstractMethod.java | 11 ++--- .../model2/media/MediaState.java | 22 +++------- .../model2/media/RatedValue.java | 41 +++++++++++++++++++ 3 files changed, 49 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/media/RatedValue.java diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index 138e9602f..d187f58ca 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -22,12 +22,12 @@ 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.movie.MovieDb; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.movie.MovieDb; import com.omertron.themoviedbapi.model2.person.Person; import com.omertron.themoviedbapi.model2.person.PersonFind; import com.omertron.themoviedbapi.model2.review.Review; @@ -39,8 +39,6 @@ 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; /** @@ -56,9 +54,6 @@ public class AbstractMethod { protected final HttpTools httpTools; // Jackson JSON configuration protected static final ObjectMapper MAPPER = new ObjectMapper(); - // Logger - protected static final Logger LOG = LoggerFactory.getLogger(AbstractMethod.class); - private static final Map TYPE_REFS = new HashMap(); static { @@ -120,7 +115,7 @@ public class AbstractMethod { * @return * @throws MovieDbException */ - public List processWrapperList(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException { + protected List processWrapperList(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException { WrapperGenericList val = processWrapper(typeRef, url, errorMessageSuffix); return val.getResults(); } @@ -135,7 +130,7 @@ public class AbstractMethod { * @return * @throws MovieDbException */ - public WrapperGenericList processWrapper(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException { + protected WrapperGenericList processWrapper(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException { String webpage = httpTools.getRequest(url); try { // Due to type erasure, this doesn't work diff --git a/src/main/java/com/omertron/themoviedbapi/model2/media/MediaState.java b/src/main/java/com/omertron/themoviedbapi/model2/media/MediaState.java index aee208f64..dd86208fa 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/media/MediaState.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/media/MediaState.java @@ -20,6 +20,7 @@ package com.omertron.themoviedbapi.model2.media; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; /** @@ -34,8 +35,7 @@ public class MediaState extends AbstractJsonMapping { private boolean favorite; @JsonProperty("watchlist") private boolean watchlist; - @JsonProperty("rated") - private RatedValue rated; + private float rated; public int getId() { return id; @@ -62,24 +62,12 @@ public class MediaState extends AbstractJsonMapping { } public float getRated() { - return rated.getValue(); + return rated; } + @JsonSetter("rated") public void setRated(RatedValue rated) { - this.rated = rated; + this.rated = rated.getValue(); } - public class RatedValue extends AbstractJsonMapping { - - @JsonProperty("value") - private float value = -1f; - - public float getValue() { - return value; - } - - public void setValue(float value) { - this.value = value; - } - } } diff --git a/src/main/java/com/omertron/themoviedbapi/model2/media/RatedValue.java b/src/main/java/com/omertron/themoviedbapi/model2/media/RatedValue.java new file mode 100644 index 000000000..2ec203c29 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/media/RatedValue.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2004-2015 Stuart Boston + * + * This file is part of TheMovieDB API. + * + * TheMovieDB API is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * TheMovieDB API is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with TheMovieDB API. If not, see . + * + */ +package com.omertron.themoviedbapi.model2.media; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; + +/** + * + * @author Stuart.Boston + */ +public class RatedValue extends AbstractJsonMapping { + + @JsonProperty("value") + private float value = -1f; + + public float getValue() { + return value; + } + + public void setValue(float value) { + this.value = value; + } +}