Add callback interface to post build() method.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / impl / DefaultPostBuilder.java
index 9ac82c8..a07f144 100644 (file)
@@ -23,6 +23,8 @@ import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.database.Database;
 import net.pterodactylus.sone.database.PostBuilder;
 
+import com.google.common.base.Optional;
+
 /**
  * {@link PostBuilder} implementation that creates {@link PostImpl} objects.
  *
@@ -30,22 +32,24 @@ import net.pterodactylus.sone.database.PostBuilder;
  */
 public class DefaultPostBuilder extends AbstractPostBuilder {
 
-       private final Database database;
-
        /**
         * Creates a new post builder.
         *
         * @param database
         */
-       public DefaultPostBuilder(Database database) {
-               this.database = database;
+       public DefaultPostBuilder(Database database, String soneId) {
+               super(database, soneId);
        }
 
        /** {@inheritDoc} */
        @Override
-       public Post build() {
+       public Post build(Optional<PostCreated> postCreated) {
                validate();
-               return new PostImpl(database, randomId ? UUID.randomUUID().toString() : id, senderId, recipientId, currentTime ? System.currentTimeMillis() : time, text);
+               PostImpl post = new PostImpl(database, randomId ? UUID.randomUUID().toString() : id, senderId, recipientId.orNull(), currentTime ? System.currentTimeMillis() : time, text);
+               if (postCreated.isPresent()) {
+                       postCreated.get().postCreated(post);
+               }
+               return post;
        }
 
 }