X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2Fimpl%2FAbstractSoneBuilder.java;h=5ec8ec4244933d5aea7025820909bbc280c87442;hb=f8672b1385173a103d7f085d8e9cd43bc5762d71;hp=b7dda3f312994012ab73bb937656e1fc22a11b48;hpb=fd9d1edd9eef0dff1e9dd17a6bc55cb9e4da8f9f;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/impl/AbstractSoneBuilder.java b/src/main/java/net/pterodactylus/sone/data/impl/AbstractSoneBuilder.java index b7dda3f..5ec8ec4 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/AbstractSoneBuilder.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/AbstractSoneBuilder.java @@ -2,6 +2,12 @@ package net.pterodactylus.sone.data.impl; import static com.google.common.base.Preconditions.checkState; +import java.util.Collection; +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; @@ -14,8 +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 posts = new HashSet(); + protected final Collection postReplies = new HashSet(); @Override public SoneBuilder from(Identity identity) { @@ -24,22 +32,41 @@ public abstract class AbstractSoneBuilder implements SoneBuilder { } @Override - public SoneBuilder local() { - this.local = true; + public SoneBuilder lastUpdated(long lastUpdated) { + this.lastUpdated = lastUpdated; return this; } @Override - public SoneBuilder lastUpdated(long lastUpdated) { - this.lastUpdated = lastUpdated; + public SoneBuilder using(Client client) { + this.client = client; + return this; + } + + @Override + public SoneBuilder withPosts(Collection posts) { + this.posts.clear(); + this.posts.addAll(posts); + return this; + } + + @Override + public SoneBuilder withPostReplies(Collection 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"); } }