Return an optional from the Core already.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / impl / PostImpl.java
index bb8a4df..f0f9d35 100644 (file)
@@ -19,9 +19,11 @@ package net.pterodactylus.sone.data.impl;
 
 import java.util.UUID;
 
-import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.database.Database;
+
+import com.google.common.base.Optional;
 
 /**
  * A post is a short message that a user writes in his Sone to let other users
@@ -31,8 +33,7 @@ import net.pterodactylus.sone.data.Sone;
  */
 public class PostImpl implements Post {
 
-       /** The Sone provider. */
-       private final SoneProvider soneProvider;
+       private final Database database;
 
        /** The GUID of the post. */
        private final UUID id;
@@ -55,8 +56,8 @@ public class PostImpl implements Post {
        /**
         * Creates a new post.
         *
-        * @param soneProvider
-        *            The Sone provider
+        * @param database
+        *            The database
         * @param id
         *            The ID of the post
         * @param soneId
@@ -68,8 +69,8 @@ public class PostImpl implements Post {
         * @param text
         *            The text of the post
         */
-       public PostImpl(SoneProvider soneProvider, String id, String soneId, String recipientId, long time, String text) {
-               this.soneProvider = soneProvider;
+       public PostImpl(Database database, String id, String soneId, String recipientId, long time, String text) {
+               this.database = database;
                this.id = UUID.fromString(id);
                this.soneId = soneId;
                this.recipientId = recipientId;
@@ -94,15 +95,23 @@ public class PostImpl implements Post {
         */
        @Override
        public Sone getSone() {
-               return soneProvider.getSone(soneId, false);
+               return database.getSone(soneId).get();
+       }
+
+       /**
+        * {@inheritDocs}
+        */
+       @Override
+       public Optional<String> getRecipientId() {
+               return Optional.fromNullable(recipientId);
        }
 
        /**
         * {@inheritDoc}
         */
        @Override
-       public Sone getRecipient() {
-               return soneProvider.getSone(recipientId, false);
+       public Optional<Sone> getRecipient() {
+               return database.getSone(recipientId);
        }
 
        /**