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) {
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(", ")));
}
}
--- /dev/null
+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;
+ }
+
+}
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;
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());
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;
}
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;
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;
}
}
+++ /dev/null
-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;
- }
-
-}
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)
}
}
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;