From 4acdae8d247379dedcc5d41c8aded9503fcbaf72 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 22 Jan 2013 15:39:38 +0100 Subject: [PATCH] Move builder and factories to database package. --- .../java/net/pterodactylus/sone/core/Core.java | 8 +- .../pterodactylus/sone/core/SoneDownloader.java | 4 +- .../net/pterodactylus/sone/data/PostBuilder.java | 141 -------------------- .../sone/data/PostBuilderFactory.java | 34 ----- .../pterodactylus/sone/data/PostReplyBuilder.java | 59 --------- .../sone/data/PostReplyBuilderFactory.java | 34 ----- .../net/pterodactylus/sone/data/ReplyBuilder.java | 85 ------------ .../sone/data/impl/AbstractReplyBuilder.java | 2 +- .../sone/data/impl/DefaultPostBuilderFactory.java | 4 +- .../data/impl/DefaultPostReplyBuilderFactory.java | 4 +- .../sone/data/impl/PostBuilderImpl.java | 2 +- .../sone/data/impl/PostReplyBuilderImpl.java | 2 +- .../pterodactylus/sone/database/PostBuilder.java | 144 +++++++++++++++++++++ .../sone/database/PostBuilderFactory.java | 34 +++++ .../sone/database/PostReplyBuilder.java | 61 +++++++++ .../sone/database/PostReplyBuilderFactory.java | 34 +++++ .../pterodactylus/sone/database/ReplyBuilder.java | 88 +++++++++++++ .../net/pterodactylus/sone/main/SonePlugin.java | 4 +- 18 files changed, 376 insertions(+), 368 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/sone/data/PostBuilder.java delete mode 100644 src/main/java/net/pterodactylus/sone/data/PostBuilderFactory.java delete mode 100644 src/main/java/net/pterodactylus/sone/data/PostReplyBuilder.java delete mode 100644 src/main/java/net/pterodactylus/sone/data/PostReplyBuilderFactory.java delete mode 100644 src/main/java/net/pterodactylus/sone/data/ReplyBuilder.java create mode 100644 src/main/java/net/pterodactylus/sone/database/PostBuilder.java create mode 100644 src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java create mode 100644 src/main/java/net/pterodactylus/sone/database/PostReplyBuilder.java create mode 100644 src/main/java/net/pterodactylus/sone/database/PostReplyBuilderFactory.java create mode 100644 src/main/java/net/pterodactylus/sone/database/ReplyBuilder.java diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 7f62685..fb3c8a9 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -56,18 +56,18 @@ import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Client; import net.pterodactylus.sone.data.Image; import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.PostBuilder; -import net.pterodactylus.sone.data.PostBuilderFactory; import net.pterodactylus.sone.data.PostReply; -import net.pterodactylus.sone.data.PostReplyBuilder; -import net.pterodactylus.sone.data.PostReplyBuilderFactory; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.Sone.ShowCustomAvatars; import net.pterodactylus.sone.data.Sone.SoneStatus; +import net.pterodactylus.sone.database.PostBuilder; +import net.pterodactylus.sone.database.PostBuilderFactory; import net.pterodactylus.sone.database.PostProvider; +import net.pterodactylus.sone.database.PostReplyBuilder; +import net.pterodactylus.sone.database.PostReplyBuilderFactory; import net.pterodactylus.sone.database.PostReplyProvider; import net.pterodactylus.sone.database.SoneProvider; import net.pterodactylus.sone.data.TemporaryImage; diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index 388d804..aa2aa99 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -31,12 +31,12 @@ import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Client; import net.pterodactylus.sone.data.Image; import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.PostBuilder; import net.pterodactylus.sone.data.PostReply; -import net.pterodactylus.sone.data.PostReplyBuilder; import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.data.Sone.SoneStatus; +import net.pterodactylus.sone.database.PostBuilder; +import net.pterodactylus.sone.database.PostReplyBuilder; import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.number.Numbers; diff --git a/src/main/java/net/pterodactylus/sone/data/PostBuilder.java b/src/main/java/net/pterodactylus/sone/data/PostBuilder.java deleted file mode 100644 index 87d02ee..0000000 --- a/src/main/java/net/pterodactylus/sone/data/PostBuilder.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Sone - PostBuilder.java - Copyright © 2013 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.data; - -/** - * Builder for {@link Post} objects. - *

- * A {@link Post} consists of the following elements: - *

- * Except for the recipient, all this elements have to be configured on this - * builder. For the ID you have the possibility to configure either a random ID - * (which should be used for new posts) or a custom ID you specify (for creating - * an existing post). For the time you can use the current time (again, for - * creating new posts) or the given time (for loading posts). It is an error to - * specify both ways for either the ID or the time. - * - * @author David ‘Bombe’ Roden - */ -public interface PostBuilder { - - /** - * Copies all attributes of the given post to this post builder. - * - * @param post - * The post whose attributes to copy into this builder - * @return This builder - * @throws NullPointerException - * if {@code post} is {@code null} - */ - public PostBuilder copyPost(Post post) throws NullPointerException; - - /** - * Configures this builder to use the given Sone as sender of the new post. - * - * @param senderId - * The ID of the sender of the post - * @return This post builder - */ - public PostBuilder from(String senderId); - - /** - * Configures this builder to use a random ID for the new post. If this - * method is used, {@link #withId(String)} must not be used. - * - * @return This post builder - */ - public PostBuilder randomId(); - - /** - * Configures this builder to use the given ID as ID for the new post. If - * this method is used, {@link #randomId()} must not be used. - * - * @param id - * The ID to use for the post - * @return This post builder - */ - public PostBuilder withId(String id); - - /** - * Configures this builder to use the current time when creating the post. - * If this method is used, {@link #withTime(long)} must not be used. - * - * @return This post builder - */ - public PostBuilder currentTime(); - - /** - * Configures the builder to use the given time as time for the new post. If - * this method is used, {@link #currentTime()} must not be used. - * - * @param time - * The time to use for the post - * @return This post builder - */ - public PostBuilder withTime(long time); - - /** - * Configures the builder to use the given text for the new post. - * - * @param text - * The text to use for the post - * @return This post builder - */ - public PostBuilder withText(String text); - - /** - * Configures the builder to use the given {@link Sone} as recipient for the - * post. - * - * @param recipientId - * The ID of the recipient of the post - * @return This post builder - */ - public PostBuilder to(String recipientId); - - /** - * Verifies this builder’s configuration and creates a new post. - *

- * The following conditions must be met in order for this builder to be - * configured correctly: - *

- * - * @return A new post - * @throws IllegalStateException - * if this builder’s configuration is not valid - */ - public Post build() throws IllegalStateException; - -} diff --git a/src/main/java/net/pterodactylus/sone/data/PostBuilderFactory.java b/src/main/java/net/pterodactylus/sone/data/PostBuilderFactory.java deleted file mode 100644 index 845cdf6..0000000 --- a/src/main/java/net/pterodactylus/sone/data/PostBuilderFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Sone - PostBuilderFactory.java - Copyright © 2013 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.data; - -/** - * Factory for {@link PostBuilder}s. - * - * @author David ‘Bombe’ Roden - */ -public interface PostBuilderFactory { - - /** - * Creates a new post builder. - * - * @return A new post builder - */ - public PostBuilder newPostBuilder(); - -} diff --git a/src/main/java/net/pterodactylus/sone/data/PostReplyBuilder.java b/src/main/java/net/pterodactylus/sone/data/PostReplyBuilder.java deleted file mode 100644 index 09eb98a..0000000 --- a/src/main/java/net/pterodactylus/sone/data/PostReplyBuilder.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Sone - PostReplyBuilder.java - Copyright © 2013 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.data; - -/** - * 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/data/PostReplyBuilderFactory.java b/src/main/java/net/pterodactylus/sone/data/PostReplyBuilderFactory.java deleted file mode 100644 index 17a92f3..0000000 --- a/src/main/java/net/pterodactylus/sone/data/PostReplyBuilderFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Sone - PostReplyBuilderFactory.java - Copyright © 2013 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.data; - -/** - * Factory for {@link PostReplyBuilder}s. - * - * @author David ‘Bombe’ Roden - */ -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/data/ReplyBuilder.java b/src/main/java/net/pterodactylus/sone/data/ReplyBuilder.java deleted file mode 100644 index fa0aac8..0000000 --- a/src/main/java/net/pterodactylus/sone/data/ReplyBuilder.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Sone - ReplyBuilder.java - Copyright © 2013 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.data; - -/** - * 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/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java b/src/main/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java index 25dd1e1..2a68a13 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java @@ -17,7 +17,7 @@ package net.pterodactylus.sone.data.impl; -import net.pterodactylus.sone.data.ReplyBuilder; +import net.pterodactylus.sone.database.ReplyBuilder; /** * Abstract implementation of a {@link ReplyBuilder}. diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilderFactory.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilderFactory.java index fd17ec3..567708b 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilderFactory.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilderFactory.java @@ -17,8 +17,8 @@ package net.pterodactylus.sone.data.impl; -import net.pterodactylus.sone.data.PostBuilder; -import net.pterodactylus.sone.data.PostBuilderFactory; +import net.pterodactylus.sone.database.PostBuilder; +import net.pterodactylus.sone.database.PostBuilderFactory; import net.pterodactylus.sone.database.SoneProvider; /** diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostReplyBuilderFactory.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostReplyBuilderFactory.java index 1b8bab2..e326304 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostReplyBuilderFactory.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostReplyBuilderFactory.java @@ -17,9 +17,9 @@ package net.pterodactylus.sone.data.impl; -import net.pterodactylus.sone.data.PostReplyBuilder; -import net.pterodactylus.sone.data.PostReplyBuilderFactory; import net.pterodactylus.sone.database.PostProvider; +import net.pterodactylus.sone.database.PostReplyBuilder; +import net.pterodactylus.sone.database.PostReplyBuilderFactory; import net.pterodactylus.sone.database.SoneProvider; import com.google.inject.Inject; diff --git a/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java index 32f4eb4..6713827 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java @@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkState; import java.util.UUID; import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.PostBuilder; +import net.pterodactylus.sone.database.PostBuilder; import net.pterodactylus.sone.database.SoneProvider; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/net/pterodactylus/sone/data/impl/PostReplyBuilderImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/PostReplyBuilderImpl.java index c553bc3..da18f96 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/PostReplyBuilderImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/PostReplyBuilderImpl.java @@ -22,8 +22,8 @@ import static com.google.common.base.Preconditions.checkState; import java.util.UUID; import net.pterodactylus.sone.data.PostReply; -import net.pterodactylus.sone.data.PostReplyBuilder; import net.pterodactylus.sone.database.PostProvider; +import net.pterodactylus.sone.database.PostReplyBuilder; import net.pterodactylus.sone.database.SoneProvider; import org.apache.commons.lang.StringUtils; diff --git a/src/main/java/net/pterodactylus/sone/database/PostBuilder.java b/src/main/java/net/pterodactylus/sone/database/PostBuilder.java new file mode 100644 index 0000000..449147a --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/database/PostBuilder.java @@ -0,0 +1,144 @@ +/* + * Sone - PostBuilder.java - Copyright © 2013 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.Post; +import net.pterodactylus.sone.data.Sone; + +/** + * Builder for {@link Post} objects. + *

+ * A {@link Post} consists of the following elements: + *

    + *
  • an ID,
  • + *
  • a {@link Sone sender},
  • + *
  • an optional {@link Sone recipient},
  • + *
  • a time,
  • + *
  • and a text.
  • + *
+ * Except for the recipient, all this elements have to be configured on this + * builder. For the ID you have the possibility to configure either a random ID + * (which should be used for new posts) or a custom ID you specify (for creating + * an existing post). For the time you can use the current time (again, for + * creating new posts) or the given time (for loading posts). It is an error to + * specify both ways for either the ID or the time. + * + * @author David ‘Bombe’ Roden + */ +public interface PostBuilder { + + /** + * Copies all attributes of the given post to this post builder. + * + * @param post + * The post whose attributes to copy into this builder + * @return This builder + * @throws NullPointerException + * if {@code post} is {@code null} + */ + public PostBuilder copyPost(Post post) throws NullPointerException; + + /** + * Configures this builder to use the given Sone as sender of the new post. + * + * @param senderId + * The ID of the sender of the post + * @return This post builder + */ + public PostBuilder from(String senderId); + + /** + * Configures this builder to use a random ID for the new post. If this + * method is used, {@link #withId(String)} must not be used. + * + * @return This post builder + */ + public PostBuilder randomId(); + + /** + * Configures this builder to use the given ID as ID for the new post. If + * this method is used, {@link #randomId()} must not be used. + * + * @param id + * The ID to use for the post + * @return This post builder + */ + public PostBuilder withId(String id); + + /** + * Configures this builder to use the current time when creating the post. + * If this method is used, {@link #withTime(long)} must not be used. + * + * @return This post builder + */ + public PostBuilder currentTime(); + + /** + * Configures the builder to use the given time as time for the new post. If + * this method is used, {@link #currentTime()} must not be used. + * + * @param time + * The time to use for the post + * @return This post builder + */ + public PostBuilder withTime(long time); + + /** + * Configures the builder to use the given text for the new post. + * + * @param text + * The text to use for the post + * @return This post builder + */ + public PostBuilder withText(String text); + + /** + * Configures the builder to use the given {@link Sone} as recipient for the + * post. + * + * @param recipientId + * The ID of the recipient of the post + * @return This post builder + */ + public PostBuilder to(String recipientId); + + /** + * Verifies this builder’s configuration and creates a new post. + *

+ * The following conditions must be met in order for this builder to be + * configured correctly: + *

    + *
  • 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) recipient} must either not have been set, or + * it must have been set to a {@link Sone} other than {@link #from(String) + * the sender}.
  • + *
+ * + * @return A new post + * @throws IllegalStateException + * if this builder’s configuration is not valid + */ + public Post build() throws IllegalStateException; + +} diff --git a/src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java b/src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java new file mode 100644 index 0000000..b89ae28 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java @@ -0,0 +1,34 @@ +/* + * Sone - PostBuilderFactory.java - Copyright © 2013 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; + +/** + * Factory for {@link PostBuilder}s. + * + * @author David ‘Bombe’ Roden + */ +public interface PostBuilderFactory { + + /** + * Creates a new post builder. + * + * @return A new post builder + */ + public PostBuilder newPostBuilder(); + +} diff --git a/src/main/java/net/pterodactylus/sone/database/PostReplyBuilder.java b/src/main/java/net/pterodactylus/sone/database/PostReplyBuilder.java new file mode 100644 index 0000000..c031443 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/database/PostReplyBuilder.java @@ -0,0 +1,61 @@ +/* + * Sone - PostReplyBuilder.java - Copyright © 2013 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 new file mode 100644 index 0000000..7fd4ae1 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/database/PostReplyBuilderFactory.java @@ -0,0 +1,34 @@ +/* + * Sone - PostReplyBuilderFactory.java - Copyright © 2013 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; + +/** + * Factory for {@link PostReplyBuilder}s. + * + * @author David ‘Bombe’ Roden + */ +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/ReplyBuilder.java b/src/main/java/net/pterodactylus/sone/database/ReplyBuilder.java new file mode 100644 index 0000000..d83e7ce --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/database/ReplyBuilder.java @@ -0,0 +1,88 @@ +/* + * Sone - ReplyBuilder.java - Copyright © 2013 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/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index 36e49d1..10992a6 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -25,11 +25,11 @@ import java.util.logging.Logger; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.core.FreenetInterface; import net.pterodactylus.sone.core.WebOfTrustUpdater; -import net.pterodactylus.sone.data.PostBuilderFactory; -import net.pterodactylus.sone.data.PostReplyBuilderFactory; import net.pterodactylus.sone.data.impl.DefaultPostBuilderFactory; import net.pterodactylus.sone.data.impl.DefaultPostReplyBuilderFactory; +import net.pterodactylus.sone.database.PostBuilderFactory; import net.pterodactylus.sone.database.PostProvider; +import net.pterodactylus.sone.database.PostReplyBuilderFactory; import net.pterodactylus.sone.database.SoneProvider; import net.pterodactylus.sone.fcp.FcpInterface; import net.pterodactylus.sone.freenet.PluginStoreConfigurationBackend; -- 2.7.4