From 01e42c8c266e17a2c03f7c571478d816e12cc5e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 2 Dec 2014 20:23:22 +0100 Subject: [PATCH] Add method to return a local Sone from the database. --- .../net/pterodactylus/sone/database/LocalSoneDatabase.java | 4 ++++ .../pterodactylus/sone/database/memory/MemoryDatabase.java | 13 +++++++++++++ 2 files changed, 17 insertions(+) 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) { -- 2.7.4