X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2Fimpl%2FPostBuilderImpl.java;h=6d5d70f61a0282f4ed2b8e0bb0f5262622a0ce53;hb=ed19f10e7931fb0b09c042c6070e37dffb23ceac;hp=929f3152ae7ed4ab39d6dbfceaae12feba262c93;hpb=6d8f11098552fcb40a87d3e35690b3ba760fb947;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java index 929f315..6d5d70f 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java @@ -17,145 +17,35 @@ package net.pterodactylus.sone.data.impl; -import static com.google.common.base.Preconditions.checkState; - import java.util.UUID; -import net.pterodactylus.sone.core.SoneProvider; import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.PostBuilder; - -import org.apache.commons.lang.StringUtils; +import net.pterodactylus.sone.database.PostBuilder; +import net.pterodactylus.sone.database.SoneProvider; /** * {@link PostBuilder} implementation that creates {@link PostImpl} objects. * * @author David ‘Bombe’ Roden */ -public class PostBuilderImpl implements PostBuilder { +public class PostBuilderImpl extends AbstractPostBuilder { - /** The Sone provider for the created posts. */ private final SoneProvider soneProvider; - /** Wether to create a post with a random ID. */ - private boolean randomId; - - /** The ID of the post. */ - private String id; - - /** The sender of the post. */ - private String senderId; - - /** Whether to use the current time when creating the post. */ - private boolean currentTime; - - /** The time of the post. */ - private long time; - - /** The text of the post. */ - private String text; - - /** The (optional) recipient of the post. */ - private String recipientId; - /** * Creates a new post builder. * * @param soneProvider - * The Sone provider + * The Sone provider */ public PostBuilderImpl(SoneProvider soneProvider) { this.soneProvider = soneProvider; } - /** - * {@inheritDoc} - */ - @Override - public PostBuilder copyPost(Post post) { - this.randomId = false; - this.id = post.getId(); - this.senderId = post.getSone().getId(); - this.currentTime = false; - this.time = post.getTime(); - this.text = post.getText(); - this.recipientId = (post.getRecipient() != null) ? post.getRecipient().getId() : null; - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public PostBuilder randomId() { - randomId = true; - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public PostBuilder withId(String id) { - this.id = id; - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public PostBuilder from(String senderId) { - this.senderId = senderId; - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public PostBuilder currentTime() { - currentTime = true; - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public PostBuilder withTime(long time) { - this.time = time; - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public PostBuilder withText(String text) { - this.text = text; - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public PostBuilder to(String recipientId) { - this.recipientId = recipientId; - return this; - } - - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public Post build() { - checkState((randomId && (id == null)) || (!randomId && (id != null)), "exactly one of random ID or custom ID must be set"); - checkState(senderId != null, "sender must not be null"); - checkState((currentTime && (time == 0)) || (!currentTime && (time > 0)), "one of current time or custom time must be set"); - checkState(!StringUtils.isBlank(text), "text must not be empty"); - checkState((recipientId == null) || !recipientId.equals(senderId), "sender and recipient must not be the same"); + validate(); return new PostImpl(soneProvider, randomId ? UUID.randomUUID().toString() : id, senderId, recipientId, currentTime ? System.currentTimeMillis() : time, text); }