From: David ‘Bombe’ Roden Date: Sat, 13 Nov 2010 10:16:52 +0000 (+0100) Subject: Add method to only optionally create a new Sone. X-Git-Tag: 0.3-RC1~103 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=9ddf85f5b48acd6fb134e8b70e9701226107003f;p=Sone.git Add method to only optionally create 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 90d3696..393c91f 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -301,9 +301,23 @@ public class Core implements IdentityListener { * @return The Sone with the given ID */ public Sone getLocalSone(String id) { + return getLocalSone(id, true); + } + + /** + * Returns the local Sone with the given ID, optionally creating a new Sone. + * + * @param id + * The ID of the Sone + * @param create + * {@code true} to create a new Sone if none exists, + * {@code false} to return null if none exists + * @return The Sone with the given ID, or {@code null} + */ + public Sone getLocalSone(String id, boolean create) { synchronized (localSones) { Sone sone = localSones.get(id); - if (sone == null) { + if ((sone == null) && create) { sone = new Sone(id); localSones.put(id, sone); }