♻️ Rename “TicketLink” to “Performance”
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 12 Feb 2024 20:28:49 +0000 (21:28 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 12 Feb 2024 20:28:49 +0000 (21:28 +0100)
src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.java
src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Performance.java [new file with mode: 0644]
src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/SavoyTicketsFilter.java
src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/TicketLink.java [deleted file]
src/main/kotlin/net/pterodactylus/rhynodge/filters/webpages/savoy/MovieExtractor.kt
src/test/java/net/pterodactylus/rhynodge/filters/webpages/savoy/MovieExtractorTest.java

index 562c392..42480f9 100644 (file)
@@ -16,9 +16,9 @@ import java.util.stream.Collectors;
 public class Movie {
 
        private final String name;
-       private final List<TicketLink> ticketLinks = new ArrayList<>();
+       private final List<Performance> performances = new ArrayList<>();
 
-       public static final Predicate<Movie> withPresentations = movie -> !movie.getTicketLinks().isEmpty();
+       public static final Predicate<Movie> withPerformances = movie -> !movie.getPerformances().isEmpty();
        public static final Comparator<Movie> byName = (leftMovie, rightMovie) -> leftMovie.getName().compareToIgnoreCase(rightMovie.getName());
 
        public Movie(String name) {
@@ -29,17 +29,17 @@ public class Movie {
                return name;
        }
 
-       public List<TicketLink> getTicketLinks() {
-               return ticketLinks;
+       public List<Performance> 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 (file)
index 0000000..4585e6e
--- /dev/null
@@ -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<Performance> 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;
+       }
+
+}
index 8f2fc74..cf32c1c 100644 (file)
@@ -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.<Presentation, LocalDate>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.<Presentation, LocalDate>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 (file)
index 357245f..0000000
+++ /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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class TicketLink {
-
-       private final LocalDateTime presentationTime;
-       private final String ticketLink;
-
-       public static final Comparator<TicketLink> 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;
-       }
-
-}
index a49c280..d828ec8 100644 (file)
@@ -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%<tm%<td", begin)}/${String.format("%tH%<tM", begin)}/${performance.get("crypt_id").asText()}"
-                               TicketLink(begin, link)
+                               Performance(begin, link)
                        }
-                       .forEach(this::addTicketLink)
+                       .forEach(this::addPerformance)
        }
 
 }
index 50d8884..964b304 100644 (file)
@@ -155,27 +155,27 @@ public class MovieExtractorTest {
                                        mismatchDescription.appendText("movie is named ").appendValue(movie.getName());
                                        return false;
                                }
-                               List<TicketLink> ticketLinks = new ArrayList<>(movie.getTicketLinks());
-                               if (ticketLinks.size() != presentationTimesAndLinks.length) {
-                                       mismatchDescription.appendText("has ").appendValue(ticketLinks.size()).appendText(" presentations");
+                               List<Performance> performances = new ArrayList<>(movie.getPerformances());
+                               if (performances.size() != presentationTimesAndLinks.length) {
+                                       mismatchDescription.appendText("has ").appendValue(performances.size()).appendText(" presentations");
                                        return false;
                                }
                                for (Pair<LocalDateTime, String> presentationTimeAndLink : presentationTimesAndLinks) {
-                                       Optional<TicketLink> foundTicketLink = empty();
-                                       for (TicketLink ticketLink : ticketLinks) {
-                                               if (ticketLink.getPresentationTime().equals(presentationTimeAndLink.getFirst()) && ticketLink.getLink().equals(presentationTimeAndLink.getSecond())) {
-                                                       foundTicketLink = Optional.of(ticketLink);
+                                       Optional<Performance> 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;