diff --git a/source/net/filebot/web/AnidbSearchResult.java b/source/net/filebot/web/AnidbSearchResult.java index 5721d605..3ebab742 100644 --- a/source/net/filebot/web/AnidbSearchResult.java +++ b/source/net/filebot/web/AnidbSearchResult.java @@ -2,52 +2,25 @@ package net.filebot.web; public class AnidbSearchResult extends SearchResult { - protected int aid; - protected AnidbSearchResult() { // used by serializer } public AnidbSearchResult(int aid, String primaryTitle, String[] aliasNames) { - super(primaryTitle, aliasNames); - this.aid = aid; - } - - public int getId() { - return aid; + super(aid, primaryTitle, aliasNames); } public int getAnimeId() { - return aid; - } - - @Override - public String getName() { - return name; + return id; } public String getPrimaryTitle() { return name; } - @Override - public int hashCode() { - return aid; - } - - @Override - public boolean equals(Object object) { - if (object instanceof AnidbSearchResult) { - AnidbSearchResult other = (AnidbSearchResult) object; - return this.aid == other.aid; - } - - return false; - } - @Override public AnidbSearchResult clone() { - return new AnidbSearchResult(aid, name, aliasNames); + return new AnidbSearchResult(id, name, aliasNames); } } diff --git a/source/net/filebot/web/HyperLink.java b/source/net/filebot/web/HyperLink.java deleted file mode 100644 index 49721844..00000000 --- a/source/net/filebot/web/HyperLink.java +++ /dev/null @@ -1,53 +0,0 @@ -package net.filebot.web; - -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.Arrays; - -public class HyperLink extends SearchResult { - - protected URL url; - - protected HyperLink() { - // used by serializer - } - - public HyperLink(String name, URL url) { - super(name, new String[0]); - this.url = url; - } - - public URL getURL() { - return url; - } - - public URI getURI() { - try { - return url.toURI(); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } - } - - @Override - public boolean equals(Object object) { - if (object instanceof HyperLink) { - HyperLink other = (HyperLink) object; - return name.equals(name) && url.toString().equals(other.url.toString()); - } - - return false; - } - - @Override - public int hashCode() { - return Arrays.hashCode(new Object[] { name, url.toString() }); - } - - @Override - public HyperLink clone() { - return new HyperLink(name, url); - } - -} diff --git a/source/net/filebot/web/Movie.java b/source/net/filebot/web/Movie.java index 6d67bca4..d3502312 100644 --- a/source/net/filebot/web/Movie.java +++ b/source/net/filebot/web/Movie.java @@ -20,16 +20,12 @@ public class Movie extends SearchResult { // used by serializer } - public Movie(Movie obj) { - this(obj.name, obj.aliasNames, obj.year, obj.imdbId, obj.tmdbId, obj.getLanguage()); - } - public Movie(String name, int year, int imdbId, int tmdbId) { - this(name, new String[0], year, imdbId, tmdbId, null); + this(name, null, year, imdbId, tmdbId, null); } public Movie(String name, String[] aliasNames, int year, int imdbId, int tmdbId, Locale locale) { - super(name, aliasNames); + super(tmdbId > 0 ? tmdbId : imdbId > 0 ? imdbId : -1, name, aliasNames); this.year = year; this.imdbId = imdbId; this.tmdbId = tmdbId; @@ -99,12 +95,7 @@ public class Movie extends SearchResult { @Override public Movie clone() { - return new Movie(this); - } - - @Override - public int hashCode() { - return tmdbId > 0 ? tmdbId : imdbId > 0 ? imdbId : year; + return new Movie(name, aliasNames, year, imdbId, tmdbId, getLanguage()); } @Override diff --git a/source/net/filebot/web/MoviePart.java b/source/net/filebot/web/MoviePart.java index 10a9cc71..d9b14204 100644 --- a/source/net/filebot/web/MoviePart.java +++ b/source/net/filebot/web/MoviePart.java @@ -14,7 +14,7 @@ public class MoviePart extends Movie { } public MoviePart(Movie movie, int partIndex, int partCount) { - super(movie); + super(movie.getName(), movie.getAliasNames(), movie.getYear(), movie.getImdbId(), movie.getTmdbId(), movie.getLanguage()); this.partIndex = partIndex; this.partCount = partCount; } @@ -44,7 +44,7 @@ public class MoviePart extends Movie { @Override public String toString() { - return String.format("%s (%d) [%d]", name, year, partIndex); + return String.format("%s (%d) [CD%d]", name, year, partIndex); } } diff --git a/source/net/filebot/web/SearchResult.java b/source/net/filebot/web/SearchResult.java index 8d09bee2..625853f8 100644 --- a/source/net/filebot/web/SearchResult.java +++ b/source/net/filebot/web/SearchResult.java @@ -8,6 +8,7 @@ import java.util.List; public abstract class SearchResult implements Serializable { + protected int id; protected String name; protected String[] aliasNames; @@ -15,11 +16,22 @@ public abstract class SearchResult implements Serializable { // used by serializer } - public SearchResult(String name, String[] aliasNames) { + public SearchResult(int id, String name) { + this.id = id; + this.name = name; + this.aliasNames = EMPTY_STRING_ARRAY; + } + + public SearchResult(int id, String name, String[] aliasNames) { + this.id = id; this.name = name; this.aliasNames = (aliasNames == null || aliasNames.length == 0) ? EMPTY_STRING_ARRAY : aliasNames.clone(); } + public int getId() { + return id; + } + public String getName() { return name; } @@ -50,13 +62,26 @@ public abstract class SearchResult implements Serializable { } @Override - public abstract SearchResult clone(); + public int hashCode() { + return id; + } + + @Override + public boolean equals(Object other) { + if (getClass().isInstance(other)) { + return getId() == ((SearchResult) other).getId(); + } + return false; + } @Override public String toString() { return name; } - private static final String[] EMPTY_STRING_ARRAY = new String[0]; + @Override + public abstract SearchResult clone(); + + protected static final String[] EMPTY_STRING_ARRAY = new String[0]; } diff --git a/source/net/filebot/web/TVMazeSearchResult.java b/source/net/filebot/web/TVMazeSearchResult.java index 903642d8..e97f2633 100644 --- a/source/net/filebot/web/TVMazeSearchResult.java +++ b/source/net/filebot/web/TVMazeSearchResult.java @@ -2,34 +2,12 @@ package net.filebot.web; public class TVMazeSearchResult extends SearchResult { - protected int id; - protected TVMazeSearchResult() { // used by serializer } public TVMazeSearchResult(int id, String name) { - super(name, new String[0]); - this.id = id; - } - - public int getId() { - return id; - } - - @Override - public int hashCode() { - return id; - } - - @Override - public boolean equals(Object object) { - if (object instanceof TVMazeSearchResult) { - TVMazeSearchResult other = (TVMazeSearchResult) object; - return this.id == other.id; - } - - return false; + super(id, name); } @Override diff --git a/source/net/filebot/web/TheTVDBClient.java b/source/net/filebot/web/TheTVDBClient.java index 2fd9c076..c3d9b969 100644 --- a/source/net/filebot/web/TheTVDBClient.java +++ b/source/net/filebot/web/TheTVDBClient.java @@ -410,12 +410,12 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { public List getBannerList(TheTVDBSearchResult series) throws Exception { // check cache first - BannerDescriptor[] cachedList = getCache().getData("banners", series.seriesId, null, BannerDescriptor[].class); + BannerDescriptor[] cachedList = getCache().getData("banners", series.getId(), null, BannerDescriptor[].class); if (cachedList != null) { return asList(cachedList); } - Document dom = getXmlResource(MirrorType.XML, "/api/" + apikey + "/series/" + series.seriesId + "/banners.xml"); + Document dom = getXmlResource(MirrorType.XML, "/api/" + apikey + "/series/" + series.getId() + "/banners.xml"); List nodes = selectNodes("//Banner", dom); List banners = new ArrayList(); @@ -442,7 +442,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { } } - getCache().putData("banners", series.seriesId, null, banners.toArray(new BannerDescriptor[0])); + getCache().putData("banners", series.getId(), null, banners.toArray(new BannerDescriptor[0])); return banners; } diff --git a/source/net/filebot/web/TheTVDBSearchResult.java b/source/net/filebot/web/TheTVDBSearchResult.java index 131f54f8..d661ec2f 100644 --- a/source/net/filebot/web/TheTVDBSearchResult.java +++ b/source/net/filebot/web/TheTVDBSearchResult.java @@ -2,47 +2,25 @@ package net.filebot.web; public class TheTVDBSearchResult extends SearchResult { - protected int seriesId; - protected TheTVDBSearchResult() { // used by serializer } public TheTVDBSearchResult(String seriesName, int seriesId) { - this(seriesName, new String[0], seriesId); + super(seriesId, seriesName); } public TheTVDBSearchResult(String seriesName, String[] aliasNames, int seriesId) { - super(seriesName, aliasNames); - this.seriesId = seriesId; - } - - public int getId() { - return seriesId; + super(seriesId, seriesName, aliasNames); } public int getSeriesId() { - return seriesId; - } - - @Override - public int hashCode() { - return seriesId; - } - - @Override - public boolean equals(Object object) { - if (object instanceof TheTVDBSearchResult) { - TheTVDBSearchResult other = (TheTVDBSearchResult) object; - return this.seriesId == other.seriesId; - } - - return false; + return id; } @Override public TheTVDBSearchResult clone() { - return new TheTVDBSearchResult(name, aliasNames, seriesId); + return new TheTVDBSearchResult(name, aliasNames, id); } -} \ No newline at end of file +}