X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Frhynodge%2Fstates%2FComicState.java;h=ffc38b56221d87dc35ed7b4bec028889bb1042fd;hb=4fea375ff20fbbbaaad6feba574d4b6c6380ed93;hp=89f1cdcdd27c21733b8004272e31bfc68f6829f6;hpb=408cc963020f3cfc4d994a84f5109b914759399c;p=rhynodge.git diff --git a/src/main/java/net/pterodactylus/rhynodge/states/ComicState.java b/src/main/java/net/pterodactylus/rhynodge/states/ComicState.java index 89f1cdc..ffc38b5 100644 --- a/src/main/java/net/pterodactylus/rhynodge/states/ComicState.java +++ b/src/main/java/net/pterodactylus/rhynodge/states/ComicState.java @@ -22,6 +22,7 @@ import java.util.List; import net.pterodactylus.rhynodge.states.ComicState.Comic; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.Lists; /** @@ -33,6 +34,7 @@ import com.google.common.collect.Lists; public class ComicState extends AbstractState implements Iterable { /** The comics in this state. */ + @JsonProperty private final List comics = Lists.newArrayList(); /** @@ -79,13 +81,15 @@ public class ComicState extends AbstractState implements Iterable { * * @author David ‘Bombe’ Roden */ - public static class Comic implements Iterable { + public static class Comic implements Iterable { /** The title of the comic. */ + @JsonProperty private final String title; - /** The URLs of the comic’s images. */ - private final List imageUrls = Lists.newArrayList(); + /** The strips of the comic. */ + @JsonProperty + private final List strips = Lists.newArrayList(); /** * Creates a new comic with the given title. @@ -93,7 +97,7 @@ public class ComicState extends AbstractState implements Iterable { * @param title * The title of the comic */ - public Comic(String title) { + public Comic(@JsonProperty("title") String title) { this.title = title; } @@ -107,23 +111,23 @@ public class ComicState extends AbstractState implements Iterable { } /** - * Returns the URLs of this comic’s images. + * Returns the strips of this comic. * - * @return The URLs of this comic’s images + * @return The strips of this comic */ - public List imageUrls() { - return imageUrls; + public List strips() { + return strips; } /** - * Adds an image URL to this comic. + * Adds a strip to this comic. * - * @param imageUrl - * The URL of the comic image to add + * @param strip + * The strip to add * @return This comic */ - public Comic addImageUrl(String imageUrl) { - imageUrls.add(imageUrl); + public Comic add(Strip strip) { + strips.add(strip); return this; } @@ -132,8 +136,8 @@ public class ComicState extends AbstractState implements Iterable { // @Override - public Iterator iterator() { - return imageUrls.iterator(); + public Iterator iterator() { + return strips.iterator(); } // @@ -142,7 +146,7 @@ public class ComicState extends AbstractState implements Iterable { @Override public int hashCode() { - return title.hashCode() ^ imageUrls().hashCode(); + return title.hashCode() ^ strips().hashCode(); } @Override @@ -151,12 +155,83 @@ public class ComicState extends AbstractState implements Iterable { 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 David ‘Bombe’ Roden + */ + public static class Strip { + + /** The URL of the image. */ + @JsonProperty + private final String imageUrl; + + /** The comment of the image. */ + @JsonProperty + private final String comment; + + /** + * Creates a new strip. + * + * @param imageUrl + * The URL of the image + * @param comment + * The comment of the image + */ + public Strip(@JsonProperty("imageUrl") String imageUrl, @JsonProperty("comment") String comment) { + this.imageUrl = imageUrl; + this.comment = comment; + } + + /** + * Returns the URL of the image. + * + * @return The URL of the image + */ + public String imageUrl() { + return imageUrl; + } + + /** + * Returns the comment of the image. + * + * @return The comment of the image + */ + public String comment() { + return comment; + } + + // + // OBJECT METHODS + // + + @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()); } }