2 * rhynodge - ComicState.java - Copyright © 2013 David Roden
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.
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.
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/>.
18 package net.pterodactylus.rhynodge.states;
20 import java.util.Iterator;
21 import java.util.List;
23 import net.pterodactylus.rhynodge.states.ComicState.Comic;
25 import com.fasterxml.jackson.annotation.JsonProperty;
26 import com.google.common.collect.Lists;
29 * {@link net.pterodactylus.rhynodge.State} that can store an arbitrary amout of
32 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34 public class ComicState extends AbstractState implements Iterable<Comic> {
37 private final List<Comic> comics = Lists.newArrayList();
39 public List<Comic> comics() {
43 public ComicState add(Comic comic) {
49 public Iterator<Comic> iterator() {
50 return comics.iterator();
54 public String toString() {
55 return String.format("ComicState[comics=%s]", comics());
61 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
63 public static class Comic implements Iterable<Strip> {
66 private final String title;
69 private final List<Strip> strips = Lists.newArrayList();
71 public Comic(@JsonProperty("title") String title) {
75 public String title() {
79 public List<Strip> strips() {
83 public Comic add(Strip strip) {
89 public Iterator<Strip> iterator() {
90 return strips.iterator();
94 public int hashCode() {
95 return title.hashCode() ^ strips().hashCode();
99 public boolean equals(Object object) {
100 if (!(object instanceof Comic)) {
103 Comic comic = (Comic) object;
104 return title().equals(comic.title()) && strips().equals(comic.strips());
108 public String toString() {
109 return String.format("Comic[title=%s,strips=%s]", title(), strips());
115 * A strip is a single image that belongs to a comic.
117 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
119 public static class Strip {
122 private final String imageUrl;
125 private final String comment;
127 public Strip(@JsonProperty("imageUrl") String imageUrl, @JsonProperty("comment") String comment) {
128 this.imageUrl = imageUrl;
129 this.comment = comment;
132 public String imageUrl() {
136 public String comment() {
141 public int hashCode() {
142 return imageUrl().hashCode() ^ comment().hashCode();
146 public boolean equals(Object object) {
147 if (!(object instanceof Strip)) {
150 Strip strip = (Strip) object;
151 return imageUrl().equals(strip.imageUrl()) && comment().equals(strip.comment());
155 public String toString() {
156 return String.format("Strip[imageUrl=%s,comment=%s]", imageUrl(), comment());