2 * Sone - PostReplyBuilderImpl.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.data.impl;
20 import static com.google.common.base.Preconditions.checkState;
22 import java.util.UUID;
24 import net.pterodactylus.sone.core.PostProvider;
25 import net.pterodactylus.sone.core.SoneProvider;
26 import net.pterodactylus.sone.data.PostReply;
27 import net.pterodactylus.sone.data.PostReplyBuilder;
29 import org.apache.commons.lang.StringUtils;
32 * {@link PostReplyBuilder} implementation that creates {@link PostReplyImpl}
35 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
37 public class PostReplyBuilderImpl extends AbstractReplyBuilder<PostReplyBuilder> implements PostReplyBuilder {
39 /** The Sone provider. */
40 private final SoneProvider soneProvider;
42 /** The post provider. */
43 private final PostProvider postProvider;
45 /** The ID of the post the created reply refers to. */
46 private String postId;
49 * Creates a new post reply builder.
56 public PostReplyBuilderImpl(SoneProvider soneProvider, PostProvider postProvider) {
57 this.soneProvider = soneProvider;
58 this.postProvider = postProvider;
65 public PostReplyBuilder to(String postId) {
74 public PostReply build() {
75 checkState((randomId && (id == null)) || (!randomId && (id != null)), "either random ID nor custom ID must be set");
76 checkState(senderId != null, "sender must not be null");
77 checkState((currentTime && (time == 0)) || (!currentTime && (time >= 0)), "either current time or custom time must be set");
78 checkState(!StringUtils.isBlank(text), "text must not be empty");
79 checkState(postId != null, "post must not be null");
81 /* create new post reply. */
82 return new PostReplyImpl(soneProvider, postProvider, randomId ? UUID.randomUUID().toString() : id, senderId, currentTime ? System.currentTimeMillis() : time, text, postId);