1
0
mirror of https://github.com/mitb-archive/filebot synced 2025-03-10 06:20:27 -04: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; return false;
} }
}
@Override
public AnidbSearchResult clone() {
return new AnidbSearchResult(aid, name, aliasNames);
}
}

View File

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

View File

@ -1,33 +1,26 @@
package net.sourceforge.filebot.web; package net.sourceforge.filebot.web;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
public class HyperLink extends SearchResult { public class HyperLink extends SearchResult {
protected URL url; protected URL url;
protected HyperLink() { protected HyperLink() {
// used by serializer // used by serializer
} }
public HyperLink(String name, URL url) { public HyperLink(String name, URL url) {
super(name); super(name);
this.url = url; this.url = url;
} }
public URL getURL() { public URL getURL() {
return url; return url;
} }
public URI getURI() { public URI getURI() {
try { try {
@ -36,7 +29,6 @@ public class HyperLink extends SearchResult {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@Override @Override
public boolean equals(Object object) { public boolean equals(Object object) {
@ -44,14 +36,18 @@ public class HyperLink extends SearchResult {
HyperLink other = (HyperLink) object; HyperLink other = (HyperLink) object;
return name.equals(name) && url.toString().equals(other.url.toString()); return name.equals(name) && url.toString().equals(other.url.toString());
} }
return false; return false;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Arrays.hashCode(new Object[] { name, url.toString() }); 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; package net.sourceforge.filebot.web;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class MultiEpisode extends Episode { public class MultiEpisode extends Episode {
private Episode[] episodes; private Episode[] episodes;
public MultiEpisode(Episode... episodes) { public MultiEpisode(Episode... episodes) {
super(episodes[0]); super(episodes[0]);
this.episodes = episodes; this.episodes = episodes;
} }
public List<Episode> getEpisodes() { public List<Episode> getEpisodes() {
return Arrays.asList(episodes); return unmodifiableList(asList(episodes));
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof MultiEpisode) { if (obj instanceof MultiEpisode) {
@ -30,23 +27,20 @@ public class MultiEpisode extends Episode {
} }
return false; return false;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Arrays.hashCode(episodes); return Arrays.hashCode(episodes);
} }
@Override @Override
public MultiEpisode clone() { public MultiEpisode clone() {
return new MultiEpisode(this.episodes); return new MultiEpisode(episodes.clone());
} }
@Override @Override
public String toString() { public String toString() {
return EpisodeFormat.SeasonEpisode.formatMultiEpisode(getEpisodes()); return EpisodeFormat.SeasonEpisode.formatMultiEpisode(getEpisodes());
} }
} }

View File

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

View File

@ -47,4 +47,10 @@ public class SerienjunkiesSearchResult extends SearchResult {
return false; 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; package net.sourceforge.filebot.web;
public class TVRageSearchResult extends SearchResult { public class TVRageSearchResult extends SearchResult {
protected int showId; protected int showId;
protected String link; protected String link;
protected TVRageSearchResult() { protected TVRageSearchResult() {
// used by serializer // used by serializer
} }
public TVRageSearchResult(String name, int showId, String link) { public TVRageSearchResult(String name, int showId, String link) {
super(name); super(name);
this.showId = showId; this.showId = showId;
this.link = link; this.link = link;
} }
public int getId() { public int getId() {
return showId; return showId;
} }
public int getSeriesId() { public int getSeriesId() {
return showId; return showId;
} }
public String getLink() { public String getLink() {
return link; return link;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return showId; return showId;
} }
@Override @Override
public boolean equals(Object object) { public boolean equals(Object object) {
if (object instanceof TVRageSearchResult) { if (object instanceof TVRageSearchResult) {
TVRageSearchResult other = (TVRageSearchResult) object; TVRageSearchResult other = (TVRageSearchResult) object;
return this.showId == other.showId; return this.showId == other.showId;
} }
return false; return false;
} }
}
@Override
public TVRageSearchResult clone() {
return new TVRageSearchResult(name, showId, link);
}
}

View File

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