mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 00:38:52 -05:00
Refactor SearchResult classes
This commit is contained in:
parent
e2a3149d19
commit
7a4f0eb9e2
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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];
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -410,12 +410,12 @@ public class TheTVDBClient extends AbstractEpisodeListProvider {
|
||||
|
||||
public List<BannerDescriptor> 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<Node> nodes = selectNodes("//Banner", dom);
|
||||
List<BannerDescriptor> banners = new ArrayList<BannerDescriptor>();
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user