package net.pterodactylus.sone.data.impl;
-import static com.google.common.base.Preconditions.checkState;
-
-import java.util.UUID;
-
-import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.PostReplyBuilder;
-
-import org.apache.commons.lang.StringUtils;
+import net.pterodactylus.sone.database.Database;
+import net.pterodactylus.sone.database.PostReplyBuilder;
/**
* {@link PostReplyBuilder} implementation that creates {@link PostReplyImpl}
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
-public class PostReplyBuilderImpl extends AbstractReplyBuilder<PostReplyBuilderImpl, PostReplyBuilder> implements PostReplyBuilder {
+public class PostReplyBuilderImpl extends AbstractPostReplyBuilder {
- /** The post the created reply refers to. */
- private Post post;
+ private final Database database;
- /**
- * {@inheritDoc}
- */
- @Override
- public PostReplyBuilder to(Post post) {
- this.post = post;
- return this;
+ public PostReplyBuilderImpl(Database database) {
+ this.database = database;
}
/**
*/
@Override
public PostReply build() {
- checkState((randomId && (id == null)) || (!randomId && (id != null)), "either random ID nor custom ID must be set");
- checkState(sender != null, "sender must not be null");
- checkState((currentTime && (time == 0)) || (!currentTime && (time >= 0)), "either current time or custom time must be set");
- checkState(!StringUtils.isBlank(text), "text must not be empty");
- checkState(post != null, "post must not be null");
+ validate();
/* create new post reply. */
- PostReplyImpl postReplyImpl = new PostReplyImpl(randomId ? UUID.randomUUID().toString() : id);
- postReplyImpl.setSone(sender);
- postReplyImpl.setPost(post);
- postReplyImpl.setTime(currentTime ? System.currentTimeMillis() : time);
- postReplyImpl.setText(text);
- return postReplyImpl;
+ return new PostReplyImpl(database, getId(), senderId, getTime(), text, postId);
}
+
}