From 23c8601ac67d04ab39badf47d2c365e0f733ca70 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 12 Feb 2024 21:28:49 +0100 Subject: [PATCH] =?utf8?q?=E2=99=BB=EF=B8=8F=20Rename=20=E2=80=9CTicketLin?= =?utf8?q?k=E2=80=9D=20to=20=E2=80=9CPerformance=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../rhynodge/filters/webpages/savoy/Movie.java | 14 +++++----- .../filters/webpages/savoy/Performance.java | 29 ++++++++++++++++++++ .../filters/webpages/savoy/SavoyTicketsFilter.java | 26 +++++++++--------- .../filters/webpages/savoy/TicketLink.java | 31 ---------------------- .../filters/webpages/savoy/MovieExtractor.kt | 4 +-- .../filters/webpages/savoy/MovieExtractorTest.java | 22 +++++++-------- 6 files changed, 62 insertions(+), 64 deletions(-) create mode 100644 src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Performance.java delete mode 100644 src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/TicketLink.java 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 index 562c392..42480f9 100644 --- a/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.java +++ b/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.java @@ -16,9 +16,9 @@ import java.util.stream.Collectors; public class Movie { private final String name; - private final List ticketLinks = new ArrayList<>(); + private final List performances = new ArrayList<>(); - public static final Predicate withPresentations = movie -> !movie.getTicketLinks().isEmpty(); + public static final Predicate withPerformances = movie -> !movie.getPerformances().isEmpty(); public static final Comparator byName = (leftMovie, rightMovie) -> leftMovie.getName().compareToIgnoreCase(rightMovie.getName()); public Movie(String name) { @@ -29,17 +29,17 @@ public class Movie { return name; } - public List getTicketLinks() { - return ticketLinks; + public List getPerformances() { + return performances; } - public void addTicketLink(TicketLink ticketLink) { - ticketLinks.add(ticketLink); + public void addPerformance(Performance performance) { + performances.add(performance); } @Override public String toString() { - return format("%s (%s)", name, ticketLinks.stream().map(link -> String.format("%s: %s", link.getPresentationTime(), link.getLink())).collect(Collectors.joining(", "))); + return format("%s (%s)", name, performances.stream().map(link -> String.format("%s: %s", link.getTime(), link.getLink())).collect(Collectors.joining(", "))); } } diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Performance.java b/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Performance.java new file mode 100644 index 0000000..4585e6e --- /dev/null +++ b/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Performance.java @@ -0,0 +1,29 @@ +package net.pterodactylus.rhynodge.filters.webpages.savoy; + +import java.time.LocalDateTime; +import java.util.Comparator; + +/** + * Information about a performance and a link to buy a ticket. + */ +public class Performance { + + private final LocalDateTime time; + private final String link; + + public static final Comparator byTime = (leftPerformance, rightPerformance) -> leftPerformance.getTime().compareTo(rightPerformance.getTime()); + + public Performance(LocalDateTime time, String link) { + this.time = time; + this.link = link; + } + + public LocalDateTime getTime() { + return time; + } + + public String getLink() { + return link; + } + +} 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 index 8f2fc74..cf32c1c 100644 --- a/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyTicketsFilter.java +++ b/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyTicketsFilter.java @@ -5,8 +5,8 @@ import static java.time.format.DateTimeFormatter.ofPattern; import static java.util.Optional.empty; import static java.util.Optional.of; import static net.pterodactylus.rhynodge.filters.webpages.savoy.Movie.byName; -import static net.pterodactylus.rhynodge.filters.webpages.savoy.Movie.withPresentations; -import static net.pterodactylus.rhynodge.filters.webpages.savoy.TicketLink.byPresentationTime; +import static net.pterodactylus.rhynodge.filters.webpages.savoy.Movie.withPerformances; +import static net.pterodactylus.rhynodge.filters.webpages.savoy.Performance.byTime; import static org.jsoup.nodes.Document.createShell; import static org.jsoup.parser.Tag.valueOf; @@ -57,15 +57,15 @@ public class SavoyTicketsFilter implements Filter { document.head().appendElement("style").attr("type", "text/css").text(generateStyleSheet()); document.body().appendElement("h1").text("Kinoprogramm: Savoy"); document.body().appendElement("h2").text("Filme"); - movies.stream().filter(withPresentations).sorted(byName).forEach(movie -> { + movies.stream().filter(withPerformances).sorted(byName).forEach(movie -> { document.body().appendChild(createMovieNode(movie)); }); document.body().appendElement("h2").text("Zeiten"); - movies.stream().flatMap(movie -> movie.getTicketLinks().stream().map(ticketLink -> new Presentation(movie, ticketLink))).sorted((leftPresentation, rightPresentation) -> leftPresentation.getTicketLink().getPresentationTime().compareTo(rightPresentation.getTicketLink().getPresentationTime())).collect(Collectors.groupingBy(presentation -> presentation.getTicketLink().getPresentationTime().toLocalDate())).entrySet().stream().sorted((leftEntry, rightEntry) -> leftEntry.getKey().compareTo(rightEntry.getKey())).forEach(dateEntry -> { + movies.stream().flatMap(movie -> movie.getPerformances().stream().map(performance -> new Presentation(movie, performance))).sorted((leftPresentation, rightPresentation) -> leftPresentation.getTicketLink().getTime().compareTo(rightPresentation.getTicketLink().getTime())).collect(Collectors.groupingBy(presentation -> presentation.getTicketLink().getTime().toLocalDate())).entrySet().stream().sorted((leftEntry, rightEntry) -> leftEntry.getKey().compareTo(rightEntry.getKey())).forEach(dateEntry -> { document.body().appendChild(createDayNode(dateEntry.getKey(), dateEntry.getValue())); }); document.body().appendElement("h2").text("Vorschau"); - movies.stream().filter(withPresentations.negate()).sorted(byName).forEach(movie -> { + movies.stream().filter(withPerformances.negate()).sorted(byName).forEach(movie -> { document.body().appendElement("div").attr("class", "name").text(movie.getName()); }); return of(document.toString()); @@ -85,9 +85,9 @@ public class SavoyTicketsFilter implements Filter { Element movieNode = new Element(valueOf("div"), ""); movieNode.attr("class", "movie"); movieNode.appendElement("div").attr("class", "name").text(movie.getName()); - movie.getTicketLinks().stream().sorted(byPresentationTime).forEach(ticketLink -> { + movie.getPerformances().stream().sorted(byTime).forEach(performance -> { Element presentationNode = movieNode.appendElement("div").attr("class", "presentation"); - presentationNode.appendElement("div").attr("class", "time").text("» ").appendElement("a").attr("href", ticketLink.getLink()).text(ticketLink.getPresentationTime().format(dateTimeFormatter)); + presentationNode.appendElement("div").attr("class", "time").text("» ").appendElement("a").attr("href", performance.getLink()).text(performance.getTime().format(dateTimeFormatter)); }); return movieNode; } @@ -97,7 +97,7 @@ public class SavoyTicketsFilter implements Filter { dayNode.appendElement("div").attr("class", "date").text(date.format(dateFormatter)); presentations.stream().forEach(presentation -> { Element presentationNode = dayNode.appendElement("div").attr("class", "presentation"); - presentationNode.appendElement("div").attr("class", "time").text("» " + presentation.getTicketLink().getPresentationTime().format(timeFormatter)); + presentationNode.appendElement("div").attr("class", "time").text("» " + presentation.getTicketLink().getTime().format(timeFormatter)); presentationNode.appendElement("div").attr("class", "movie").appendElement("a").attr("href", presentation.getTicketLink().getLink()).text(presentation.getMovie().getName()); }); return dayNode; @@ -110,19 +110,19 @@ public class SavoyTicketsFilter implements Filter { private static class Presentation { private final Movie movie; - private final TicketLink ticketLink; + private final Performance performance; - private Presentation(Movie movie, TicketLink ticketLink) { + private Presentation(Movie movie, Performance performance) { this.movie = movie; - this.ticketLink = ticketLink; + this.performance = performance; } private Movie getMovie() { return movie; } - private TicketLink getTicketLink() { - return ticketLink; + private Performance getTicketLink() { + return performance; } } diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/TicketLink.java b/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/TicketLink.java deleted file mode 100644 index 357245f..0000000 --- a/src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/TicketLink.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.pterodactylus.rhynodge.filters.webpages.savoy; - -import java.time.LocalDateTime; -import java.util.Comparator; - -/** - * Information about a presentation and a link to buy a ticket. - * - * @author David ‘Bombe’ Roden - */ -public class TicketLink { - - private final LocalDateTime presentationTime; - private final String ticketLink; - - public static final Comparator byPresentationTime = (leftTicketLink, rightTicketLink) -> leftTicketLink.getPresentationTime().compareTo(rightTicketLink.getPresentationTime()); - - public TicketLink(LocalDateTime presentationTime, String ticketLink) { - this.presentationTime = presentationTime; - this.ticketLink = ticketLink; - } - - public LocalDateTime getPresentationTime() { - return presentationTime; - } - - public String getLink() { - return ticketLink; - } - -} diff --git a/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/MovieExtractor.kt b/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/MovieExtractor.kt index a49c280..d828ec8 100644 --- a/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/MovieExtractor.kt +++ b/src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/MovieExtractor.kt @@ -31,9 +31,9 @@ class MovieExtractor { val begin = LocalDateTime.parse(performance.get("begin").asText(), dateFormat) val slug = performance.get("slug").asText() val link = "https://savoy.premiumkino.de/vorstellung/${slug}/${String.format("%tY% ticketLinks = new ArrayList<>(movie.getTicketLinks()); - if (ticketLinks.size() != presentationTimesAndLinks.length) { - mismatchDescription.appendText("has ").appendValue(ticketLinks.size()).appendText(" presentations"); + List performances = new ArrayList<>(movie.getPerformances()); + if (performances.size() != presentationTimesAndLinks.length) { + mismatchDescription.appendText("has ").appendValue(performances.size()).appendText(" presentations"); return false; } for (Pair presentationTimeAndLink : presentationTimesAndLinks) { - Optional foundTicketLink = empty(); - for (TicketLink ticketLink : ticketLinks) { - if (ticketLink.getPresentationTime().equals(presentationTimeAndLink.getFirst()) && ticketLink.getLink().equals(presentationTimeAndLink.getSecond())) { - foundTicketLink = Optional.of(ticketLink); + Optional foundLink = empty(); + for (Performance performance : performances) { + if (performance.getTime().equals(presentationTimeAndLink.getFirst()) && performance.getLink().equals(presentationTimeAndLink.getSecond())) { + foundLink = Optional.of(performance); break; } } - if (!foundTicketLink.isPresent()) { + if (!foundLink.isPresent()) { mismatchDescription.appendValue("has no presentation at ").appendValue(presentationTimeAndLink.getFirst()); return false; } - ticketLinks.remove(foundTicketLink.get()); + performances.remove(foundLink.get()); } - if (!ticketLinks.isEmpty()) { - mismatchDescription.appendText("has no presentations at ").appendValueList("", ", ", "", ticketLinks); + if (!performances.isEmpty()) { + mismatchDescription.appendText("has no presentations at ").appendValueList("", ", ", "", performances); return false; } return true; -- 2.7.4