projects
/
rhynodge.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
d176fca
)
🚧 Make Movie and Performance JSON-serializable
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Sat, 24 Feb 2024 22:19:32 +0000
(23:19 +0100)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Sat, 24 Feb 2024 22:19:32 +0000
(23:19 +0100)
src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Performance.java
patch
|
blob
|
history
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
42480f9
..
0844b7c
100644
(file)
--- a/
src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.java
+++ b/
src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Movie.java
@@
-1,13
+1,14
@@
package net.pterodactylus.rhynodge.filters.webpages.savoy;
package net.pterodactylus.rhynodge.filters.webpages.savoy;
-import
static java.lang.String.format
;
+import
com.fasterxml.jackson.annotation.JsonProperty
;
import java.util.ArrayList;
import java.util.ArrayList;
-import java.util.Comparator;
import java.util.List;
import java.util.List;
-import java.util.
function.Predicate
;
+import java.util.
Objects
;
import java.util.stream.Collectors;
import java.util.stream.Collectors;
+import static java.lang.String.format;
+
/**
* Information about a movie.
*
/**
* Information about a movie.
*
@@
-15,11
+16,15
@@
import java.util.stream.Collectors;
*/
public class Movie {
*/
public class Movie {
+ @JsonProperty
private final String name;
private final String name;
+
+ @JsonProperty
private final List<Performance> performances = new ArrayList<>();
private final List<Performance> performances = new ArrayList<>();
- 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() {
+ this("");
+ }
public Movie(String name) {
this.name = name;
public Movie(String name) {
this.name = name;
@@
-42,4
+47,17
@@
public class Movie {
return format("%s (%s)", name, performances.stream().map(link -> String.format("%s: %s", link.getTime(), 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(", ")));
}
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, 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(performances, movie.performances);
+ }
+
}
}
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
index
4585e6e
..
c50dd31
100644
(file)
--- a/
src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Performance.java
+++ b/
src/main/java/net/pterodactylus/rhynodge/filters/webpages/savoy/Performance.java
@@
-1,17
+1,24
@@
package net.pterodactylus.rhynodge.filters.webpages.savoy;
package net.pterodactylus.rhynodge.filters.webpages.savoy;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
import java.time.LocalDateTime;
import java.time.LocalDateTime;
-import java.util.
Comparator
;
+import java.util.
Objects
;
/**
* Information about a performance and a link to buy a ticket.
*/
public class Performance {
/**
* Information about a performance and a link to buy a ticket.
*/
public class Performance {
+ @JsonProperty
private final LocalDateTime time;
private final LocalDateTime time;
+
+ @JsonProperty
private final String link;
private final String link;
- public static final Comparator<Performance> byTime = (leftPerformance, rightPerformance) -> leftPerformance.getTime().compareTo(rightPerformance.getTime());
+ public Performance() {
+ this(null, null);
+ }
public Performance(LocalDateTime time, String link) {
this.time = time;
public Performance(LocalDateTime time, String link) {
this.time = time;
@@
-26,4
+33,17
@@
public class Performance {
return link;
}
return link;
}
+ @Override
+ public int hashCode() {
+ return Objects.hash(time, link);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Performance that = (Performance) o;
+ return Objects.equals(time, that.time) && Objects.equals(link, that.link);
+ }
+
}
}