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();
40 public boolean isEmpty() {
41 return comics.isEmpty();
44 public List<Comic> comics() {
48 public ComicState add(Comic comic) {
54 public Iterator<Comic> iterator() {
55 return comics.iterator();
59 public String toString() {
60 return String.format("ComicState[comics=%s]", comics());
66 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
68 public static class Comic implements Iterable<Strip> {
71 private final String title;
74 private final List<Strip> strips = Lists.newArrayList();
76 public Comic(@JsonProperty("title") String title) {
80 public String title() {
84 public List<Strip> strips() {
88 public Comic add(Strip strip) {
94 public Iterator<Strip> iterator() {
95 return strips.iterator();
99 public int hashCode() {
100 return title.hashCode() ^ strips().hashCode();
104 public boolean equals(Object object) {
105 if (!(object instanceof Comic)) {
108 Comic comic = (Comic) object;
109 return title().equals(comic.title()) && strips().equals(comic.strips());
113 public String toString() {
114 return String.format("Comic[title=%s,strips=%s]", title(), strips());
120 * A strip is a single image that belongs to a comic.
122 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
124 public static class Strip {
127 private final String imageUrl;
130 private final String comment;
132 public Strip(@JsonProperty("imageUrl") String imageUrl, @JsonProperty("comment") String comment) {
133 this.imageUrl = imageUrl;
134 this.comment = comment;
137 public String imageUrl() {
141 public String comment() {
146 public int hashCode() {
147 return imageUrl().hashCode() ^ comment().hashCode();
151 public boolean equals(Object object) {
152 if (!(object instanceof Strip)) {
155 Strip strip = (Strip) object;
156 return imageUrl().equals(strip.imageUrl()) && comment().equals(strip.comment());
160 public String toString() {
161 return String.format("Strip[imageUrl=%s,comment=%s]", imageUrl(), comment());