diff --git a/README.md b/README.md index c1682d9..a5716c2 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ * Если всего поровну или вам лень что-либо настраивать - `Смешанный`; поиск выполняется по цепочке `XML -> JSON -> HTML` #### Сравнение: - * Если не хотите разбираться в тонкостях настройки или это ваш первый запуск, то оставьте как есть, а именно: `Год с отклонением` и `Интеллектуальное сравнение названий`. + * Если не хотите разбираться в тонкостях настройки или это ваш первый запуск, то оставьте как есть, а именно: `Год с отклонением`, `Тип фильма с полным совпадением` и `Интеллектуальное сравнение названий`. #### Чистый запуск: * Включайте только если случайно удалили оценки/список на сайте IMDB, и хотите импортировать список с Кинопоиска заново. @@ -51,6 +51,8 @@ - `Сравнение` - каким способом сравнивать названия фильмов из таблицы Кинопоиска с найденными в IMDB. - (По умолчанию) `Год с отклонением` - сравнить год, используя отклонение в +/-1 год - `Год с полным совпадением` - проверить идентичность по годам. + - (По умолчанию) `Тип фильма с полным совпадением` - индентичное сравнение типов фильмов (обычный/сериал/документальный/короткометражка) + - `Любой тип фильма` - не сравнивать типы фильмов - (По умолчанию) `Интеллектуальное сравнение названий` - сравнить названия, используя уникальный алгоритм. - `Полное совпадение названий` - проверить на идентичность названий. - `Одно название начинается с другого` - сравнить находится ли название фильма из таблицы Кинопоиска в начале названия с IMDB. diff --git a/core/build.gradle b/core/build.gradle index c1a222a..25fde12 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,4 +1,4 @@ -version = "0.7.8" +version = "0.9.0" ext { guiceVersion = "4.0" diff --git a/core/src/main/java/org/f0w/k2i/core/comparator/MovieComparator.java b/core/src/main/java/org/f0w/k2i/core/comparator/MovieComparator.java index cae925d..ab94a2c 100644 --- a/core/src/main/java/org/f0w/k2i/core/comparator/MovieComparator.java +++ b/core/src/main/java/org/f0w/k2i/core/comparator/MovieComparator.java @@ -27,6 +27,8 @@ enum Type { TITLE_EQUALS, TITLE_SMART, YEAR_DEVIATION, - YEAR_EQUALS + YEAR_EQUALS, + TYPE_EQUALS, + TYPE_ANY } } diff --git a/core/src/main/java/org/f0w/k2i/core/comparator/MovieComparatorFactory.java b/core/src/main/java/org/f0w/k2i/core/comparator/MovieComparatorFactory.java index 7077265..101202b 100644 --- a/core/src/main/java/org/f0w/k2i/core/comparator/MovieComparatorFactory.java +++ b/core/src/main/java/org/f0w/k2i/core/comparator/MovieComparatorFactory.java @@ -3,6 +3,8 @@ import com.google.inject.Inject; import com.typesafe.config.Config; import org.f0w.k2i.core.comparator.title.*; +import org.f0w.k2i.core.comparator.type.AnyTypeComparator; +import org.f0w.k2i.core.comparator.type.EqualsTypeComparator; import org.f0w.k2i.core.comparator.year.DeviationYearComparator; import org.f0w.k2i.core.comparator.year.EqualsYearComparator; @@ -41,6 +43,10 @@ public MovieComparator make(MovieComparator.Type type) { return new DeviationYearComparator(config); case YEAR_EQUALS: return new EqualsYearComparator(); + case TYPE_EQUALS: + return new EqualsTypeComparator(); + case TYPE_ANY: + return new AnyTypeComparator(); default: throw new IllegalArgumentException("Comparator of this type not found!"); } diff --git a/core/src/main/java/org/f0w/k2i/core/comparator/title/SmartTitleComparator.java b/core/src/main/java/org/f0w/k2i/core/comparator/title/SmartTitleComparator.java index 4ab0462..36fa1cf 100644 --- a/core/src/main/java/org/f0w/k2i/core/comparator/title/SmartTitleComparator.java +++ b/core/src/main/java/org/f0w/k2i/core/comparator/title/SmartTitleComparator.java @@ -29,8 +29,8 @@ public final class SmartTitleComparator extends AbstractMovieComparator { list.add(s -> s); // Original string without one of symbols - val symbolsToRemove = Arrays.asList(",", ":", "-", " "); - symbolsToRemove.forEach(symbol -> list.add(s -> replace(s, symbol, ""))); + val symbolsToRemove = Arrays.asList(",", ":", "-", " ", "3-D", "3D", "4D", "4-D"); + symbolsToRemove.forEach(symbol -> list.add(s -> replace(s, symbol, "").trim())); // Original string without apostrophes and quotes list.add(s -> { @@ -50,13 +50,20 @@ public final class SmartTitleComparator extends AbstractMovieComparator { // Original string without special symbols like unicode etc list.add(s -> javaLetterOrDigit().or(WHITESPACE).or(isNot('.')).precomputed().retainFrom(s)); - // Original string with part before one of separating symbols - val separatingSymbols = Collections.singletonList("-"); - separatingSymbols.forEach(separator -> list.add(s -> Arrays.stream(splitByWholeSeparator(s, separator)) - .findFirst() - .map(String::trim) - .orElse(s) - )); + // Original string with part before or after one of separating symbols + val separatingSymbols = Arrays.asList("-", ":"); + separatingSymbols.forEach(separator -> { + list.add(s -> Arrays.stream(splitByWholeSeparator(s, separator)) + .findFirst() + .map(String::trim) + .orElse(s) + ); + list.add(s -> Arrays.stream(splitByWholeSeparator(s, separator)) + .reduce((s1, s2) -> s2) + .map(String::trim) + .orElse(s) + ); + }); // One of the prefixes + original string val prefixes = Collections.singletonList("The "); diff --git a/core/src/main/java/org/f0w/k2i/core/comparator/type/AnyTypeComparator.java b/core/src/main/java/org/f0w/k2i/core/comparator/type/AnyTypeComparator.java new file mode 100644 index 0000000..8ac5ab6 --- /dev/null +++ b/core/src/main/java/org/f0w/k2i/core/comparator/type/AnyTypeComparator.java @@ -0,0 +1,21 @@ +package org.f0w.k2i.core.comparator.type; + +import lombok.NonNull; +import org.f0w.k2i.core.comparator.AbstractMovieComparator; +import org.f0w.k2i.core.model.entity.Movie; + +public final class AnyTypeComparator extends AbstractMovieComparator { + /** + * {@inheritDoc} + */ + @Override + public boolean areEqual(@NonNull Movie movie1, @NonNull Movie movie2) { + LOG.debug( + "Comparing types disabled, tried to compare type '{}' with type '{}''", + movie1.getType(), + movie2.getType() + ); + + return true; + } +} diff --git a/core/src/main/java/org/f0w/k2i/core/comparator/type/EqualsTypeComparator.java b/core/src/main/java/org/f0w/k2i/core/comparator/type/EqualsTypeComparator.java new file mode 100644 index 0000000..d2ab08a --- /dev/null +++ b/core/src/main/java/org/f0w/k2i/core/comparator/type/EqualsTypeComparator.java @@ -0,0 +1,24 @@ +package org.f0w.k2i.core.comparator.type; + +import lombok.NonNull; +import org.f0w.k2i.core.comparator.AbstractMovieComparator; +import org.f0w.k2i.core.model.entity.Movie; + +public final class EqualsTypeComparator extends AbstractMovieComparator { + /** + * {@inheritDoc} + */ + @Override + public boolean areEqual(@NonNull Movie movie1, @NonNull Movie movie2) { + boolean result = movie1.getType().equals(movie2.getType()); + + LOG.debug( + "Comparing type '{}' with type '{}', matches = '{}'", + movie1.getType(), + movie2.getType(), + result + ); + + return result; + } +} diff --git a/core/src/main/java/org/f0w/k2i/core/exchange/finder/MixedMovieFinder.java b/core/src/main/java/org/f0w/k2i/core/exchange/finder/MixedMovieFinder.java index 4e867aa..50addc3 100644 --- a/core/src/main/java/org/f0w/k2i/core/exchange/finder/MixedMovieFinder.java +++ b/core/src/main/java/org/f0w/k2i/core/exchange/finder/MixedMovieFinder.java @@ -8,10 +8,7 @@ import org.jsoup.Connection; import java.io.IOException; -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; +import java.util.*; @Slf4j public final class MixedMovieFinder implements MovieFinder { diff --git a/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/ExchangeStrategy.java b/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/ExchangeStrategy.java index 0eb51f6..edcc3db 100644 --- a/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/ExchangeStrategy.java +++ b/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/ExchangeStrategy.java @@ -2,6 +2,7 @@ import lombok.NonNull; import org.f0w.k2i.core.model.entity.Movie; +import org.f0w.k2i.core.util.MovieUtils; import java.net.URL; import java.util.Collections; @@ -35,23 +36,34 @@ public interface ExchangeStrategy { * Used in {@link this#parseSearchResult(String)} * * @param Root element - * @param Title element - * @param Year element - * @param IMDB ID element + * @param Title element + * @param <YEAR> Year element + * @param <YEAR> Type element + * @param <ID> IMDB ID element */ - interface MovieParser<R, T, Y, I> { - default Movie parse(R rootElement, Function<R, T> title, Function<R, Y> year, Function<R, I> imdbID) { + interface MovieParser<R, TITLE, YEAR, TYPE, ID> { + default Movie parse( + R rootElement, + Function<R, TITLE> title, + Function<R, YEAR> year, + Function<R, TYPE> type, + Function<R, ID> imdbID + ) { return new Movie( parseTitle(prepareTitle(title.apply(rootElement))), parseYear(prepareYear(year.apply(rootElement))), + parseType(type.apply(rootElement)), + null, parseIMDBId(prepareImdbId(imdbID.apply(rootElement))) ); } - String prepareTitle(T element); + String prepareTitle(TITLE element); - String prepareYear(Y element); + String prepareYear(YEAR element); - String prepareImdbId(I element); + Movie.Type parseType(TYPE element); + + String prepareImdbId(ID element); } } diff --git a/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/HTMLExchangeStrategy.java b/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/HTMLExchangeStrategy.java index 6eb0719..d4e08f4 100644 --- a/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/HTMLExchangeStrategy.java +++ b/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/HTMLExchangeStrategy.java @@ -47,12 +47,13 @@ public List<Movie> parseSearchResult(@NonNull final String data) { e, t -> t, Element::text, + t -> t, t -> t.getElementsByTag("a").first() )) .collect(Collectors.toList()); } - private static final class HTMLMovieParser implements MovieParser<Element, Element, String, Element> { + private static final class HTMLMovieParser implements MovieParser<Element, Element, String, Element, Element> { @Override public String prepareTitle(Element element) { String elementText = element.text(); @@ -86,6 +87,21 @@ public String prepareYear(String element) { return preparedYear; } + @Override + public Movie.Type parseType(Element element) { + val elementText = element.text(); + + if (elementText.contains("(TV Series)") || elementText.contains("(TV Mini-Series)")) { + return Movie.Type.SERIES; + } else if (elementText.contains("(Short)")) { + return Movie.Type.SHORT; + } else if (elementText.contains("(Video Game)")) { + return Movie.Type.VIDEO_GAME; + } + + return Movie.Type.MOVIE; + } + @Override public String prepareImdbId(Element element) { return Optional.ofNullable(element) diff --git a/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/JSONExchangeStrategy.java b/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/JSONExchangeStrategy.java index 7f071b3..7a15171 100644 --- a/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/JSONExchangeStrategy.java +++ b/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/JSONExchangeStrategy.java @@ -55,12 +55,13 @@ public List<Movie> parseSearchResult(@NonNull final String data) { e.getAsJsonObject(), t -> t.get("title"), t -> t.get("description"), + t -> t.get("description"), t -> t.get("id") )) .collect(Collectors.toList()); } - private static final class JSONMovieParser implements MovieParser<JsonObject, JsonElement, JsonElement, JsonElement> { + private static final class JSONMovieParser implements MovieParser<JsonObject, JsonElement, JsonElement, JsonElement, JsonElement> { @Override public String prepareTitle(JsonElement element) { return getStringOrNull(element); @@ -71,6 +72,23 @@ public String prepareYear(JsonElement element) { return getStringOrNull(element); } + @Override + public Movie.Type parseType(JsonElement element) { + val stringValue = Optional.ofNullable(element).map(JsonElement::getAsString).orElse(""); + + if (stringValue.contains("TV series")) { + return Movie.Type.SERIES; + } else if (stringValue.contains("documentary")) { + return Movie.Type.DOCUMENTARY; + } else if (stringValue.contains("short")) { + return Movie.Type.SHORT; + } else if (stringValue.contains("video game")) { + return Movie.Type.VIDEO_GAME; + } + + return Movie.Type.MOVIE; + } + @Override public String prepareImdbId(JsonElement element) { return getStringOrNull(element); diff --git a/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/XMLExchangeStrategy.java b/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/XMLExchangeStrategy.java index bbec22d..0e47d92 100644 --- a/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/XMLExchangeStrategy.java +++ b/core/src/main/java/org/f0w/k2i/core/exchange/finder/strategy/XMLExchangeStrategy.java @@ -44,12 +44,13 @@ public List<Movie> parseSearchResult(@NonNull final String data) { e, Element::ownText, t -> t.getElementsByTag("Description").first(), + t -> t.getElementsByTag("Description").first(), t -> t.attr("id") )) .collect(Collectors.toList()); } - private static final class XMLMovieParser implements MovieParser<Element, String, Element, String> { + private static final class XMLMovieParser implements MovieParser<Element, String, Element, Element, String> { @Override public String prepareTitle(String element) { return element; @@ -62,6 +63,23 @@ public String prepareYear(Element element) { .orElse(null); } + @Override + public Movie.Type parseType(Element element) { + val stringValue = Optional.ofNullable(element).map(Element::text).orElse(""); + + if (stringValue.contains("TV series")) { + return Movie.Type.SERIES; + } else if (stringValue.contains("documentary")) { + return Movie.Type.DOCUMENTARY; + } else if (stringValue.contains("short")) { + return Movie.Type.SHORT; + } else if (stringValue.contains("video game")) { + return Movie.Type.VIDEO_GAME; + } + + return Movie.Type.MOVIE; + } + @Override public String prepareImdbId(String element) { return element; diff --git a/core/src/main/java/org/f0w/k2i/core/model/entity/Movie.java b/core/src/main/java/org/f0w/k2i/core/model/entity/Movie.java index e64e288..af33d14 100644 --- a/core/src/main/java/org/f0w/k2i/core/model/entity/Movie.java +++ b/core/src/main/java/org/f0w/k2i/core/model/entity/Movie.java @@ -2,10 +2,7 @@ import lombok.*; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; +import javax.persistence.*; @Entity @Table(name = "MOVIES", uniqueConstraints = @UniqueConstraint(columnNames = {"TITLE", "YEAR"})) @@ -21,6 +18,11 @@ public class Movie extends BaseEntity { @Column(name = "YEAR", nullable = false) private int year; + @Column(name = "TYPE", nullable = false) + @Enumerated(EnumType.STRING) + @NonNull + private Type type; + @Column(name = "RATING") private Integer rating; @@ -28,18 +30,33 @@ public class Movie extends BaseEntity { private String imdbId; public Movie(String title, int year) { - this(title, year, null, null); + this(title, year, Type.MOVIE, null, null); } public Movie(String title, int year, Integer rating) { - this(title, year, rating, null); + this(title, year, Type.MOVIE, rating, null); + } + + public Movie(String title, int year, Type type) { + this(title, year, type, null, null); } public Movie(String title, int year, String imdbId) { - this(title, year, null, imdbId); + this(title, year, Type.MOVIE, null, imdbId); } public Movie(Movie movie) { - this(movie.getTitle(), movie.getYear(), movie.getRating(), movie.getImdbId()); + this(movie.getTitle(), movie.getYear(), movie.getType(), movie.getRating(), movie.getImdbId()); + } + + /** + * Type of movie + */ + public enum Type { + MOVIE, + DOCUMENTARY, + SHORT, + SERIES, + VIDEO_GAME } } diff --git a/core/src/main/java/org/f0w/k2i/core/util/MovieUtils.java b/core/src/main/java/org/f0w/k2i/core/util/MovieUtils.java index 175a9b6..0ea61c2 100644 --- a/core/src/main/java/org/f0w/k2i/core/util/MovieUtils.java +++ b/core/src/main/java/org/f0w/k2i/core/util/MovieUtils.java @@ -1,21 +1,26 @@ package org.f0w.k2i.core.util; +import com.google.common.collect.ImmutableMap; import lombok.val; +import org.f0w.k2i.core.exchange.finder.strategy.XMLExchangeStrategy; import org.f0w.k2i.core.model.entity.Movie; import org.f0w.k2i.core.util.exception.KinopoiskToIMDBException; import org.jsoup.Jsoup; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; +import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import static org.f0w.k2i.core.util.exception.ExceptionUtils.uncheck; import static org.apache.commons.lang3.StringUtils.replaceEachRepeatedly; +import static org.apache.commons.lang3.StringUtils.splitByWholeSeparator; /** * NullPointer safe class for checking and parsing movie fields. @@ -79,6 +84,23 @@ public static int parseYear(final String yearString) { } } + private static Movie.Type parseType(final Map<String, String> row) { + val genres = Arrays.asList(splitByWholeSeparator(row.get("жанры"), ", ")); + val isSeries = splitByWholeSeparator(row.get("год"), "-").length == 2; + + if (isSeries) { + return Movie.Type.SERIES; + } + + if (genres.contains("документальный")) { + return Movie.Type.DOCUMENTARY; + } else if (genres.contains("короткометражка")) { + return Movie.Type.SHORT; + } + + return Movie.Type.MOVIE; + } + /** * Parses IMDB ID or returns null if it not valid * @@ -192,7 +214,9 @@ public static List<Movie> parseMovies(final Path filePath) { .map(m -> new Movie( parseTitle(m.get("оригинальное название"), m.get("русскоязычное название")), parseYear(m.get("год")), - parseRating(m.get("моя оценка")) + parseType(m), + parseRating(m.get("моя оценка")), + null )) .collect(Collectors.toList()); } diff --git a/core/src/main/resources/application.json b/core/src/main/resources/application.json index 97a79b6..fa5408d 100644 --- a/core/src/main/resources/application.json +++ b/core/src/main/resources/application.json @@ -9,6 +9,7 @@ "auth": "", "comparators": [ "YEAR_DEVIATION", + "TYPE_EQUALS", "TITLE_SMART" ], "db": { diff --git a/core/src/test/java/org/f0w/k2i/MovieTestData.java b/core/src/test/java/org/f0w/k2i/MovieTestData.java index 745557d..c7799c2 100644 --- a/core/src/test/java/org/f0w/k2i/MovieTestData.java +++ b/core/src/test/java/org/f0w/k2i/MovieTestData.java @@ -6,13 +6,13 @@ import java.util.List; public class MovieTestData { - public static final Movie MOVIE_1 = new Movie("Inception", 2010, 9, "tt1375666"); - public static final Movie MOVIE_2 = new Movie("Breaking Bad", 2008, 10, "tt0903747"); - public static final Movie MOVIE_3 = new Movie("Kokaku kidotai: Stand Alone Complex", 2002, 10, "tt0346314"); - public static final Movie MOVIE_4 = new Movie("Hannibal", 2013, 10, "tt2243973"); - public static final Movie MOVIE_5 = new Movie("Sin City", 2005, 10, "tt0401792"); - public static final Movie MOVIE_6 = new Movie("Шерлок Холмс и доктор Ватсон: Знакомство", 1979, 10, "tt0079902"); - public static final Movie MOVIE_7 = new Movie("Операция Ы и другие приключения Шурика", 1965, 10, "tt0059550"); + public static final Movie MOVIE_1 = new Movie("Inception", 2010, Movie.Type.MOVIE, 9, "tt1375666"); + public static final Movie MOVIE_2 = new Movie("Breaking Bad", 2008, Movie.Type.SERIES, 10, "tt0903747"); + public static final Movie MOVIE_3 = new Movie("Kokaku kidotai: Stand Alone Complex", 2002, Movie.Type.SERIES, 10, "tt0346314"); + public static final Movie MOVIE_4 = new Movie("Hannibal", 2013, Movie.Type.SERIES, 10, "tt2243973"); + public static final Movie MOVIE_5 = new Movie("Sin City", 2005, Movie.Type.MOVIE, 10, "tt0401792"); + public static final Movie MOVIE_6 = new Movie("Шерлок Холмс и доктор Ватсон: Знакомство", 1979, Movie.Type.MOVIE, 10, "tt0079902"); + public static final Movie MOVIE_7 = new Movie("Операция Ы и другие приключения Шурика", 1965, Movie.Type.MOVIE, 10, "tt0059550"); public static final List<Movie> MOVIES_LIST = Arrays.asList(MOVIE_7, MOVIE_6, MOVIE_5, MOVIE_4, MOVIE_3, MOVIE_2, MOVIE_1); } diff --git a/core/src/test/java/org/f0w/k2i/core/comparator/MovieComparatorFactoryTest.java b/core/src/test/java/org/f0w/k2i/core/comparator/MovieComparatorFactoryTest.java index 8da9938..dcdf8f3 100644 --- a/core/src/test/java/org/f0w/k2i/core/comparator/MovieComparatorFactoryTest.java +++ b/core/src/test/java/org/f0w/k2i/core/comparator/MovieComparatorFactoryTest.java @@ -4,6 +4,8 @@ import com.typesafe.config.ConfigFactory; import lombok.val; import org.f0w.k2i.core.comparator.title.*; +import org.f0w.k2i.core.comparator.type.AnyTypeComparator; +import org.f0w.k2i.core.comparator.type.EqualsTypeComparator; import org.f0w.k2i.core.comparator.year.DeviationYearComparator; import org.f0w.k2i.core.comparator.year.EqualsYearComparator; import org.junit.Test; @@ -20,6 +22,8 @@ public void make() throws Exception { val classMap = new ImmutableMap.Builder<Type, Class<? extends MovieComparator>>() .put(YEAR_EQUALS, EqualsYearComparator.class) .put(YEAR_DEVIATION, DeviationYearComparator.class) + .put(TYPE_EQUALS, EqualsTypeComparator.class) + .put(TYPE_ANY, AnyTypeComparator.class) .put(TITLE_CONTAINS, ContainsTitleComparator.class) .put(TITLE_ENDS, EndsWithTitleComparator.class) .put(TITLE_STARTS, StartsWithTitleComparator.class) diff --git a/core/src/test/java/org/f0w/k2i/core/comparator/title/SmartTitleComparatorTest.java b/core/src/test/java/org/f0w/k2i/core/comparator/title/SmartTitleComparatorTest.java index c394878..92d3886 100644 --- a/core/src/test/java/org/f0w/k2i/core/comparator/title/SmartTitleComparatorTest.java +++ b/core/src/test/java/org/f0w/k2i/core/comparator/title/SmartTitleComparatorTest.java @@ -52,6 +52,11 @@ public void areEqualWithRemovedSymbols() throws Exception { new Movie("Lock Out", 2012), new Movie("Lockout", 2012) )); + + assertTrue(comparator.areEqual( + new Movie("The Incredibles 3-D", 2004), + new Movie("The Incredibles", 2004) + )); } @Test @@ -81,6 +86,24 @@ public void areEqualWithPartBeforeOneOfSeparatingSymbols() { new Movie("Super Movie - Again", 2002), new Movie("Super Movie", 2002) )); + + assertTrue(comparator.areEqual( + new Movie("Taare Zameen Par: Every Child Is Special", 2007), + new Movie("Taare Zameen Par", 2007) + )); + } + + @Test + public void areEqualWithPartAfterOneOfSeparatingSymbols() { + assertTrue(comparator.areEqual( + new Movie("Super Movie - Again - And again", 2002), + new Movie("And again", 2002) + )); + + assertTrue(comparator.areEqual( + new Movie("4: Rise of the Silver Surfer", 2007), + new Movie("Rise of the Silver Surfer", 2007) + )); } @Test diff --git a/core/src/test/java/org/f0w/k2i/core/comparator/type/AnyTypeComparatorTest.java b/core/src/test/java/org/f0w/k2i/core/comparator/type/AnyTypeComparatorTest.java new file mode 100644 index 0000000..e9e92b3 --- /dev/null +++ b/core/src/test/java/org/f0w/k2i/core/comparator/type/AnyTypeComparatorTest.java @@ -0,0 +1,27 @@ +package org.f0w.k2i.core.comparator.type; + +import org.f0w.k2i.core.comparator.MovieComparator; +import org.f0w.k2i.core.model.entity.Movie; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.*; + +public class AnyTypeComparatorTest { + private MovieComparator comparator = new AnyTypeComparator(); + + @Test + public void areAllEqual() throws Exception { + List<Movie> equalMovies = Arrays.asList( + new Movie("Inception", 2010, Movie.Type.MOVIE), + new Movie("Inception", 2010, Movie.Type.DOCUMENTARY), + new Movie("Inception", 2010, Movie.Type.SERIES), + new Movie("Inception", 2010, Movie.Type.SHORT), + new Movie("Inception", 2010, Movie.Type.VIDEO_GAME) + ); + + equalMovies.forEach(m1 -> equalMovies.forEach(m2 -> assertTrue(comparator.areEqual(m1, m2)))); + } +} \ No newline at end of file diff --git a/core/src/test/java/org/f0w/k2i/core/comparator/type/EqualsTypeComparatorTest.java b/core/src/test/java/org/f0w/k2i/core/comparator/type/EqualsTypeComparatorTest.java new file mode 100644 index 0000000..368c31f --- /dev/null +++ b/core/src/test/java/org/f0w/k2i/core/comparator/type/EqualsTypeComparatorTest.java @@ -0,0 +1,45 @@ +package org.f0w.k2i.core.comparator.type; + +import org.f0w.k2i.core.comparator.MovieComparator; +import org.f0w.k2i.core.model.entity.Movie; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class EqualsTypeComparatorTest { + private MovieComparator comparator = new EqualsTypeComparator(); + + @Test + public void areEqualEqual() throws Exception { + for (Movie.Type type : Movie.Type.values()) { + assertTrue(comparator.areEqual( + new Movie("Inception", 2010, type), + new Movie("Inception", 2010, type) + )); + } + } + + @Test + public void areEqualNotEqual() throws Exception { + assertFalse(comparator.areEqual( + new Movie("Inception", 2010, Movie.Type.MOVIE), + new Movie("Inception", 2010, Movie.Type.DOCUMENTARY) + )); + + assertFalse(comparator.areEqual( + new Movie("Inception", 2010, Movie.Type.MOVIE), + new Movie("Inception", 2010, Movie.Type.SHORT) + )); + + assertFalse(comparator.areEqual( + new Movie("Inception", 2010, Movie.Type.MOVIE), + new Movie("Inception", 2010, Movie.Type.SERIES) + )); + + assertFalse(comparator.areEqual( + new Movie("Inception", 2010, Movie.Type.MOVIE), + new Movie("Inception", 2010, Movie.Type.VIDEO_GAME) + )); + } +} \ No newline at end of file diff --git a/core/src/test/java/org/f0w/k2i/core/event/ImportFinishedEventTest.java b/core/src/test/java/org/f0w/k2i/core/event/ImportFinishedEventTest.java index 9dd275f..eef02d5 100644 --- a/core/src/test/java/org/f0w/k2i/core/event/ImportFinishedEventTest.java +++ b/core/src/test/java/org/f0w/k2i/core/event/ImportFinishedEventTest.java @@ -27,7 +27,7 @@ public void constructorInitialization() { @Test public void isImmutableError() { List<MovieHandler.Error> errors = Collections.singletonList( - new MovieHandler.Error(new Movie("Inception", 2010, 9, "tt1375666"), "Error 1") + new MovieHandler.Error(new Movie("Inception", 2010, Movie.Type.MOVIE, 9, "tt1375666"), "Error 1") ); ImportFinishedEvent event = new ImportFinishedEvent(errors); @@ -36,13 +36,13 @@ public void isImmutableError() { mutableEntity.setYear(9999); mutableEntity.setRating(1); - assertEquals(new Movie("Inception", 2010, 9, "tt1375666"), event.errors.get(0).getMovie()); + assertEquals(new Movie("Inception", 2010, Movie.Type.MOVIE, 9, "tt1375666"), event.errors.get(0).getMovie()); } @Test public void isImmutableErrorsList() { List<MovieHandler.Error> errors = new ArrayList<>(Collections.singletonList( - new MovieHandler.Error(new Movie("Inception", 2010, 9, "tt1375666"), "Error 1") + new MovieHandler.Error(new Movie("Inception", 2010, Movie.Type.MOVIE, 9, "tt1375666"), "Error 1") )); ImportFinishedEvent event = new ImportFinishedEvent(errors); @@ -51,7 +51,7 @@ public void isImmutableErrorsList() { assertTrue(errors.isEmpty()); assertEquals( Collections.singletonList( - new MovieHandler.Error(new Movie("Inception", 2010, 9, "tt1375666"), "Error 1") + new MovieHandler.Error(new Movie("Inception", 2010, Movie.Type.MOVIE, 9, "tt1375666"), "Error 1") ), event.errors ); diff --git a/core/src/test/java/org/f0w/k2i/core/model/entity/MovieTest.java b/core/src/test/java/org/f0w/k2i/core/model/entity/MovieTest.java index 98a86ef..10f26b8 100644 --- a/core/src/test/java/org/f0w/k2i/core/model/entity/MovieTest.java +++ b/core/src/test/java/org/f0w/k2i/core/model/entity/MovieTest.java @@ -17,9 +17,11 @@ public class MovieTest { public void testEqualsAndHashCode() throws Exception { val equalMovies = new ImmutableMap.Builder<Movie, Movie>() .put(new Movie("Inception", 2010), new Movie("Inception", 2010)) - .put(new Movie("Sin City", 2005), new Movie("Sin City", 2005, 10, "tt1")) - .put(new Movie("Breaking Bad", 2008, null, null), new Movie("Breaking Bad", 2008, 10, "tt1")) - .put(new Movie("Hannibal", 2013, 5, "tt1"), new Movie("Hannibal", 2013, 10, "tt2")) + .put(new Movie("Sin City", 2005), new Movie("Sin City", 2005, Movie.Type.MOVIE, 10, "tt1")) + .put(new Movie("Breaking Bad", 2008), new Movie("Breaking Bad", 2008, Movie.Type.MOVIE, 10, "tt1")) + .put(new Movie("Hannibal", 2013, Movie.Type.MOVIE, 5, "tt1"), + new Movie("Hannibal", 2013, Movie.Type.MOVIE, 10, "tt2") + ) .build(); equalMovies.forEach((movie1, movie2) -> { diff --git a/core/src/test/java/org/f0w/k2i/core/util/MovieUtilsTest.java b/core/src/test/java/org/f0w/k2i/core/util/MovieUtilsTest.java index 77bb54a..ca13bd1 100644 --- a/core/src/test/java/org/f0w/k2i/core/util/MovieUtilsTest.java +++ b/core/src/test/java/org/f0w/k2i/core/util/MovieUtilsTest.java @@ -129,16 +129,16 @@ public void parseMoviesFromValidFileExportedFromLists() throws Exception { new Movie("Intouchables", 2011, 10), new Movie("South Park", 1997, 10), new Movie("Breaking Bad", 2008, 10), - new Movie("Они сражались за Родину", 1975, null, null), - new Movie("Белый Бим Черное ухо", 1976, null, null), - new Movie("Судьба человека", 1959, null, null), - new Movie("Летят журавли", 1957, null, null), - new Movie("Москва слезам не верит", 1979, null, null), - new Movie("Офицеры", 1971, null, null), + new Movie("Они сражались за Родину", 1975), + new Movie("Белый Бим Черное ухо", 1976), + new Movie("Судьба человека", 1959), + new Movie("Летят журавли", 1957), + new Movie("Москва слезам не верит", 1979), + new Movie("Офицеры", 1971), new Movie("Собачье сердце", 1988, 10), - new Movie("Шерлок Холмс и доктор Ватсон: Знакомство", 1979, null, null), - new Movie("Приключения Шерлока Холмса и доктора Ватсона: Собака Баскервилей", 1981, null, null), - new Movie("...А зори здесь тихие", 1972, null, null), + new Movie("Шерлок Холмс и доктор Ватсон: Знакомство", 1979), + new Movie("Приключения Шерлока Холмса и доктора Ватсона: Собака Баскервилей", 1981), + new Movie("...А зори здесь тихие", 1972), new Movie("Бриллиантовая рука", 1968, 8), new Movie("В бой идут одни старики", 1973, 8), new Movie("Иван Васильевич меняет профессию", 1973, 8), diff --git a/gui/build.gradle b/gui/build.gradle index c78deff..c042f66 100644 --- a/gui/build.gradle +++ b/gui/build.gradle @@ -5,7 +5,7 @@ plugins { } mainClassName = 'org.f0w.k2i.gui.Main' -version = '1.0.0' +version = '1.1.0' dependencies { compile project(':k2i-core') diff --git a/gui/src/main/java/org/f0w/k2i/gui/Controller.java b/gui/src/main/java/org/f0w/k2i/gui/Controller.java index 31866f1..7ce2539 100644 --- a/gui/src/main/java/org/f0w/k2i/gui/Controller.java +++ b/gui/src/main/java/org/f0w/k2i/gui/Controller.java @@ -147,6 +147,8 @@ void initialize() { comparatorsBox.getItems().addAll(FXCollections.observableList(Arrays.asList( new Choice<>(YEAR_DEVIATION, "Год с отклонением"), new Choice<>(YEAR_EQUALS, "Год с полным совпадением"), + new Choice<>(TYPE_EQUALS, "Тип фильма с полным совпадением"), + new Choice<>(TYPE_ANY, "Любой тип фильма"), new Choice<>(TITLE_SMART, "Интеллектуальное сравнение названий"), new Choice<>(TITLE_EQUALS, "Полное совпадение названий"), new Choice<>(TITLE_CONTAINS, "Одно название содержит другое"),