Updating equals to check id's over title names to prevent issues with languages

This commit is contained in:
jhouse
2020-01-07 12:04:58 +09:00
parent 76e774bc9b
commit 54d93755bb
4 changed files with 27 additions and 15 deletions

View File

@@ -102,16 +102,28 @@ public final class Movie implements Comparable<Movie> {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Movie movie = (Movie) o;
return year == movie.year &&
Objects.equals(name, movie.name);
}
@Nullable
public String getPosterUrl() {
return posterUrl;
//Compare tvdb id first
if(tvdbId != -1 && movie.tvdbId != -1) {
return tvdbId == movie.tvdbId;
}
//Compare imdb id next
if(StringUtils.isNotEmpty(imdbId) &&
StringUtils.isNotEmpty(movie.imdbId)) {
return Objects.equals(imdbId, movie.imdbId);
}
//Fallback is year and title
return year == movie.year &&
name.equals(movie.name);
}
@Override
@@ -119,6 +131,11 @@ public final class Movie implements Comparable<Movie> {
return Objects.hash(name, year);
}
@Nullable
public String getPosterUrl() {
return posterUrl;
}
@Override
public String toString() {
return name + " (" + year + ")" + (StringUtils.isNotEmpty(collection) ? " --- collection='" + collection + '\'' : "");

View File

@@ -31,8 +31,6 @@ import java.time.LocalDate;
import java.time.Year;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
@@ -50,15 +48,12 @@ import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -26,7 +26,7 @@ logging:
level:
root: INFO
server:
port: 8484
port: 8443
compression:
enabled: true
mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json

File diff suppressed because one or more lines are too long