From: David ‘Bombe’ Roden Date: Tue, 2 Dec 2014 19:23:22 +0000 (+0100) Subject: Add method to return a local Sone from the database. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=01e42c8c266e17a2c03f7c571478d816e12cc5e5;p=Sone.git Add method to return a local Sone from the database. --- diff --git a/src/main/java/net/pterodactylus/sone/database/LocalSoneDatabase.java b/src/main/java/net/pterodactylus/sone/database/LocalSoneDatabase.java index b53d890..036c607 100644 --- a/src/main/java/net/pterodactylus/sone/database/LocalSoneDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/LocalSoneDatabase.java @@ -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 getLocalSone(String localSoneId); Sone registerLocalSone(OwnIdentity ownIdentity); String getLastInsertFingerprint(Sone sone); void setLastInsertFingerprint(Sone sone, String lastInsertFingerprint); 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 813dc42..12ef439 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -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 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) {