1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-04 16:35:08 -05:00

* make sure the Episode/Movie object graphs don't share any objects so json-io won't write json with @ref attributes

This commit is contained in:
Reinhard Pointner 2014-03-20 17:36:56 +00:00
parent d2b2b453b5
commit 1ae64235f1
9 changed files with 84 additions and 87 deletions

View File

@ -44,4 +44,10 @@ public class AnidbSearchResult extends SearchResult {
return false;
}
}
@Override
public AnidbSearchResult clone() {
return new AnidbSearchResult(aid, name, aliasNames);
}
}

View File

@ -1,7 +1,5 @@
package net.sourceforge.filebot.web;
import static java.util.Calendar.*;
import java.io.Serializable;
@ -12,86 +10,78 @@ import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
public class Date implements Serializable {
private int year;
private int month;
private int day;
protected Date() {
// used by serializer
}
public Date(int year, int month, int day) {
this.year = year;
this.month = month;
this.day = day;
}
public int getYear() {
return year;
}
public int getMonth() {
return month;
}
public int getDay() {
return day;
}
public long getTimeStamp() {
return new GregorianCalendar(year, month - 1, day).getTimeInMillis(); // Month value is 0-based, e.g. 0 for January
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Date) {
Date other = (Date) obj;
return year == other.year && month == other.month && day == other.day;
}
return super.equals(obj);
}
@Override
public int hashCode() {
return Arrays.hashCode(new Object[] { year, month, day });
}
@Override
public Date clone() {
return new Date(year, month, day);
}
@Override
public String toString() {
return String.format("%04d-%02d-%02d", year, month, day);
}
public String format(String pattern) {
return format(pattern, Locale.ROOT);
}
public String format(String pattern, Locale locale) {
return new SimpleDateFormat(pattern, locale).format(new GregorianCalendar(year, month - 1, day).getTime()); // Calendar months start at 0
}
public static Date parse(String string, String pattern) {
if (string == null || string.isEmpty())
return null;
SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.ROOT);
formatter.setLenient(false); // enable strict mode (e.g. fail on invalid dates like 0000-00-00)
try {
Calendar date = new GregorianCalendar(Locale.ROOT);
date.setTime(formatter.parse(string));
@ -102,5 +92,5 @@ public class Date implements Serializable {
return null;
}
}
}

View File

@ -39,14 +39,14 @@ public class Episode implements Serializable {
public Episode(String seriesName, Date seriesStartDate, Integer season, Integer episode, String title, Integer absolute, Integer special, Date airdate, SearchResult series) {
this.seriesName = seriesName;
this.seriesStartDate = seriesStartDate;
this.seriesStartDate = (seriesStartDate == null ? null : seriesStartDate.clone());
this.season = season;
this.episode = episode;
this.title = title;
this.absolute = absolute;
this.special = special;
this.airdate = airdate;
this.series = series;
this.airdate = (airdate == null ? null : airdate.clone());
this.series = (series == null ? null : series.clone());
}
public String getSeriesName() {

View File

@ -1,33 +1,26 @@
package net.sourceforge.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);
this.url = url;
}
public URL getURL() {
return url;
}
public URI getURI() {
try {
@ -36,7 +29,6 @@ public class HyperLink extends SearchResult {
throw new RuntimeException(e);
}
}
@Override
public boolean equals(Object object) {
@ -44,14 +36,18 @@ public class HyperLink extends SearchResult {
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);
}
}

View File

@ -1,27 +1,24 @@
package net.sourceforge.filebot.web;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.util.Arrays;
import java.util.List;
public class MultiEpisode extends Episode {
private Episode[] episodes;
public MultiEpisode(Episode... episodes) {
super(episodes[0]);
this.episodes = episodes;
}
public List<Episode> getEpisodes() {
return Arrays.asList(episodes);
return unmodifiableList(asList(episodes));
}
@Override
public boolean equals(Object obj) {
if (obj instanceof MultiEpisode) {
@ -30,23 +27,20 @@ public class MultiEpisode extends Episode {
}
return false;
}
@Override
public int hashCode() {
return Arrays.hashCode(episodes);
}
@Override
public MultiEpisode clone() {
return new MultiEpisode(this.episodes);
return new MultiEpisode(episodes.clone());
}
@Override
public String toString() {
return EpisodeFormat.SeasonEpisode.formatMultiEpisode(getEpisodes());
}
}

View File

@ -46,6 +46,9 @@ public abstract class SearchResult implements Serializable {
};
}
@Override
public abstract SearchResult clone();
@Override
public String toString() {
return name;

View File

@ -47,4 +47,10 @@ public class SerienjunkiesSearchResult extends SearchResult {
return false;
}
}
@Override
public SerienjunkiesSearchResult clone() {
return new SerienjunkiesSearchResult(sid, link, name, aliasNames, startDate == null ? null : startDate.clone());
}
}

View File

@ -1,53 +1,50 @@
package net.sourceforge.filebot.web;
public class TVRageSearchResult extends SearchResult {
protected int showId;
protected String link;
protected TVRageSearchResult() {
// used by serializer
}
public TVRageSearchResult(String name, int showId, String link) {
super(name);
this.showId = showId;
this.link = link;
}
public int getId() {
return showId;
}
public int getSeriesId() {
return showId;
}
public String getLink() {
return link;
}
@Override
public int hashCode() {
return showId;
}
@Override
public boolean equals(Object object) {
if (object instanceof TVRageSearchResult) {
TVRageSearchResult other = (TVRageSearchResult) object;
return this.showId == other.showId;
}
return false;
}
}
@Override
public TVRageSearchResult clone() {
return new TVRageSearchResult(name, showId, link);
}
}

View File

@ -1,6 +1,5 @@
package net.sourceforge.filebot.web;
public class TheTVDBSearchResult extends SearchResult {
protected int seriesId;
@ -40,4 +39,10 @@ public class TheTVDBSearchResult extends SearchResult {
return false;
}
@Override
public TheTVDBSearchResult clone() {
return new TheTVDBSearchResult(name, seriesId);
}
}