🔀 Merge branch 'release/v82'
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Post.java
1 /*
2  * Sone - Post.java - Copyright Â© 2010–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;
19
20 import static com.google.common.base.Optional.absent;
21
22 import com.google.common.base.Optional;
23
24 /**
25  * A post is a short message that a user writes in his Sone to let other users
26  * know what is going on.
27  */
28 public interface Post extends Identified {
29
30         //
31         // ACCESSORS
32         //
33
34         /**
35          * Returns the ID of the post.
36          *
37          * @return The ID of the post
38          */
39         public String getId();
40
41         /**
42          * Returns whether this post has already been loaded.
43          *
44          * @return {@code true} if this post has already been loaded, {@code
45          * false} otherwise
46          */
47         boolean isLoaded();
48
49         /**
50          * Returns the Sone this post belongs to.
51          *
52          * @return The Sone of this post
53          */
54         public Sone getSone();
55
56         /**
57          * Returns the ID of the recipient {@link Sone}, or
58          * {@link Optional#absent()} if this post does not have a recipient.
59          *
60          * @return The ID of the recipient, or {@link Optional#absent()}
61          */
62         public Optional<String> getRecipientId();
63
64         /**
65          * Returns the recipient of this post, if any.
66          *
67          * @return The recipient of this post, or {@link Optional#absent()} if there
68          *         is no recipient
69          */
70         public Optional<Sone> getRecipient();
71
72         /**
73          * Returns the time of the post.
74          *
75          * @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
76          */
77         public long getTime();
78
79         /**
80          * Returns the text of the post.
81          *
82          * @return The text of the post
83          */
84         public String getText();
85
86         /**
87          * Returns whether this post is known.
88          *
89          * @return {@code true} if this post is known, {@code false} otherwise
90          */
91         public boolean isKnown();
92
93         /**
94          * Sets whether this post is known.
95          *
96          * @param known
97          *            {@code true} if this post is known, {@code false} otherwise
98          * @return This post
99          */
100         public Post setKnown(boolean known);
101
102         /**
103          * Shell for a post that has not yet been loaded.
104          */
105         public static class EmptyPost implements Post {
106
107                 private final String id;
108
109                 public EmptyPost(String id) {
110                         this.id = id;
111                 }
112
113                 @Override
114                 public String getId() {
115                         return id;
116                 }
117
118                 @Override
119                 public boolean isLoaded() {
120                         return false;
121                 }
122
123                 @Override
124                 public Sone getSone() {
125                         return null;
126                 }
127
128                 @Override
129                 public Optional<String> getRecipientId() {
130                         return absent();
131                 }
132
133                 @Override
134                 public Optional<Sone> getRecipient() {
135                         return absent();
136                 }
137
138                 @Override
139                 public long getTime() {
140                         return 0;
141                 }
142
143                 @Override
144                 public String getText() {
145                         return null;
146                 }
147
148                 @Override
149                 public boolean isKnown() {
150                         return false;
151                 }
152
153                 @Override
154                 public Post setKnown(boolean known) {
155                         return this;
156                 }
157
158         }
159
160 }