X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdatabase%2Fmemory%2FMemoryDatabase.java;h=3c32f71b780573b2a2e1f98f866ff29619bc7dd4;hb=a7c7118b60516be41b759d4cc41d61e2bc074ebb;hp=d87a712a5c24cdee67ff3f834244979706db1090;hpb=c3055539dfe69e19c28bae7f3ad167ddc7491118;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index d87a712..3c32f71 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -48,48 +48,8 @@ public class MemoryDatabase implements Database { * {@inheritDoc} */ @Override - public boolean isLocalSone(Sone sone) throws DatabaseException { - Validation.begin().isNotNull("Sone", sone).check(); - return isLocalSone(sone.getId()); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isLocalSone(String id) throws DatabaseException { - Validation.begin().isNotNull("Sone ID", id).check(); - synchronized (localSones) { - return localSones.containsKey(id); - } - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isRemoteSone(Sone sone) throws DatabaseException { - Validation.begin().isNotNull("Sone", sone).check(); - return isRemoteSone(sone.getId()); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isRemoteSone(String id) throws DatabaseException { - Validation.begin().isNotNull("Sone ID", id).check(); - synchronized (remoteSones) { - return remoteSones.containsKey(id); - } - } - - /** - * {@inheritDoc} - */ - @Override public Sone getSone(String id, boolean create) throws DatabaseException { - if (isLocalSone(id)) { + if (getLocalSone(id, false) != null) { return getLocalSone(id, create); } return getRemoteSone(id, create); @@ -131,7 +91,7 @@ public class MemoryDatabase implements Database { Validation.begin().isNotNull("Sone ID", id).check(); synchronized (localSones) { if (!localSones.containsKey(id) && create) { - localSones.put(id, new Sone(id)); + localSones.put(id, new Sone(id, true)); } return localSones.get(id); } @@ -145,7 +105,7 @@ public class MemoryDatabase implements Database { Validation.begin().isNotNull("Sone ID", id).check(); synchronized (remoteSones) { if (!remoteSones.containsKey(id) && create) { - remoteSones.put(id, new Sone(id)); + remoteSones.put(id, new Sone(id, false)); } return remoteSones.get(id); } @@ -156,7 +116,7 @@ public class MemoryDatabase implements Database { */ @Override public void saveSone(Sone sone) throws DatabaseException { - if (isLocalSone(sone)) { + if (sone.isLocal()) { synchronized (localSones) { localSones.put(sone.getId(), sone); } @@ -173,7 +133,7 @@ public class MemoryDatabase implements Database { */ @Override public void removeSone(Sone sone) throws DatabaseException { - Map sones = isLocalSone(sone) ? localSones : remoteSones; + Map sones = sone.isLocal() ? localSones : remoteSones; synchronized (sones) { sones.remove(sone.getId()); } @@ -184,7 +144,7 @@ public class MemoryDatabase implements Database { */ @Override public void removeSone(String id) throws DatabaseException { - Map sones = isLocalSone(id) ? localSones : remoteSones; + Map sones = ((getSone(id, false) != null) && getSone(id, false).isLocal()) ? localSones : remoteSones; synchronized (sones) { sones.remove(id); }