2 * Sone - PostBuilder.kt - Copyright © 2013–2020 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.database
20 import net.pterodactylus.sone.data.Post
21 import net.pterodactylus.sone.data.Sone
24 * Builder for [Post] objects.
27 * A [Post] consists of the following elements:
31 * * an optional [recipient][Sone],
35 * Except for the recipient, all this elements have to be configured on this
36 * builder. For the ID you have the possibility to configure either a random ID
37 * (which should be used for new posts) or a custom ID you specify (for creating
38 * an existing post). For the time you can use the current time (again, for
39 * creating new posts) or the given time (for loading posts). It is an error to
40 * specify both ways for either the ID or the time.
42 interface PostBuilder {
44 fun copyPost(post: Post): PostBuilder
46 fun from(senderId: String): PostBuilder
48 fun randomId(): PostBuilder
49 fun withId(id: String): PostBuilder
51 fun currentTime(): PostBuilder
52 fun withTime(time: Long): PostBuilder
54 fun withText(text: String): PostBuilder
56 fun to(recipientId: String): PostBuilder
59 * Verifies this builder’s configuration and creates a new post.
61 * The following conditions must be met in order for this builder to be
62 * configured correctly:
64 * * Exactly one of [randomId] or [withId] must have been called.
65 * * The [sender][from] must not be `null`.
66 * * Exactly one of [currentTime] or [withTime] must have been called.
67 * * The [text][withText] must not be `null` and must contain something other than whitespace.
68 * * The [recipient][to] must either not have been set, or it must have been set to a [Sone] other than [the sender][from].
71 * @throws IllegalStateException if this builder’s configuration is not valid