From f6816b0b1519a69a68fc280ee7d21d7ab0607289 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 15 Oct 2013 07:23:08 +0200 Subject: [PATCH] Use database instead of Sone provider in post and post builder. --- .../sone/data/impl/DefaultPostBuilder.java | 13 ++++++------ .../sone/data/impl/DefaultPostBuilderFactory.java | 23 ++++++++++------------ .../net/pterodactylus/sone/data/impl/PostImpl.java | 17 ++++++++-------- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilder.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilder.java index bf1c1e7..9ac82c8 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilder.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilder.java @@ -20,8 +20,8 @@ package net.pterodactylus.sone.data.impl; import java.util.UUID; import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.database.Database; import net.pterodactylus.sone.database.PostBuilder; -import net.pterodactylus.sone.database.SoneProvider; /** * {@link PostBuilder} implementation that creates {@link PostImpl} objects. @@ -30,23 +30,22 @@ import net.pterodactylus.sone.database.SoneProvider; */ public class DefaultPostBuilder extends AbstractPostBuilder { - private final SoneProvider soneProvider; + private final Database database; /** * Creates a new post builder. * - * @param soneProvider - * The Sone provider + * @param database */ - public DefaultPostBuilder(SoneProvider soneProvider) { - this.soneProvider = soneProvider; + public DefaultPostBuilder(Database database) { + this.database = database; } /** {@inheritDoc} */ @Override public Post build() { validate(); - return new PostImpl(soneProvider, randomId ? UUID.randomUUID().toString() : id, senderId, recipientId, currentTime ? System.currentTimeMillis() : time, text); + return new PostImpl(database, randomId ? UUID.randomUUID().toString() : id, senderId, recipientId, currentTime ? System.currentTimeMillis() : time, text); } } 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 72c4eb4..83548bd 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilderFactory.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilderFactory.java @@ -17,40 +17,37 @@ package net.pterodactylus.sone.data.impl; +import net.pterodactylus.sone.database.Database; import net.pterodactylus.sone.database.PostBuilder; import net.pterodactylus.sone.database.PostBuilderFactory; -import net.pterodactylus.sone.database.SoneProvider; import com.google.inject.Inject; /** - * {@link PostBuilderFactory} implementation that creates - * {@link DefaultPostBuilder}s. + * {@link PostBuilderFactory} implementation that creates {@link + * DefaultPostBuilder}s. * * @author David ‘Bombe’ Roden */ public class DefaultPostBuilderFactory implements PostBuilderFactory { - /** The Sone provider. */ - private final SoneProvider soneProvider; + private final Database database; /** * Creates a new default post builder factory. * - * @param soneProvider - * The Sone provider + * @param database + * The database */ @Inject - public DefaultPostBuilderFactory(SoneProvider soneProvider) { - this.soneProvider = soneProvider; + public DefaultPostBuilderFactory(Database database) { + this.database = database; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public PostBuilder newPostBuilder() { - return new DefaultPostBuilder(soneProvider); + return new DefaultPostBuilder(database); } } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java index 2d25715..f0f9d35 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java @@ -21,7 +21,7 @@ import java.util.UUID; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.database.SoneProvider; +import net.pterodactylus.sone.database.Database; import com.google.common.base.Optional; @@ -33,8 +33,7 @@ import com.google.common.base.Optional; */ public class PostImpl implements Post { - /** The Sone provider. */ - private final SoneProvider soneProvider; + private final Database database; /** The GUID of the post. */ private final UUID id; @@ -57,8 +56,8 @@ public class PostImpl implements Post { /** * Creates a new post. * - * @param soneProvider - * The Sone provider + * @param database + * The database * @param id * The ID of the post * @param soneId @@ -70,8 +69,8 @@ public class PostImpl implements Post { * @param text * The text of the post */ - public PostImpl(SoneProvider soneProvider, String id, String soneId, String recipientId, long time, String text) { - this.soneProvider = soneProvider; + public PostImpl(Database database, String id, String soneId, String recipientId, long time, String text) { + this.database = database; this.id = UUID.fromString(id); this.soneId = soneId; this.recipientId = recipientId; @@ -96,7 +95,7 @@ public class PostImpl implements Post { */ @Override public Sone getSone() { - return soneProvider.getSone(soneId).get(); + return database.getSone(soneId).get(); } /** @@ -112,7 +111,7 @@ public class PostImpl implements Post { */ @Override public Optional getRecipient() { - return soneProvider.getSone(recipientId); + return database.getSone(recipientId); } /** -- 2.7.4