From: David ‘Bombe’ Roden Date: Mon, 10 Jan 2011 20:34:52 +0000 (+0100) Subject: Add methods to create images. X-Git-Tag: beta-freefall-0.6.2-1~130 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a841a0883726a9b23862997adca5765306de0d0f;p=Sone.git Add methods to create images. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index c830cf4..e01ea45 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -33,6 +33,7 @@ import net.pterodactylus.sone.core.Options.Option; import net.pterodactylus.sone.core.Options.OptionWatcher; import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Client; +import net.pterodactylus.sone.data.Image; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Reply; @@ -155,6 +156,9 @@ public class Core implements IdentityListener, UpdateListener { /** All known albums. */ private Map albums = new HashMap(); + /** All known images. */ + private Map images = new HashMap(); + /** * Creates a new core. * @@ -752,6 +756,40 @@ public class Core implements IdentityListener, UpdateListener { } } + /** + * Returns the image with the given ID, creating it if necessary. + * + * @param imageId + * The ID of the image + * @return The image with the given ID + */ + public Image getImage(String imageId) { + return getImage(imageId, true); + } + + /** + * Returns the image with the given ID, optionally creating it if it does + * not exist. + * + * @param imageId + * The ID of the image + * @param create + * {@code true} to create an image if none exists with the given + * ID + * @return The image with the given ID, or {@code null} if none exists and + * none was created + */ + public Image getImage(String imageId, boolean create) { + synchronized (images) { + Image image = images.get(imageId); + if (create && (image == null)) { + image = new Image(imageId); + images.put(imageId, image); + } + return image; + } + } + // // ACTIONS //