X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2Fimpl%2FAbstractReplyBuilder.java;h=389eb85bbce8d4a69d79dd8daac3ba61a4693cfd;hb=8d5dcab8d96af52241aaf425440680806c5e20d3;hp=5c1b97678bb086d54d795cd47af1c823d2392e44;hpb=041f2bcb967b6ae170053d2a0a7055f869b894dd;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java b/src/main/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java index 5c1b976..389eb85 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java @@ -20,12 +20,14 @@ package net.pterodactylus.sone.data.impl; import static com.google.common.base.Optional.absent; import static com.google.common.base.Optional.fromNullable; import static com.google.common.base.Optional.of; +import static com.google.common.base.Preconditions.checkState; import static java.lang.System.currentTimeMillis; import static java.util.UUID.randomUUID; import net.pterodactylus.sone.database.ReplyBuilder; import com.google.common.base.Optional; +import org.apache.commons.lang.StringUtils; /** * Abstract implementation of a {@link ReplyBuilder}. @@ -36,24 +38,13 @@ import com.google.common.base.Optional; */ public class AbstractReplyBuilder> implements ReplyBuilder { + protected final String senderId; protected Optional id = absent(); - - /** The sender of the reply. */ - protected String senderId; - protected Optional time = absent(); - - /** The text of the reply. */ protected String text; - /** - * {@inheritDoc} - */ - @Override - @SuppressWarnings("unchecked") - public B withId(String id) { - this.id = fromNullable(id); - return (B) this; + protected AbstractReplyBuilder(String senderId) { + this.senderId = senderId; } /** @@ -61,8 +52,8 @@ public class AbstractReplyBuilder> implements ReplyBui */ @Override @SuppressWarnings("unchecked") - public B from(String senderId) { - this.senderId = senderId; + public B withId(String id) { + this.id = fromNullable(id); return (B) this; } @@ -94,4 +85,15 @@ public class AbstractReplyBuilder> implements ReplyBui return time.isPresent() ? time.get() : currentTimeMillis(); } + /** + * Validates the state of this post reply builder. + * + * @throws IllegalStateException + * if the state is not valid for building a new post reply + */ + protected void validate() throws IllegalStateException { + checkState(senderId != null, "sender must not be null"); + checkState(!StringUtils.isBlank(text), "text must not be empty"); + } + }