Only create Sones if create is actually true.
[Sone.git] / src / main / java / net / pterodactylus / sone / database / memory / MemoryDatabase.java
index 902410e..d87a712 100644 (file)
@@ -38,7 +38,7 @@ import net.pterodactylus.util.validation.Validation;
  */
 public class MemoryDatabase implements Database {
 
-       /** The local SSones. */
+       /** The local Sones. */
        private final Map<String, Sone> localSones = new HashMap<String, Sone>();
 
        /** The remote Sones. */
@@ -130,7 +130,7 @@ public class MemoryDatabase implements Database {
        public Sone getLocalSone(String id, boolean create) throws DatabaseException {
                Validation.begin().isNotNull("Sone ID", id).check();
                synchronized (localSones) {
-                       if (!localSones.containsKey(id)) {
+                       if (!localSones.containsKey(id) && create) {
                                localSones.put(id, new Sone(id));
                        }
                        return localSones.get(id);
@@ -144,7 +144,7 @@ public class MemoryDatabase implements Database {
        public Sone getRemoteSone(String id, boolean create) throws DatabaseException {
                Validation.begin().isNotNull("Sone ID", id).check();
                synchronized (remoteSones) {
-                       if (!remoteSones.containsKey(id)) {
+                       if (!remoteSones.containsKey(id) && create) {
                                remoteSones.put(id, new Sone(id));
                        }
                        return remoteSones.get(id);