import net.pterodactylus.rhynodge.states.ComicState.Comic;
+import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Lists;
/**
*/
public class ComicState extends AbstractState implements Iterable<Comic> {
- /** The comics in this state. */
+ @JsonProperty
private final List<Comic> comics = Lists.newArrayList();
- /**
- * Returns the list of comics contained in this state.
- *
- * @return The list of comics in this state
- */
+ @Override
+ public boolean isEmpty() {
+ return comics.isEmpty();
+ }
+
public List<Comic> comics() {
return comics;
}
- /**
- * Adds the given comic to this state.
- *
- * @param comic
- * The comic to add
- * @return This comic state
- */
public ComicState add(Comic comic) {
comics.add(comic);
return this;
}
- //
- // ITERABLE METHODS
- //
-
@Override
public Iterator<Comic> iterator() {
return comics.iterator();
}
- //
- // OBJECT METHODS
- //
-
@Override
public String toString() {
return String.format("ComicState[comics=%s]", comics());
*
* @author <a href="mailto:bombe@pterodactylus.net">David āBombeā Roden</a>
*/
- public static class Comic implements Iterable<String> {
+ public static class Comic implements Iterable<Strip> {
- /** The title of the comic. */
+ @JsonProperty
private final String title;
- /** The URLs of the comicās images. */
- private final List<String> imageUrls = Lists.newArrayList();
+ @JsonProperty
+ private final List<Strip> strips = Lists.newArrayList();
- /**
- * Creates a new comic with the given title.
- *
- * @param title
- * The title of the comic
- */
- public Comic(String title) {
+ public Comic(@JsonProperty("title") String title) {
this.title = title;
}
- /**
- * Returns the title of this comic.
- *
- * @return The title of this comic
- */
public String title() {
return title;
}
- /**
- * Returns the URLs of this comicās images.
- *
- * @return The URLs of this comicās images
- */
- public List<String> imageUrls() {
- return imageUrls;
+ public List<Strip> strips() {
+ return strips;
}
- /**
- * Adds an image URL to this comic.
- *
- * @param imageUrl
- * The URL of the comic image to add
- * @return This comic
- */
- public Comic addImageUrl(String imageUrl) {
- imageUrls.add(imageUrl);
+ public Comic add(Strip strip) {
+ strips.add(strip);
return this;
}
- //
- // ITERABLE METHODS
- //
-
@Override
- public Iterator<String> iterator() {
- return imageUrls.iterator();
+ public Iterator<Strip> iterator() {
+ return strips.iterator();
}
- //
- // OBJECT METHODS
- //
-
@Override
public int hashCode() {
- return title.hashCode() ^ imageUrls().hashCode();
+ return title.hashCode() ^ strips().hashCode();
}
@Override
return false;
}
Comic comic = (Comic) object;
- return title().equals(comic.title()) && imageUrls().equals(comic.imageUrls());
+ return title().equals(comic.title()) && strips().equals(comic.strips());
+ }
+
+ @Override
+ public String toString() {
+ return String.format("Comic[title=%s,strips=%s]", title(), strips());
+ }
+
+ }
+
+ /**
+ * A strip is a single image that belongs to a comic.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David āBombeā Roden</a>
+ */
+ public static class Strip {
+
+ @JsonProperty
+ private final String imageUrl;
+
+ @JsonProperty
+ private final String comment;
+
+ public Strip(@JsonProperty("imageUrl") String imageUrl, @JsonProperty("comment") String comment) {
+ this.imageUrl = imageUrl;
+ this.comment = comment;
+ }
+
+ public String imageUrl() {
+ return imageUrl;
+ }
+
+ public String comment() {
+ return comment;
+ }
+
+ @Override
+ public int hashCode() {
+ return imageUrl().hashCode() ^ comment().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (!(object instanceof Strip)) {
+ return false;
+ }
+ Strip strip = (Strip) object;
+ return imageUrl().equals(strip.imageUrl()) && comment().equals(strip.comment());
}
@Override
public String toString() {
- return String.format("Comic[title=%s,imageUrls=%s]", title(), imageUrls());
+ return String.format("Strip[imageUrl=%s,comment=%s]", imageUrl(), comment());
}
}