Remove all those useless comments
[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         public List<Comic> comics() {
40                 return comics;
41         }
42
43         public ComicState add(Comic comic) {
44                 comics.add(comic);
45                 return this;
46         }
47
48         @Override
49         public Iterator<Comic> iterator() {
50                 return comics.iterator();
51         }
52
53         @Override
54         public String toString() {
55                 return String.format("ComicState[comics=%s]", comics());
56         }
57
58         /**
59          * Defines a comic.
60          *
61          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
62          */
63         public static class Comic implements Iterable<Strip> {
64
65                 @JsonProperty
66                 private final String title;
67
68                 @JsonProperty
69                 private final List<Strip> strips = Lists.newArrayList();
70
71                 public Comic(@JsonProperty("title") String title) {
72                         this.title = title;
73                 }
74
75                 public String title() {
76                         return title;
77                 }
78
79                 public List<Strip> strips() {
80                         return strips;
81                 }
82
83                 public Comic add(Strip strip) {
84                         strips.add(strip);
85                         return this;
86                 }
87
88                 @Override
89                 public Iterator<Strip> iterator() {
90                         return strips.iterator();
91                 }
92
93                 @Override
94                 public int hashCode() {
95                         return title.hashCode() ^ strips().hashCode();
96                 }
97
98                 @Override
99                 public boolean equals(Object object) {
100                         if (!(object instanceof Comic)) {
101                                 return false;
102                         }
103                         Comic comic = (Comic) object;
104                         return title().equals(comic.title()) && strips().equals(comic.strips());
105                 }
106
107                 @Override
108                 public String toString() {
109                         return String.format("Comic[title=%s,strips=%s]", title(), strips());
110                 }
111
112         }
113
114         /**
115          * A strip is a single image that belongs to a comic.
116          *
117          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
118          */
119         public static class Strip {
120
121                 @JsonProperty
122                 private final String imageUrl;
123
124                 @JsonProperty
125                 private final String comment;
126
127                 public Strip(@JsonProperty("imageUrl") String imageUrl, @JsonProperty("comment") String comment) {
128                         this.imageUrl = imageUrl;
129                         this.comment = comment;
130                 }
131
132                 public String imageUrl() {
133                         return imageUrl;
134                 }
135
136                 public String comment() {
137                         return comment;
138                 }
139
140                 @Override
141                 public int hashCode() {
142                         return imageUrl().hashCode() ^ comment().hashCode();
143                 }
144
145                 @Override
146                 public boolean equals(Object object) {
147                         if (!(object instanceof Strip)) {
148                                 return false;
149                         }
150                         Strip strip = (Strip) object;
151                         return imageUrl().equals(strip.imageUrl()) && comment().equals(strip.comment());
152                 }
153
154                 @Override
155                 public String toString() {
156                         return String.format("Strip[imageUrl=%s,comment=%s]", imageUrl(), comment());
157                 }
158
159         }
160
161 }