🔀 Merge “release/v81” into “master”
[Sone.git] / src / main / java / net / pterodactylus / sone / data / impl / AbstractReplyBuilder.java
1 /*
2  * Sone - AbstractReplyBuilder.java - Copyright Â© 2013–2020 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 net.pterodactylus.sone.database.ReplyBuilder;
21
22 /**
23  * Abstract implementation of a {@link ReplyBuilder}.
24  *
25  * @param <B>
26  *            The interface implemented and exposed by the builder
27  */
28 public class AbstractReplyBuilder<B extends ReplyBuilder<B>> implements ReplyBuilder<B> {
29
30         /** Whether to use a random ID for the reply. */
31         protected boolean randomId;
32
33         /** The ID of the reply. */
34         protected String id;
35
36         /** The sender of the reply. */
37         protected String senderId;
38
39         /** Whether to use the current time when creating the reply. */
40         protected boolean currentTime;
41
42         /** The time of the reply. */
43         protected long time;
44
45         /** The text of the reply. */
46         protected String text;
47
48         /**
49          * {@inheritDoc}
50          */
51         @Override
52         @SuppressWarnings("unchecked")
53         public B randomId() {
54                 this.randomId = true;
55                 return (B) this;
56         }
57
58         /**
59          * {@inheritDoc}
60          */
61         @Override
62         @SuppressWarnings("unchecked")
63         public B withId(String id) {
64                 this.id = id;
65                 return (B) this;
66         }
67
68         /**
69          * {@inheritDoc}
70          */
71         @Override
72         @SuppressWarnings("unchecked")
73         public B from(String senderId) {
74                 this.senderId = senderId;
75                 return (B) this;
76         }
77
78         /**
79          * {@inheritDoc}
80          */
81         @Override
82         @SuppressWarnings("unchecked")
83         public B currentTime() {
84                 this.currentTime = true;
85                 return (B) this;
86         }
87
88         /**
89          * {@inheritDoc}
90          */
91         @Override
92         @SuppressWarnings("unchecked")
93         public B withTime(long time) {
94                 this.time = time;
95                 return (B) this;
96         }
97
98         /**
99          * {@inheritDoc}
100          */
101         @Override
102         @SuppressWarnings("unchecked")
103         public B withText(String text) {
104                 this.text = text;
105                 return (B) this;
106         }
107
108 }