5e831d8f68206c9d9291f580b62cb16633f893f6
[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 String imageUrl;
24
25         @JsonProperty
26         private final List<Performance> performances = new ArrayList<>();
27
28         public Movie() {
29                 this("", "");
30         }
31
32         public Movie(String name, String imageUrl) {
33                 this.name = name;
34                 this.imageUrl = imageUrl;
35         }
36
37         public String getName() {
38                 return name;
39         }
40
41         public String getImageUrl() {
42                 return imageUrl;
43         }
44
45         public List<Performance> getPerformances() {
46                 return performances;
47         }
48
49         public void addPerformance(Performance performance) {
50                 performances.add(performance);
51         }
52
53         @Override
54         public String toString() {
55                 return format("%s (%s, %s)", name, imageUrl, performances.stream().map(link -> String.format("%s: %s", link.getTime(), link.getLink())).collect(Collectors.joining(", ")));
56         }
57
58         @Override
59         public int hashCode() {
60                 return Objects.hash(name, imageUrl, performances);
61         }
62
63         @Override
64         public boolean equals(Object o) {
65                 if (this == o) return true;
66                 if (o == null || getClass() != o.getClass()) return false;
67                 Movie movie = (Movie) o;
68                 return Objects.equals(name, movie.name) && Objects.equals(imageUrl, movie.imageUrl) && Objects.equals(performances, movie.performances);
69         }
70
71 }