Cleaning up code

This commit is contained in:
Jason House
2020-07-19 19:01:44 +09:00
parent 37f3d1019b
commit ed04fe145e
7 changed files with 14 additions and 78 deletions

View File

@@ -1,53 +0,0 @@
/*
* Copyright 2020 Jason H House
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.jasonhhouse.gaps;
import java.util.Objects;
public class MoviePair {
private final String title;
private final int year;
public MoviePair(String title, int year) {
this.title = title;
this.year = year;
}
public String getTitle() {
return title;
}
public int getYear() {
return year;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MoviePair moviePair = (MoviePair) o;
return year == moviePair.year &&
Objects.equals(title, moviePair.title);
}
@Override
public int hashCode() {
return Objects.hash(title, year);
}
@Override
public String toString() {
return "MoviePair{" +
"title='" + title + '\'' +
", year=" + year +
'}';
}
}

View File

@@ -13,7 +13,7 @@ package com.jasonhhouse.gaps;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
public class PlexLibrary implements Comparable<PlexLibrary> {
public final class PlexLibrary implements Comparable<PlexLibrary> {
private @NotNull Integer key;
private @NotNull String title;
private @NotNull String machineIdentifier;

View File

@@ -36,7 +36,7 @@ public interface PlexQuery {
* Connect to plex via the URL and parse all the movies from the returned XML creating a HashSet of movies the
* user has.
*/
List<Movie> findAllPlexMovies(Map<MoviePair, Movie> previousMovies, @NotNull String url);
List<Movie> findAllPlexMovies(Map<Pair<String, Integer>, Movie> previousMovies, @NotNull String url);
@NotNull MediaContainer findAllPlexVideos(@NotNull String url);
}

View File

@@ -13,14 +13,14 @@ import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
public class PlexServer {
public final class PlexServer {
private String friendlyName;
private String machineIdentifier;
private String plexToken;
private String address;
private Integer port;
private Set<PlexLibrary> plexLibraries;
private final Set<PlexLibrary> plexLibraries;
public PlexServer() {
plexLibraries = new TreeSet<>();

View File

@@ -13,7 +13,7 @@ package com.jasonhhouse.gaps;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Objects;
public class Rss {
public final class Rss {
@JsonProperty("imdb_id")
private String imdbId;

View File

@@ -10,11 +10,7 @@
package com.jasonhhouse.gaps.controller;
import com.jasonhhouse.gaps.GapsService;
import com.jasonhhouse.gaps.Movie;
import com.jasonhhouse.gaps.MoviePair;
import com.jasonhhouse.gaps.PlexLibrary;
import com.jasonhhouse.gaps.PlexQuery;
import com.jasonhhouse.gaps.*;
import com.jasonhhouse.gaps.service.IoService;
import java.util.HashMap;
import java.util.List;
@@ -28,7 +24,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@@ -53,7 +48,7 @@ public class PlexMovieListController {
LOGGER.info("getPlexMovies( " + machineIdentifier + ", " + key + " )");
Set<Movie> everyMovie = ioService.readMovieIdsFromFile();
Map<MoviePair, Movie> previousMovies = generateOwnedMovieMap(everyMovie);
Map<Pair<String, Integer>, Movie> previousMovies = generateOwnedMovieMap(everyMovie);
String url = generatePlexUrl(machineIdentifier, key);
List<Movie> ownedMovies = plexQuery.findAllPlexMovies(previousMovies, url);
@@ -62,8 +57,8 @@ public class PlexMovieListController {
return ResponseEntity.ok().body(ownedMovies);
}
private Map<MoviePair, Movie> generateOwnedMovieMap(Set<Movie> everyMovie) {
Map<MoviePair, Movie> previousMovies = new HashMap<>();
private Map<Pair<String, Integer>, Movie> generateOwnedMovieMap(Set<Movie> everyMovie) {
Map<Pair<String, Integer>, Movie> previousMovies = new HashMap<>();
gapsService
.getPlexSearch()
@@ -75,7 +70,7 @@ public class PlexMovieListController {
.forEach(plexLibrary -> {
everyMovie
.forEach(movie -> {
previousMovies.put(new MoviePair(movie.getName(), movie.getYear()), movie);
previousMovies.put(new Pair<>(movie.getName(), movie.getYear()), movie);
});
}));

View File

@@ -10,13 +10,7 @@
package com.jasonhhouse.gaps.service;
import com.jasonhhouse.gaps.Movie;
import com.jasonhhouse.gaps.MoviePair;
import com.jasonhhouse.gaps.Payload;
import com.jasonhhouse.gaps.PlexLibrary;
import com.jasonhhouse.gaps.PlexQuery;
import com.jasonhhouse.gaps.PlexServer;
import com.jasonhhouse.gaps.UrlGenerator;
import com.jasonhhouse.gaps.*;
import com.jasonhhouse.plex.MediaContainer;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -298,7 +292,7 @@ public class PlexQueryImpl implements PlexQuery {
@Override
public List<Movie> findAllPlexMovies(Map<MoviePair, Movie> previousMovies, @NotNull String url) {
public List<Movie> findAllPlexMovies(Map<Pair<String, Integer>, Movie> previousMovies, @NotNull String url) {
LOGGER.info("findAllPlexMovies()");
List<Movie> ownedMovies = new ArrayList<>();
@@ -418,8 +412,8 @@ public class PlexQueryImpl implements PlexQuery {
return ownedMovies;
}
private Movie getOrCreateOwnedMovie(Map<MoviePair, Movie> previousMovies, String title, int year, String thumbnail, int tvdbId, String imdbId, String language, int collection, String collectionName, String summary) {
MoviePair moviePair = new MoviePair(title, year);
private Movie getOrCreateOwnedMovie(Map<Pair<String, Integer>, Movie> previousMovies, String title, int year, String thumbnail, int tvdbId, String imdbId, String language, int collection, String collectionName, String summary) {
Pair<String, Integer> moviePair = new Pair<>(title, year);
if (previousMovies.containsKey(moviePair)) {
return previousMovies.get(moviePair);
} else {