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.google.common.collect.Lists;
28 * {@link net.pterodactylus.rhynodge.State} that can store an arbitrary amout of
31 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33 public class ComicState extends AbstractState implements Iterable<Comic> {
35 /** The comics in this state. */
36 private List<Comic> comics = Lists.newArrayList();
39 * Returns the list of comics contained in this state.
41 * @return The list of comics in this state
43 public List<Comic> comics() {
48 * Adds the given comic to this state.
52 * @return This comic state
54 public ComicState add(Comic comic) {
64 public Iterator<Comic> iterator() {
65 return comics.iterator();
73 public String toString() {
74 return String.format("ComicState[comics=%s]", comics());
80 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
82 public static class Comic implements Iterable<String> {
84 /** The title of the comic. */
85 private final String title;
87 /** The URLs of the comic’s images. */
88 private final List<String> imageUrls = Lists.newArrayList();
91 * Creates a new comic with the given title.
94 * The title of the comic
96 public Comic(String title) {
101 * Returns the title of this comic.
103 * @return The title of this comic
105 public String title() {
110 * Returns the URLs of this comic’s images.
112 * @return The URLs of this comic’s images
114 public List<String> imageUrls() {
119 * Adds an image URL to this comic.
122 * The URL of the comic image to add
125 public Comic addImageUrl(String imageUrl) {
126 imageUrls.add(imageUrl);
135 public Iterator<String> iterator() {
136 return imageUrls.iterator();
144 public int hashCode() {
145 return title.hashCode() ^ imageUrls().hashCode();
149 public boolean equals(Object object) {
150 if (!(object instanceof Comic)) {
153 Comic comic = (Comic) object;
154 return title().equals(comic.title()) && imageUrls().equals(comic.imageUrls());
158 public String toString() {
159 return String.format("Comic[title=%s,imageUrls=%s]", title(), imageUrls());