Use different method to create a local Sone.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / impl / AbstractSoneBuilder.java
index bc19d4d..5ec8ec4 100644 (file)
@@ -7,6 +7,7 @@ import java.util.HashSet;
 
 import net.pterodactylus.sone.data.Client;
 import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.database.SoneBuilder;
 import net.pterodactylus.sone.freenet.wot.Identity;
 import net.pterodactylus.sone.freenet.wot.OwnIdentity;
@@ -19,10 +20,10 @@ import net.pterodactylus.sone.freenet.wot.OwnIdentity;
 public abstract class AbstractSoneBuilder implements SoneBuilder {
 
        protected Identity identity;
-       protected boolean local;
        protected long lastUpdated;
        protected Client client;
        protected final Collection<Post> posts = new HashSet<Post>();
+       protected final Collection<PostReply> postReplies = new HashSet<PostReply>();
 
        @Override
        public SoneBuilder from(Identity identity) {
@@ -31,12 +32,6 @@ public abstract class AbstractSoneBuilder implements SoneBuilder {
        }
 
        @Override
-       public SoneBuilder local() {
-               this.local = true;
-               return this;
-       }
-
-       @Override
        public SoneBuilder lastUpdated(long lastUpdated) {
                this.lastUpdated = lastUpdated;
                return this;
@@ -55,12 +50,23 @@ public abstract class AbstractSoneBuilder implements SoneBuilder {
                return this;
        }
 
+       @Override
+       public SoneBuilder withPostReplies(Collection<PostReply> postReplies) {
+               this.postReplies.clear();
+               this.postReplies.addAll(postReplies);
+               return this;
+       }
+
        protected void validate() throws IllegalStateException {
                checkState(identity != null, "identity must not be null");
-               checkState(!local || (identity instanceof OwnIdentity),
-                               "can not create local Sone from remote identity");
                checkState(lastUpdated > 0, "last update time must be set");
                checkState(client != null, "client must not be null");
        }
 
+       protected void validateLocal() throws IllegalStateException {
+               validate();
+               checkState(identity instanceof OwnIdentity,
+                               "identity must be an own identity for a local Sone");
+       }
+
 }