♻️ Remove “addPerformance” method
[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.Collection;
7 import java.util.List;
8 import java.util.Objects;
9 import java.util.stream.Collectors;
10
11 import static java.lang.String.format;
12 import static java.util.Collections.emptyList;
13
14 /**
15  * Information about a movie.
16  *
17  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
18  */
19 public class Movie {
20
21         @JsonProperty
22         private final String name;
23
24         @JsonProperty
25         private final String imageUrl;
26
27         @JsonProperty
28         private final String description;
29
30         @JsonProperty
31         private final List<Performance> performances = new ArrayList<>();
32
33         public Movie() {
34                 this("", "", "");
35         }
36
37         public Movie(String name, String imageUrl) {
38                 this(name, imageUrl, "");
39         }
40
41         public Movie(String name, String imageUrl, String description) {
42                 this(name, imageUrl, description, emptyList());
43         }
44
45         public Movie(String name, String imageUrl, String description, Collection<Performance> performances) {
46                 this.name = name;
47                 this.imageUrl = imageUrl;
48                 this.description = description;
49                 this.performances.addAll(performances);
50         }
51
52         public String getName() {
53                 return name;
54         }
55
56         public String getImageUrl() {
57                 return imageUrl;
58         }
59
60         public String getDescription() {
61                 return description;
62         }
63
64         public List<Performance> getPerformances() {
65                 return performances;
66         }
67
68         @Override
69         public String toString() {
70                 return format("%s (%s, %s, %s)", name, imageUrl, description, performances.stream().map(link -> String.format("%s: %s", link.getTime(), link.getLink())).collect(Collectors.joining(", ")));
71         }
72
73         @Override
74         public int hashCode() {
75                 return Objects.hash(name, imageUrl, description, performances);
76         }
77
78         @Override
79         public boolean equals(Object o) {
80                 if (this == o) return true;
81                 if (o == null || getClass() != o.getClass()) return false;
82                 Movie movie = (Movie) o;
83                 return Objects.equals(name, movie.name) && Objects.equals(imageUrl, movie.imageUrl) && Objects.equals(description, movie.description) && Objects.equals(performances, movie.performances);
84         }
85
86 }