From dd9e0bdc22f39d3b4ddd120482eab4ab873f6ed3 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 16 Feb 2012 07:19:12 +0000 Subject: [PATCH] * make sure every matched object is a unique object (as required by Matcher) --- .../filebot/ui/rename/EpisodeListMatcher.java | 4 +- .../filebot/ui/rename/MatchAction.java | 28 +++++++------- .../filebot/ui/rename/MovieHashMatcher.java | 4 +- .../net/sourceforge/filebot/web/Episode.java | 35 ++++++++++-------- source/net/sourceforge/filebot/web/Movie.java | 25 +++++++++---- .../sourceforge/filebot/web/MoviePart.java | 37 ++++++++++++++++--- 6 files changed, 88 insertions(+), 45 deletions(-) diff --git a/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java b/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java index 74723fe8..2162a4aa 100644 --- a/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java +++ b/source/net/sourceforge/filebot/ui/rename/EpisodeListMatcher.java @@ -218,8 +218,8 @@ class EpisodeListMatcher implements AutoCompleteMatcher { for (File file : derivateFiles) { for (Match match : matches) { - if (file.getParentFile().equals(match.getValue().getParentFile()) && isDerived(file, match.getValue())) { - derivateMatches.add(new Match(file, match.getCandidate())); + if (file.getParentFile().equals(match.getValue().getParentFile()) && isDerived(file, match.getValue()) && match.getCandidate() instanceof Episode) { + derivateMatches.add(new Match(file, new Episode((Episode) match.getCandidate()))); break; } } diff --git a/source/net/sourceforge/filebot/ui/rename/MatchAction.java b/source/net/sourceforge/filebot/ui/rename/MatchAction.java index e59ef354..8ac8d4c2 100644 --- a/source/net/sourceforge/filebot/ui/rename/MatchAction.java +++ b/source/net/sourceforge/filebot/ui/rename/MatchAction.java @@ -25,15 +25,15 @@ import net.sourceforge.filebot.similarity.Match; import net.sourceforge.filebot.similarity.Matcher; import net.sourceforge.filebot.similarity.SimilarityMetric; import net.sourceforge.tuned.ui.ProgressDialog; -import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter; import net.sourceforge.tuned.ui.ProgressDialog.Cancellable; +import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter; class MatchAction extends AbstractAction { private final RenameModel model; - + public MatchAction(RenameModel model) { this.model = model; @@ -42,17 +42,17 @@ class MatchAction extends AbstractAction { putValue(SHORT_DESCRIPTION, "Match files and names"); } - + public void actionPerformed(ActionEvent evt) { if (model.names().isEmpty() || model.files().isEmpty()) return; - Window window = getWindow(evt.getSource()); - window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - BackgroundMatcher backgroundMatcher = new BackgroundMatcher(model, EpisodeMetrics.defaultSequence(true)); backgroundMatcher.execute(); + Window window = getWindow(evt.getSource()); + window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + try { // wait a for little while (matcher might finish in less than a second) backgroundMatcher.get(2, TimeUnit.SECONDS); @@ -65,12 +65,12 @@ class MatchAction extends AbstractAction { dialog.setVisible(true); } catch (Exception e) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e); + } finally { + window.setCursor(Cursor.getDefaultCursor()); } - - window.setCursor(Cursor.getDefaultCursor()); } - + protected ProgressDialog createProgressDialog(Window parent, final BackgroundMatcher worker) { final ProgressDialog progressDialog = new ProgressDialog(parent, worker); @@ -91,24 +91,24 @@ class MatchAction extends AbstractAction { return progressDialog; } - + protected class BackgroundMatcher extends SwingWorker>, Void> implements Cancellable { private final Matcher matcher; - + public BackgroundMatcher(MatchModel model, SimilarityMetric[] metrics) { // match names against files this.matcher = new Matcher(model.values(), model.candidates(), false, metrics); } - + @Override protected List> doInBackground() throws Exception { return matcher.match(); } - + @Override protected void done() { if (isCancelled()) @@ -129,7 +129,7 @@ class MatchAction extends AbstractAction { } } - + @Override public boolean cancel() { return cancel(true); diff --git a/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java b/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java index bebfdbdd..c7b2b45d 100644 --- a/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java +++ b/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java @@ -180,13 +180,13 @@ class MovieHashMatcher implements AutoCompleteMatcher { moviePart = new MoviePart(moviePart, i + 1, fileSet.size()); } - matches.add(new Match(fileSet.get(i), moviePart)); + matches.add(new Match(fileSet.get(i), moviePart.clone())); // automatically add matches for derivate files List derivates = derivatesByMovieFile.get(fileSet.get(i)); if (derivates != null) { for (File derivate : derivates) { - matches.add(new Match(derivate, moviePart)); + matches.add(new Match(derivate, moviePart.clone())); } } } diff --git a/source/net/sourceforge/filebot/web/Episode.java b/source/net/sourceforge/filebot/web/Episode.java index 573c549f..2c29647b 100644 --- a/source/net/sourceforge/filebot/web/Episode.java +++ b/source/net/sourceforge/filebot/web/Episode.java @@ -24,17 +24,22 @@ public class Episode implements Serializable { // episode airdate private Date airdate; - + protected Episode() { // used by serializer } - + + public Episode(Episode obj) { + this(obj.seriesName, obj.seriesStartDate, obj.season, obj.episode, obj.title, obj.absolute, obj.special, obj.airdate); + } + + public Episode(String seriesName, Date seriesStartDate, Integer season, Integer episode, String title) { this(seriesName, seriesStartDate, season, episode, title, null, null, null); } - + public Episode(String seriesName, Date seriesStartDate, Integer season, Integer episode, String title, Integer absolute, Integer special, Date airdate) { this.seriesName = seriesName; this.seriesStartDate = seriesStartDate; @@ -46,47 +51,47 @@ public class Episode implements Serializable { this.airdate = airdate; } - + public String getSeriesName() { return seriesName; } - + public Date getSeriesStartDate() { return seriesStartDate; } - + public Integer getEpisode() { return episode; } - + public Integer getSeason() { return season; } - + public String getTitle() { return title; } - + public Integer getAbsolute() { return absolute; } - + public Integer getSpecial() { return special; } - + public Date airdate() { return airdate; } - + @Override public boolean equals(Object obj) { if (obj instanceof Episode) { @@ -97,7 +102,7 @@ public class Episode implements Serializable { return false; } - + private boolean equals(Object o1, Object o2) { if (o1 == null || o2 == null) return o1 == o2; @@ -105,13 +110,13 @@ public class Episode implements Serializable { return o1.equals(o2); } - + @Override public int hashCode() { return Arrays.hashCode(new Object[] { seriesName, season, episode, title, special }); } - + @Override public String toString() { return EpisodeFormat.SeasonEpisode.format(this); diff --git a/source/net/sourceforge/filebot/web/Movie.java b/source/net/sourceforge/filebot/web/Movie.java index fd726334..4a5afab6 100644 --- a/source/net/sourceforge/filebot/web/Movie.java +++ b/source/net/sourceforge/filebot/web/Movie.java @@ -10,29 +10,34 @@ public class Movie extends SearchResult { protected int year; protected int imdbId; - + protected Movie() { // used by serializer } - + + public Movie(Movie obj) { + this(obj.name, obj.year, obj.imdbId); + } + + public Movie(String name, int year, int imdbId) { super(name); this.year = year; this.imdbId = imdbId; } - + public int getYear() { return year; } - + public int getImdbId() { return imdbId; } - + @Override public boolean equals(Object object) { if (object instanceof Movie) { @@ -43,13 +48,19 @@ public class Movie extends SearchResult { return false; } - + + @Override + public Movie clone() { + return new Movie(this); + } + + @Override public int hashCode() { return Arrays.hashCode(new Object[] { name, year, imdbId }); } - + @Override public String toString() { return String.format("%s (%d)", name, year); diff --git a/source/net/sourceforge/filebot/web/MoviePart.java b/source/net/sourceforge/filebot/web/MoviePart.java index 0906799f..b0019e11 100644 --- a/source/net/sourceforge/filebot/web/MoviePart.java +++ b/source/net/sourceforge/filebot/web/MoviePart.java @@ -7,24 +7,51 @@ public class MoviePart extends Movie { protected final int partIndex; protected final int partCount; - + + public MoviePart(MoviePart obj) { + this(obj.name, obj.year, obj.imdbId, obj.partIndex, obj.partCount); + } + + public MoviePart(Movie movie, int partIndex, int partCount) { - super(movie.name, movie.year, movie.imdbId); + this(movie.name, movie.year, movie.imdbId, partIndex, partCount); + } + + + public MoviePart(String name, int year, int imdbId, int partIndex, int partCount) { + super(name, year, imdbId); this.partIndex = partIndex; this.partCount = partCount; } - + public int getPartIndex() { return partIndex; } - + public int getPartCount() { return partCount; } - + + @Override + public boolean equals(Object object) { + if (object instanceof MoviePart && super.equals(object)) { + MoviePart other = (MoviePart) object; + return partIndex == other.partIndex && partCount == other.partCount; + } + + return super.equals(object); + } + + + @Override + public MoviePart clone() { + return new MoviePart(this); + } + + @Override public String toString() { return String.format("%s (%d) [%d]", name, year, partIndex);