🎨 Replace QC filter with Kotlin version
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / states / ComicState.java
1 /*
2  * rhynodge - ComicState.java - Copyright Â© 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.rhynodge.states;
19
20 import java.util.Iterator;
21 import java.util.List;
22
23 import net.pterodactylus.rhynodge.states.ComicState.Comic;
24
25 import com.fasterxml.jackson.annotation.JsonProperty;
26 import com.google.common.collect.Lists;
27
28 /**
29  * {@link net.pterodactylus.rhynodge.State} that can store an arbitrary amout of
30  * {@link Comic}s.
31  *
32  * @author <a href="mailto:bombe@pterodactylus.net">David â€˜Bombe’ Roden</a>
33  */
34 public class ComicState extends AbstractState implements Iterable<Comic> {
35
36         @JsonProperty
37         private final List<Comic> comics = Lists.newArrayList();
38
39         @Override
40         public boolean isEmpty() {
41                 return comics.isEmpty();
42         }
43
44         public List<Comic> comics() {
45                 return comics;
46         }
47
48         public ComicState add(Comic comic) {
49                 comics.add(comic);
50                 return this;
51         }
52
53         @Override
54         public Iterator<Comic> iterator() {
55                 return comics.iterator();
56         }
57
58         @Override
59         public String toString() {
60                 return String.format("ComicState[comics=%s]", comics());
61         }
62
63         /**
64          * Defines a comic.
65          *
66          * @author <a href="mailto:bombe@pterodactylus.net">David â€˜Bombe’ Roden</a>
67          */
68         public static class Comic implements Iterable<Strip> {
69
70                 @JsonProperty
71                 private final String title;
72
73                 @JsonProperty
74                 private final List<Strip> strips = Lists.newArrayList();
75
76                 public Comic(@JsonProperty("title") String title) {
77                         this.title = title;
78                 }
79
80                 public String title() {
81                         return title;
82                 }
83
84                 public List<Strip> strips() {
85                         return strips;
86                 }
87
88                 public Comic add(Strip strip) {
89                         strips.add(strip);
90                         return this;
91                 }
92
93                 @Override
94                 public Iterator<Strip> iterator() {
95                         return strips.iterator();
96                 }
97
98                 @Override
99                 public int hashCode() {
100                         return title.hashCode() ^ strips().hashCode();
101                 }
102
103                 @Override
104                 public boolean equals(Object object) {
105                         if (!(object instanceof Comic)) {
106                                 return false;
107                         }
108                         Comic comic = (Comic) object;
109                         return title().equals(comic.title()) && strips().equals(comic.strips());
110                 }
111
112                 @Override
113                 public String toString() {
114                         return String.format("Comic[title=%s,strips=%s]", title(), strips());
115                 }
116
117         }
118
119         /**
120          * A strip is a single image that belongs to a comic.
121          *
122          * @author <a href="mailto:bombe@pterodactylus.net">David â€˜Bombe’ Roden</a>
123          */
124         public static class Strip {
125
126                 @JsonProperty
127                 private final String imageUrl;
128
129                 @JsonProperty
130                 private final String comment;
131
132                 public Strip(@JsonProperty("imageUrl") String imageUrl, @JsonProperty("comment") String comment) {
133                         this.imageUrl = imageUrl;
134                         this.comment = comment;
135                 }
136
137                 public String imageUrl() {
138                         return imageUrl;
139                 }
140
141                 public String comment() {
142                         return comment;
143                 }
144
145                 @Override
146                 public int hashCode() {
147                         return imageUrl().hashCode() ^ comment().hashCode();
148                 }
149
150                 @Override
151                 public boolean equals(Object object) {
152                         if (!(object instanceof Strip)) {
153                                 return false;
154                         }
155                         Strip strip = (Strip) object;
156                         return imageUrl().equals(strip.imageUrl()) && comment().equals(strip.comment());
157                 }
158
159                 @Override
160                 public String toString() {
161                         return String.format("Strip[imageUrl=%s,comment=%s]", imageUrl(), comment());
162                 }
163
164         }
165
166 }