From d920774a69518c31b5e66d36b830bcf95a5ec237 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 15 Oct 2017 12:56:17 +0200 Subject: [PATCH] Replace reply-specific interfaces with Kotlin versions --- .../sone/database/PostReplyBuilder.java | 61 --------------- .../sone/database/PostReplyBuilderFactory.java | 39 ---------- .../sone/database/PostReplyDatabase.java | 30 -------- .../sone/database/PostReplyProvider.java | 51 ------------- .../sone/database/PostReplyStore.java | 48 ------------ .../pterodactylus/sone/database/ReplyBuilder.java | 88 ---------------------- .../sone/database/PostReplyBuilder.kt | 46 +++++++++++ .../sone/database/PostReplyBuilderFactory.kt | 32 ++++++++ .../sone/database/PostReplyDatabase.kt | 24 ++++++ .../sone/database/PostReplyProvider.kt | 38 ++++++++++ .../pterodactylus/sone/database/PostReplyStore.kt | 31 ++++++++ .../pterodactylus/sone/database/ReplyBuilder.kt | 39 ++++++++++ 12 files changed, 210 insertions(+), 317 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/sone/database/PostReplyBuilder.java delete mode 100644 src/main/java/net/pterodactylus/sone/database/PostReplyBuilderFactory.java delete mode 100644 src/main/java/net/pterodactylus/sone/database/PostReplyDatabase.java delete mode 100644 src/main/java/net/pterodactylus/sone/database/PostReplyProvider.java delete mode 100644 src/main/java/net/pterodactylus/sone/database/PostReplyStore.java delete mode 100644 src/main/java/net/pterodactylus/sone/database/ReplyBuilder.java create mode 100644 src/main/kotlin/net/pterodactylus/sone/database/PostReplyBuilder.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/database/PostReplyBuilderFactory.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/database/PostReplyDatabase.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/database/PostReplyProvider.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/database/PostReplyStore.kt create mode 100644 src/main/kotlin/net/pterodactylus/sone/database/ReplyBuilder.kt diff --git a/src/main/java/net/pterodactylus/sone/database/PostReplyBuilder.java b/src/main/java/net/pterodactylus/sone/database/PostReplyBuilder.java deleted file mode 100644 index 16569d9..0000000 --- a/src/main/java/net/pterodactylus/sone/database/PostReplyBuilder.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Sone - PostReplyBuilder.java - Copyright © 2013–2016 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.database; - -import net.pterodactylus.sone.data.PostReply; - -/** - * Builder for a {@link PostReply} object. - * - * @author David ‘Bombe’ Roden - */ -public interface PostReplyBuilder extends ReplyBuilder { - - /** - * Configures this builder to set the given post as post the created reply - * refers to. - * - * @param postId - * The ID of the post the reply refers to - * @return This builder - */ - public PostReplyBuilder to(String postId); - - /** - * Verifies the configuration of this builder and creates a new post reply. - *

- * The following conditions must be met in order for the configuration to be - * considered valid: - *

    - *
  • Exactly one of {@link #randomId()} or {@link #withId(String)} must - * have been called.
  • - *
  • The {@link #from(String) sender} must not be {@code null}.
  • - *
  • Exactly one of {@link #currentTime()} or {@link #withTime(long)} must - * have been called.
  • - *
  • The {@link #withText(String) text} must not be {@code null} and must - * contain something other than whitespace.
  • - *
  • The {@link #to(String) post} have been set.
  • - *
- * - * @return The created post reply - * @throws IllegalStateException - * if this builder’s configuration is not valid - */ - public PostReply build() throws IllegalStateException; - -} diff --git a/src/main/java/net/pterodactylus/sone/database/PostReplyBuilderFactory.java b/src/main/java/net/pterodactylus/sone/database/PostReplyBuilderFactory.java deleted file mode 100644 index f85b18b..0000000 --- a/src/main/java/net/pterodactylus/sone/database/PostReplyBuilderFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Sone - PostReplyBuilderFactory.java - Copyright © 2013–2016 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.database; - -import net.pterodactylus.sone.database.memory.MemoryDatabase; - -import com.google.inject.ImplementedBy; - -/** - * Factory for {@link PostReplyBuilder}s. - * - * @author David ‘Bombe’ Roden - */ -@ImplementedBy(MemoryDatabase.class) -public interface PostReplyBuilderFactory { - - /** - * Creates a new post reply builder. - * - * @return A new post reply builder - */ - public PostReplyBuilder newPostReplyBuilder(); - -} diff --git a/src/main/java/net/pterodactylus/sone/database/PostReplyDatabase.java b/src/main/java/net/pterodactylus/sone/database/PostReplyDatabase.java deleted file mode 100644 index f226d73..0000000 --- a/src/main/java/net/pterodactylus/sone/database/PostReplyDatabase.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Sone - PostReplyDatabase.java - Copyright © 2013–2016 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.database; - -/** - * Combines a {@link PostReplyProvider}, a {@link PostReplyBuilderFactory}, and - * a {@link PostReplyStore} into a complete post reply database. - * - * @author David ‘Bombe’ Roden - */ -public interface PostReplyDatabase extends PostReplyProvider, PostReplyBuilderFactory, PostReplyStore { - - /* nothing here. */ - -} diff --git a/src/main/java/net/pterodactylus/sone/database/PostReplyProvider.java b/src/main/java/net/pterodactylus/sone/database/PostReplyProvider.java deleted file mode 100644 index e982599..0000000 --- a/src/main/java/net/pterodactylus/sone/database/PostReplyProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Sone - PostReplyProvider.java - Copyright © 2013–2016 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.database; - -import java.util.List; - -import net.pterodactylus.sone.data.PostReply; - -import com.google.common.base.Optional; - -/** - * Interface for objects that can provide {@link PostReply}s. - * - * @author David ‘Bombe’ Roden - */ -public interface PostReplyProvider { - - /** - * Returns the reply with the given ID. - * - * @param id - * The ID of the reply to get - * @return The reply, or {@code null} if there is no such reply - */ - public Optional getPostReply(String id); - - /** - * Returns all replies for the given post, order ascending by time. - * - * @param postId - * The ID of the post to get all replies for - * @return All replies for the given post - */ - public List getReplies(String postId); - -} diff --git a/src/main/java/net/pterodactylus/sone/database/PostReplyStore.java b/src/main/java/net/pterodactylus/sone/database/PostReplyStore.java deleted file mode 100644 index 7956a92..0000000 --- a/src/main/java/net/pterodactylus/sone/database/PostReplyStore.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Sone - PostReplyStore.java - Copyright © 2013–2016 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.database; - -import java.util.Collection; - -import net.pterodactylus.sone.data.PostReply; -import net.pterodactylus.sone.data.Sone; - -/** - * Defines a store for {@link PostReply post replies}. - * - * @author David ‘Bombe’ Roden - */ -public interface PostReplyStore { - - /** - * Stores the given post reply. - * - * @param postReply - * The post reply - */ - public void storePostReply(PostReply postReply); - - /** - * Removes the given post reply from this store. - * - * @param postReply - * The post reply to remove - */ - public void removePostReply(PostReply postReply); - -} diff --git a/src/main/java/net/pterodactylus/sone/database/ReplyBuilder.java b/src/main/java/net/pterodactylus/sone/database/ReplyBuilder.java deleted file mode 100644 index 21ba89c..0000000 --- a/src/main/java/net/pterodactylus/sone/database/ReplyBuilder.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Sone - ReplyBuilder.java - Copyright © 2013–2016 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.database; - -import net.pterodactylus.sone.data.Reply; -import net.pterodactylus.sone.data.Sone; - -/** - * Methods that all reply builders need to implement in order to be able to - * create any kind of {@link Reply}. - * - * @param - * The type of the builder - * @author David ‘Bombe’ Roden - */ -public interface ReplyBuilder> { - - /** - * Configures this builder to use a random ID when creating the reply. If - * this method is used, {@link #withId(String)} must not be used. - * - * @return This builder - */ - public B randomId(); - - /** - * Configures this builder to use the given ID when creating the reply. If - * this method is used, {@link #randomId()} must not be used. - * - * @param id - * The ID of the reply - * @return This builder - */ - public B withId(String id); - - /** - * Configures this builder to use the ID of the given {@link Sone} as sender - * of the reply. - * - * @param senderId - * The ID of the sender of the reply - * @return This builder - */ - public B from(String senderId); - - /** - * Configures this builder to use the current time when creating the reply. - * If this method is used, {@link #withTime(long)} must not be used. - * - * @return This builder - */ - public B currentTime(); - - /** - * Configures this builder to use the given time when creating the reply. If - * this method is used, {@link #currentTime()} must not be used. - * - * @param time - * The time of the reply - * @return This builder - */ - public B withTime(long time); - - /** - * Configures this builder to use the given text when creating the reply. - * - * @param text - * The text of the reply - * @return This builder - */ - public B withText(String text); - -} diff --git a/src/main/kotlin/net/pterodactylus/sone/database/PostReplyBuilder.kt b/src/main/kotlin/net/pterodactylus/sone/database/PostReplyBuilder.kt new file mode 100644 index 0000000..0c333da --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/database/PostReplyBuilder.kt @@ -0,0 +1,46 @@ +/* + * Sone - PostReplyBuilder.java - Copyright © 2013–2016 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.database + +import net.pterodactylus.sone.data.PostReply + +/** + * Builder for a [PostReply] object. + */ +interface PostReplyBuilder : ReplyBuilder { + + fun to(postId: String): PostReplyBuilder + + /** + * Verifies the configuration of this builder and creates a new post reply. + * + * The following conditions must be met in order for the configuration to be + * considered valid: + * + * * Exactly one of [randomId] or [withId] must have been called. + * * The [sender][from] must not be `null`. + * * Exactly one of [currentTime] or [withTime] must have been called. + * * The [text][withText] must not be `null` and must contain something other than whitespace. + * * The [post][to] must have been set. + * + * @return The created post reply + * @throws IllegalStateException if this builder’s configuration is not valid + */ + fun build(): PostReply + +} diff --git a/src/main/kotlin/net/pterodactylus/sone/database/PostReplyBuilderFactory.kt b/src/main/kotlin/net/pterodactylus/sone/database/PostReplyBuilderFactory.kt new file mode 100644 index 0000000..d039cda --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/database/PostReplyBuilderFactory.kt @@ -0,0 +1,32 @@ +/* + * Sone - PostReplyBuilderFactory.java - Copyright © 2013–2016 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.database + +import net.pterodactylus.sone.database.memory.MemoryDatabase + +import com.google.inject.ImplementedBy + +/** + * Factory for [PostReplyBuilder]s. + */ +@ImplementedBy(MemoryDatabase::class) +interface PostReplyBuilderFactory { + + fun newPostReplyBuilder(): PostReplyBuilder + +} diff --git a/src/main/kotlin/net/pterodactylus/sone/database/PostReplyDatabase.kt b/src/main/kotlin/net/pterodactylus/sone/database/PostReplyDatabase.kt new file mode 100644 index 0000000..8f08cf3 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/database/PostReplyDatabase.kt @@ -0,0 +1,24 @@ +/* + * Sone - PostReplyDatabase.java - Copyright © 2013–2016 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.database + +/** + * Combines a [PostReplyProvider], a [PostReplyBuilderFactory], and + * a [PostReplyStore] into a complete post reply database. + */ +interface PostReplyDatabase : PostReplyProvider, PostReplyBuilderFactory, PostReplyStore diff --git a/src/main/kotlin/net/pterodactylus/sone/database/PostReplyProvider.kt b/src/main/kotlin/net/pterodactylus/sone/database/PostReplyProvider.kt new file mode 100644 index 0000000..57e8df7 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/database/PostReplyProvider.kt @@ -0,0 +1,38 @@ +/* + * Sone - PostReplyProvider.java - Copyright © 2013–2016 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.database + +import com.google.common.base.Optional +import net.pterodactylus.sone.data.PostReply + +/** + * Interface for objects that can provide [PostReply]s. + */ +interface PostReplyProvider { + + fun getPostReply(id: String): Optional + + /** + * Returns all replies for the given post, order ascending by time. + * + * @param postId The ID of the post to get all replies for + * @return All replies for the given post + */ + fun getReplies(postId: String): List + +} diff --git a/src/main/kotlin/net/pterodactylus/sone/database/PostReplyStore.kt b/src/main/kotlin/net/pterodactylus/sone/database/PostReplyStore.kt new file mode 100644 index 0000000..08ba380 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/database/PostReplyStore.kt @@ -0,0 +1,31 @@ +/* + * Sone - PostReplyStore.java - Copyright © 2013–2016 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.database + +import net.pterodactylus.sone.data.PostReply +import net.pterodactylus.sone.data.Sone + +/** + * Defines a store for [post replies][PostReply]. + */ +interface PostReplyStore { + + fun storePostReply(postReply: PostReply) + fun removePostReply(postReply: PostReply) + +} diff --git a/src/main/kotlin/net/pterodactylus/sone/database/ReplyBuilder.kt b/src/main/kotlin/net/pterodactylus/sone/database/ReplyBuilder.kt new file mode 100644 index 0000000..1aa6039 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/database/ReplyBuilder.kt @@ -0,0 +1,39 @@ +/* + * Sone - ReplyBuilder.java - Copyright © 2013–2016 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone.database + +import net.pterodactylus.sone.data.Reply +import net.pterodactylus.sone.data.Sone + +/** + * Methods that all reply builders need to implement in order to be able to + * create any kind of [Reply]. + * + * @param B The type of the builder + */ +interface ReplyBuilder> { + + fun randomId(): B + fun withId(id: String): B + + fun from(senderId: String): B + fun currentTime(): B + fun withTime(time: Long): B + fun withText(text: String): B + +} -- 2.7.4