Remove unnecessary type parameter.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / impl / PostReplyBuilderImpl.java
1 /*
2  * Sone - PostReplyBuilderImpl.java - Copyright © 2013 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sone.data.impl;
19
20 import static com.google.common.base.Preconditions.checkState;
21
22 import java.util.UUID;
23
24 import net.pterodactylus.sone.data.Post;
25 import net.pterodactylus.sone.data.PostReply;
26 import net.pterodactylus.sone.data.PostReplyBuilder;
27
28 import org.apache.commons.lang.StringUtils;
29
30 /**
31  * {@link PostReplyBuilder} implementation that creates {@link PostReplyImpl}
32  * objects.
33  *
34  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
35  */
36 public class PostReplyBuilderImpl extends AbstractReplyBuilder<PostReplyBuilder> implements PostReplyBuilder {
37
38         /** The post the created reply refers to. */
39         private Post post;
40
41         /**
42          * {@inheritDoc}
43          */
44         @Override
45         public PostReplyBuilder to(Post post) {
46                 this.post = post;
47                 return this;
48         }
49
50         /**
51          * {@inheritDoc}
52          */
53         @Override
54         public PostReply build() {
55                 checkState((randomId && (id == null)) || (!randomId && (id != null)), "either random ID nor custom ID must be set");
56                 checkState(sender != null, "sender must not be null");
57                 checkState((currentTime && (time == 0)) || (!currentTime && (time >= 0)), "either current time or custom time must be set");
58                 checkState(!StringUtils.isBlank(text), "text must not be empty");
59                 checkState(post != null, "post must not be null");
60
61                 /* create new post reply. */
62                 PostReplyImpl postReplyImpl = new PostReplyImpl(randomId ? UUID.randomUUID().toString() : id);
63                 postReplyImpl.setSone(sender);
64                 postReplyImpl.setPost(post);
65                 postReplyImpl.setTime(currentTime ? System.currentTimeMillis() : time);
66                 postReplyImpl.setText(text);
67                 return postReplyImpl;
68         }
69 }