ec1299ae07b25685819cb6ea04aee879c2ec3059
[Sone.git] / src / main / java / net / pterodactylus / sone / data / impl / PostReplyBuilderImpl.java
1 /*
2  * Sone - PostReplyBuilderImpl.java - Copyright © 2013–2019 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.PostReply;
25 import net.pterodactylus.sone.database.PostProvider;
26 import net.pterodactylus.sone.database.PostReplyBuilder;
27 import net.pterodactylus.sone.database.SoneProvider;
28
29 /**
30  * {@link PostReplyBuilder} implementation that creates {@link PostReplyImpl}
31  * objects.
32  */
33 public class PostReplyBuilderImpl extends AbstractPostReplyBuilder {
34
35         /** The Sone provider. */
36         private final SoneProvider soneProvider;
37
38         /** The post provider. */
39         private final PostProvider postProvider;
40
41         /**
42          * Creates a new post reply builder.
43          *
44          * @param soneProvider
45          *            The Sone provider
46          * @param postProvider
47          *            The post provider
48          */
49         public PostReplyBuilderImpl(SoneProvider soneProvider, PostProvider postProvider) {
50                 this.soneProvider = soneProvider;
51                 this.postProvider = postProvider;
52         }
53
54         /**
55          * {@inheritDoc}
56          */
57         @Override
58         public PostReply build() {
59                 validate();
60
61                 /* create new post reply. */
62                 return new PostReplyImpl(soneProvider, postProvider, randomId ? UUID.randomUUID().toString() : id, senderId, currentTime ? System.currentTimeMillis() : time, text, postId);
63         }
64
65 }