From 08db78abe21e54199586cb90450cc0d4ec4a6b81 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 10 Jan 2011 20:35:59 +0100 Subject: [PATCH] Add methods to create albums. --- .../java/net/pterodactylus/sone/core/Core.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 78df9ef..04e37bb 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -31,6 +31,7 @@ import java.util.logging.Logger; import net.pterodactylus.sone.core.Options.DefaultOption; 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.Post; import net.pterodactylus.sone.data.Profile; @@ -151,6 +152,9 @@ public class Core implements IdentityListener, UpdateListener { /** All known replies. */ private Set knownReplies = new HashSet(); + /** All known albums. */ + private Map albums = new HashMap(); + /** * Creates a new core. * @@ -713,6 +717,38 @@ public class Core implements IdentityListener, UpdateListener { return sones; } + /** + * Returns the album with the given ID, creating a new album if no album + * with the given ID can be found. + * + * @param albumId + * The ID of the album + * @return The album with the given ID + */ + public Album getAlbum(String albumId) { + return getAlbum(albumId, true); + } + + /** + * Returns the album with the given ID, optionally creating a new album if + * an album with the given ID can not be found. + * + * @param albumId + * The ID of the album + * @return The album with the given ID, or {@code null} if no album with the + * given ID exists and {@code create} is {@code false} + */ + public Album getAlbum(String albumId, boolean create) { + synchronized (albums) { + Album album = albums.get(albumId); + if (create && (album == null)) { + album = new Album(albumId); + albums.put(albumId, album); + } + return album; + } + } + // // ACTIONS // -- 2.7.4