From: David ‘Bombe’ Roden Date: Wed, 10 Nov 2010 19:29:14 +0000 (+0100) Subject: Add “create” parameter that can skip the creation of a new Sone. X-Git-Tag: 0.2.1~13 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=3993bb581e277bc8b1a2b45122d0c7bbced9405c Add “create” parameter that can skip the creation of a new Sone. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 93891ab..b16165e 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -207,10 +207,27 @@ public class Core implements IdentityListener { * Sone */ public Sone getSone(String id) { + return getSone(id, true); + } + + /** + * Returns the Sone with the given ID, regardless whether it’s local or + * remote. + * + * @param id + * The ID of the Sone to get + * @param create + * {@code true} to create a new Sone if none exists, + * {@code false} to return {@code null} if a Sone with the given + * ID does not exist + * @return The Sone with the given ID, or {@code null} if there is no such + * Sone + */ + public Sone getSone(String id, boolean create) { if (isLocalSone(id)) { return getLocalSone(id); } - return getRemoteSone(id); + return getRemoteSone(id, create); } /** @@ -288,9 +305,23 @@ public class Core implements IdentityListener { * @return The Sone with the given ID */ public Sone getRemoteSone(String id) { + return getRemoteSone(id, true); + } + + /** + * Returns the remote Sone with the given ID. + * + * @param id + * The ID of the remote Sone to get + * @param create + * {@code true} to always create a Sone, {@code false} to return + * {@code null} if no Sone with the given ID exists + * @return The Sone with the given ID + */ + public Sone getRemoteSone(String id, boolean create) { synchronized (remoteSones) { Sone sone = remoteSones.get(id); - if (sone == null) { + if ((sone == null) && create) { sone = new Sone(id); remoteSones.put(id, sone); }