From 139383cae79cc825256f0a1693fea355f556b826 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 8 Mar 2024 11:51:42 +0100 Subject: [PATCH] =?utf8?q?=E2=99=BB=EF=B8=8F=20Convert=20Movie=20to=20Kotl?= =?utf8?q?in=20data=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../rhynodge/filters/webpages/savoy/Movie.java | 86 ---------------------- .../rhynodge/filters/webpages/savoy/Movie.kt | 15 ++++ .../rhynodge/filters/webpages/savoy/SavoyMerger.kt | 2 +- .../filters/webpages/savoy/MovieExtractorTest.java | 14 ++-- 4 files changed, 23 insertions(+), 94 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.java create mode 100644 src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.kt diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.java b/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.java deleted file mode 100644 index 76c766f..0000000 --- a/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.java +++ /dev/null @@ -1,86 +0,0 @@ -package net.pterodactylus.rhynodge.filters.webpages.savoy; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import static java.lang.String.format; -import static java.util.Collections.emptyList; - -/** - * Information about a movie. - * - * @author David ‘Bombe’ Roden - */ -public class Movie { - - @JsonProperty - private final String name; - - @JsonProperty - private final String imageUrl; - - @JsonProperty - private final String description; - - @JsonProperty - private final List performances = new ArrayList<>(); - - public Movie() { - this("", "", ""); - } - - public Movie(String name, String imageUrl) { - this(name, imageUrl, ""); - } - - public Movie(String name, String imageUrl, String description) { - this(name, imageUrl, description, emptyList()); - } - - public Movie(String name, String imageUrl, String description, Collection performances) { - this.name = name; - this.imageUrl = imageUrl; - this.description = description; - this.performances.addAll(performances); - } - - public String getName() { - return name; - } - - public String getImageUrl() { - return imageUrl; - } - - public String getDescription() { - return description; - } - - public List getPerformances() { - return performances; - } - - @Override - public String toString() { - return format("%s (%s, %s, %s)", name, imageUrl, description, performances.stream().map(link -> String.format("%s: %s", link.getTime(), link.getLink())).collect(Collectors.joining(", "))); - } - - @Override - public int hashCode() { - return Objects.hash(name, imageUrl, description, performances); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Movie movie = (Movie) o; - return Objects.equals(name, movie.name) && Objects.equals(imageUrl, movie.imageUrl) && Objects.equals(description, movie.description) && Objects.equals(performances, movie.performances); - } - -} diff --git a/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.kt b/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.kt new file mode 100644 index 0000000..b1e7b88 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.kt @@ -0,0 +1,15 @@ +package net.pterodactylus.rhynodge.filters.webpages.savoy + +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Objects +import java.util.stream.Collectors + +/** + * Information about a movie. + */ +data class Movie @JvmOverloads constructor( + @JvmField @field:JsonProperty val name: String = "", + @JvmField @field:JsonProperty val imageUrl: String = "", + @JvmField @field:JsonProperty val description: String = "", + @JvmField @field:JsonProperty val performances: Collection = emptyList() +) diff --git a/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyMerger.kt b/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyMerger.kt index 5406b17..644729f 100644 --- a/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyMerger.kt +++ b/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyMerger.kt @@ -13,7 +13,7 @@ class SavoyMerger : Merger { logger.debug("currentState: $currentState") val newMovies = currentState.movies - .filter { it.name !in previousState.movies.map(Movie::getName) } + .filter { it.name !in previousState.movies.map(Movie::name) } logger.debug("newMovies: $newMovies") val hasChangedPerformances = newMovies.isNotEmpty() || diff --git a/src/test/java/net/pterodactylus/rhynodge/filters/webpages/savoy/MovieExtractorTest.java b/src/test/java/net/pterodactylus/rhynodge/filters/webpages/savoy/MovieExtractorTest.java index 2b5988e..11e4a30 100644 --- a/src/test/java/net/pterodactylus/rhynodge/filters/webpages/savoy/MovieExtractorTest.java +++ b/src/test/java/net/pterodactylus/rhynodge/filters/webpages/savoy/MovieExtractorTest.java @@ -161,19 +161,19 @@ public class MovieExtractorTest { return new TypeSafeDiagnosingMatcher() { @Override protected boolean matchesSafely(Movie movie, Description mismatchDescription) { - if (!movie.getName().equals(name)) { - mismatchDescription.appendText("movie is named ").appendValue(movie.getName()); + if (!movie.name.equals(name)) { + mismatchDescription.appendText("movie is named ").appendValue(movie.name); return false; } - if (!movie.getImageUrl().equals(imageUrl)) { - mismatchDescription.appendText("image URL is ").appendValue(movie.getImageUrl()); + if (!movie.imageUrl.equals(imageUrl)) { + mismatchDescription.appendText("image URL is ").appendValue(movie.imageUrl); return false; } - if (!descriptionMatcher.matches(movie.getDescription())) { - descriptionMatcher.describeMismatch(movie.getDescription(), mismatchDescription); + if (!descriptionMatcher.matches(movie.description)) { + descriptionMatcher.describeMismatch(movie.description, mismatchDescription); return false; } - List performances = new ArrayList<>(movie.getPerformances()); + List performances = new ArrayList<>(movie.performances); if (performances.size() != presentationTimesTypesAndLinks.length) { mismatchDescription.appendText("has ").appendValue(performances.size()).appendText(" presentations"); return false; -- 2.7.4