From 045bbf7badb6710ead966598b74c0325e788463c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 8 Mar 2024 12:32:29 +0100 Subject: [PATCH] =?utf8?q?=E2=99=BB=EF=B8=8F=20Convert=20SavoyTicketsFilte?= =?utf8?q?r=20to=20Kotlin=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../filters/webpages/savoy/SavoyTicketsFilter.java | 35 ---------------------- .../filters/webpages/savoy/SavoyTicketsFilter.kt | 24 +++++++++++++++ 2 files changed, 24 insertions(+), 35 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyTicketsFilter.java create mode 100644 src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyTicketsFilter.kt diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyTicketsFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyTicketsFilter.java deleted file mode 100644 index 5fa2fff..0000000 --- a/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyTicketsFilter.java +++ /dev/null @@ -1,35 +0,0 @@ -package net.pterodactylus.rhynodge.filters.webpages.savoy; - -import net.pterodactylus.rhynodge.Filter; -import net.pterodactylus.rhynodge.State; -import net.pterodactylus.rhynodge.states.HtmlState; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; - -import static com.google.common.base.Preconditions.checkArgument; -import static java.util.Collections.emptySet; - -/** - * {@link Filter} implementation that creates a list of movies running at the - * Savoy theatre in Hamburg. - * - * @author David ‘Bombe’ Roden - */ -public class SavoyTicketsFilter implements Filter { - - private static final MovieExtractor movieExtractor = new MovieExtractor(); - - @NotNull - @Override - public State filter(@NotNull State state) { - checkArgument(state instanceof HtmlState, "state must be HTML"); - - HtmlState htmlState = (HtmlState) state; - Collection movies = movieExtractor.getMovies(htmlState.document()); - Logger.getLogger(SavoyTicketsFilter.class).debug("Parsed Movies: " + movies); - return new MovieState(movies, emptySet(), false); - } - -} diff --git a/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyTicketsFilter.kt b/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyTicketsFilter.kt new file mode 100644 index 0000000..10ab93c --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyTicketsFilter.kt @@ -0,0 +1,24 @@ +package net.pterodactylus.rhynodge.filters.webpages.savoy + +import net.pterodactylus.rhynodge.Filter +import net.pterodactylus.rhynodge.State +import net.pterodactylus.rhynodge.states.HtmlState +import org.apache.log4j.Logger + +/** + * [Filter] implementation that creates a list of movies running at the + * Savoy theatre in Hamburg. + */ +class SavoyTicketsFilter : Filter { + + override fun filter(state: State) = + requireNotNull(state as? HtmlState) { "state must be HTML" } + .document() + .let(movieExtractor::getMovies) + .also { logger.debug("Parsed Movies: $it") } + .let { MovieState(it, emptySet(), false) } + +} + +private val logger = Logger.getLogger(SavoyTicketsFilter::class.java) +private val movieExtractor = MovieExtractor() -- 2.7.4