Reducing search calls by saving out collection information

This commit is contained in:
Jason House
2019-12-08 10:44:14 +09:00
parent 5035382dd0
commit 97d1b79059
4 changed files with 180 additions and 51 deletions
@@ -10,6 +10,7 @@ package com.jasonhhouse.gaps;/*
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;
@@ -25,6 +26,10 @@ public final class Movie implements Comparable<Movie>, Jsonify<Movie> {
public static final String POSTER = "poster_url";
public static final String COLLECTION_ID = "collectionId";
public static final String COLLECTION = "collection";
private final String name;
private final int year;
@@ -35,42 +40,33 @@ public final class Movie implements Comparable<Movie>, Jsonify<Movie> {
@Nullable
private String collection;
private int collectionId;
private int tvdbId;
@Nullable
private String imdbId;
public Movie(int tvdbId, @Nullable String imdbId, String name, int year, @Nullable String collection, @Nullable String posterUrl) {
this.tvdbId = tvdbId;
this.imdbId = imdbId;
private Movie(String name, int year, @Nullable String posterUrl, @Nullable String collection, int collectionId, int tvdbId, @Nullable String imdbId) {
this.name = name;
this.year = year;
this.collection = collection;
this.posterUrl = posterUrl;
this.collection = collection;
this.collectionId = collectionId;
this.tvdbId = tvdbId;
this.imdbId = imdbId;
}
public Movie(int tvdbId, @Nullable String imdbId, String name, int year) {
this(tvdbId, imdbId, name, year, null, null);
public void setCollection(String collection) {
this.collection = collection;
}
public Movie(String imdbId, String name, int year, String collection) {
this(-1, imdbId, name, year, collection, null);
public int getCollectionId() {
return collectionId;
}
public Movie(int tvdbId, String name, int year, String collection) {
this(tvdbId, null, name, year, collection, null);
}
public Movie(int tvdbId, String name, int year, String collection, String posterUrl) {
this(tvdbId, null, name, year, collection, null);
}
public Movie(String name, int year, String collection) {
this(-1, name, year, collection);
}
public Movie(String name, int year) {
this(-1, name, year, null);
public void setCollectionId(int collectionId) {
this.collectionId = collectionId;
}
public int getTvdbId() {
@@ -127,13 +123,6 @@ public final class Movie implements Comparable<Movie>, Jsonify<Movie> {
return getName().compareTo(o.getName());
}
/*public void merge(Movie movie) {
tvdbId = tvdbId == -1 ? movie.getTvdbId() : -1;
imdbId = StringUtils.isBlank(imdbId) ? movie.getImdbId() : null;
collection = StringUtils.isBlank(collection) ? movie.getCollection() : null;
posterUrl = StringUtils.isBlank(posterUrl) ? movie.getPosterUrl() : null;
}*/
@Override
public JSONObject toJSON() {
JSONObject jsonObject = new JSONObject();
@@ -141,8 +130,64 @@ public final class Movie implements Comparable<Movie>, Jsonify<Movie> {
jsonObject.put(IMDB_ID, imdbId);
jsonObject.put(NAME, name);
jsonObject.put(YEAR, year);
jsonObject.put(POSTER, posterUrl);
jsonObject.put(COLLECTION_ID, collectionId);
jsonObject.put(COLLECTION, collection);
return jsonObject;
}
public static class Builder {
private final String name;
private final int year;
private String posterUrl;
private String collection;
private int collectionId;
private int tvdbId;
private String imdbId;
public Builder(String name, int year) {
this.name = name;
this.year = year;
this.tvdbId = -1;
this.imdbId = "";
this.collection = "";
this.posterUrl = "";
this.collectionId = -1;
}
public Movie build() {
return new Movie(name, year, posterUrl, collection, collectionId, tvdbId, imdbId);
}
public Builder setPosterUrl(String posterUrl) {
this.posterUrl = posterUrl;
return this;
}
public Builder setCollection(String collection) {
this.collection = collection;
return this;
}
public Builder setCollectionId(int collectionId) {
this.collectionId = collectionId;
return this;
}
public Builder setTvdbId(int tvdbId) {
this.tvdbId = tvdbId;
return this;
}
public Builder setImdbId(String imdbId) {
this.imdbId = imdbId;
return this;
}
}
}