From 3993bb581e277bc8b1a2b45122d0c7bbced9405c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 10 Nov 2010 20:29:14 +0100 Subject: [PATCH] =?utf8?q?Add=20=E2=80=9Ccreate=E2=80=9D=20parameter=20tha?= =?utf8?q?t=20can=20skip=20the=20creation=20of=20a=20new=20Sone.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/core/Core.java | 35 ++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) 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); } -- 2.7.4