Store all added Sones in the Sone cache.
[Sone.git] / src / main / java / net / pterodactylus / sone / core / Core.java
index 4a75a03..a300c66 100644 (file)
@@ -33,6 +33,7 @@ import net.pterodactylus.sone.data.PostShell;
 import net.pterodactylus.sone.data.Profile;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.ReplyShell;
+import net.pterodactylus.sone.data.Shell;
 import net.pterodactylus.sone.data.ShellCache;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.SoneShell;
@@ -119,6 +120,21 @@ public class Core extends AbstractService {
                return Collections.unmodifiableSet(localSones);
        }
 
+       /**
+        * Returns a Sone or a {@link Shell} around one for the given ID.
+        *
+        * @param soneId
+        *            The ID of the Sone
+        * @return The Sone, or a {@link Shell} around one
+        */
+       public Sone getSone(String soneId) {
+               Sone sone = soneCache.get(soneId);
+               if (sone instanceof SoneShell) {
+                       soneCache.put(soneId, sone = ((SoneShell) sone).getShelled());
+               }
+               return sone;
+       }
+
        //
        // ACTIONS
        //
@@ -131,6 +147,7 @@ public class Core extends AbstractService {
         */
        public void addSone(Sone sone) {
                if (localSones.add(sone)) {
+                       soneCache.put(sone.getId(), sone);
                        SoneInserter soneInserter = new SoneInserter(freenetInterface, sone);
                        soneInserter.start();
                        soneInserters.put(sone, soneInserter);