1 package net.pterodactylus.sone.data.impl;
3 import static com.google.common.base.Preconditions.checkState;
5 import java.util.Collection;
6 import java.util.HashSet;
8 import net.pterodactylus.sone.data.Client;
9 import net.pterodactylus.sone.data.Post;
10 import net.pterodactylus.sone.database.SoneBuilder;
11 import net.pterodactylus.sone.freenet.wot.Identity;
12 import net.pterodactylus.sone.freenet.wot.OwnIdentity;
15 * Abstract {@link SoneBuilder} implementation.
17 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
19 public abstract class AbstractSoneBuilder implements SoneBuilder {
21 protected Identity identity;
22 protected boolean local;
23 protected long lastUpdated;
24 protected Client client;
25 protected final Collection<Post> posts = new HashSet<Post>();
28 public SoneBuilder from(Identity identity) {
29 this.identity = identity;
34 public SoneBuilder local() {
40 public SoneBuilder lastUpdated(long lastUpdated) {
41 this.lastUpdated = lastUpdated;
46 public SoneBuilder using(Client client) {
52 public SoneBuilder withPosts(Collection<Post> posts) {
54 this.posts.addAll(posts);
58 protected void validate() throws IllegalStateException {
59 checkState(identity != null, "identity must not be null");
60 checkState(!local || (identity instanceof OwnIdentity),
61 "can not create local Sone from remote identity");
62 checkState(lastUpdated > 0, "last update time must be set");
63 checkState(client != null, "client must not be null");