🚧 Make Movie and Performance JSON-serializable
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / filters / webpages / savoy / Movie.java
1 package net.pterodactylus.rhynodge.filters.webpages.savoy;
2
3 import com.fasterxml.jackson.annotation.JsonProperty;
4
5 import java.util.ArrayList;
6 import java.util.List;
7 import java.util.Objects;
8 import java.util.stream.Collectors;
9
10 import static java.lang.String.format;
11
12 /**
13  * Information about a movie.
14  *
15  * @author <a href="mailto:bombe@pterodactylus.net">David â€˜Bombe’ Roden</a>
16  */
17 public class Movie {
18
19         @JsonProperty
20         private final String name;
21
22         @JsonProperty
23         private final List<Performance> performances = new ArrayList<>();
24
25         public Movie() {
26                 this("");
27         }
28
29         public Movie(String name) {
30                 this.name = name;
31         }
32
33         public String getName() {
34                 return name;
35         }
36
37         public List<Performance> getPerformances() {
38                 return performances;
39         }
40
41         public void addPerformance(Performance performance) {
42                 performances.add(performance);
43         }
44
45         @Override
46         public String toString() {
47                 return format("%s (%s)", name, performances.stream().map(link -> String.format("%s: %s", link.getTime(), link.getLink())).collect(Collectors.joining(", ")));
48         }
49
50         @Override
51         public int hashCode() {
52                 return Objects.hash(name, performances);
53         }
54
55         @Override
56         public boolean equals(Object o) {
57                 if (this == o) return true;
58                 if (o == null || getClass() != o.getClass()) return false;
59                 Movie movie = (Movie) o;
60                 return Objects.equals(name, movie.name) && Objects.equals(performances, movie.performances);
61         }
62
63 }