Add method to return a local Sone from the database.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 2 Dec 2014 19:23:22 +0000 (20:23 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 2 Dec 2014 19:23:22 +0000 (20:23 +0100)
src/main/java/net/pterodactylus/sone/database/LocalSoneDatabase.java
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java

index b53d890..036c607 100644 (file)
@@ -1,8 +1,11 @@
 package net.pterodactylus.sone.database;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.freenet.wot.OwnIdentity;
 
+import com.google.common.base.Optional;
+
 /**
  * Database functions for local Sones.
  *
@@ -10,6 +13,7 @@ import net.pterodactylus.sone.freenet.wot.OwnIdentity;
  */
 public interface LocalSoneDatabase {
 
+       Optional<LocalSone> getLocalSone(String localSoneId);
        Sone registerLocalSone(OwnIdentity ownIdentity);
        String getLastInsertFingerprint(Sone sone);
        void setLastInsertFingerprint(Sone sone, String lastInsertFingerprint);
index 813dc42..12ef439 100644 (file)
@@ -50,6 +50,7 @@ import net.pterodactylus.sone.core.ConfigurationSoneParser.InvalidPostReplyFound
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Client;
 import net.pterodactylus.sone.data.Image;
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Profile;
@@ -158,6 +159,18 @@ public class MemoryDatabase extends AbstractService implements Database {
        // DATABASE METHODS
        //
 
+       @Override
+       public Optional<LocalSone> getLocalSone(String localSoneId) {
+               lock.readLock().lock();
+               try {
+                       if (!localSones.contains(localSoneId)) {
+                               return Optional.absent();
+                       }
+                       return Optional.of((LocalSone) allSones.get(localSoneId));
+               } finally {
+                       lock.readLock().unlock();
+               }
+       }
 
        @Override
        public Sone registerLocalSone(OwnIdentity ownIdentity) {