From: David ‘Bombe’ Roden Date: Sun, 13 Oct 2013 16:42:59 +0000 (+0200) Subject: Don’t store sone provider in abstract post builder. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=ed19f10e7931fb0b09c042c6070e37dffb23ceac;p=Sone.git Don’t store sone provider in abstract post builder. --- diff --git a/src/main/java/net/pterodactylus/sone/data/impl/AbstractPostBuilder.java b/src/main/java/net/pterodactylus/sone/data/impl/AbstractPostBuilder.java index 3a56dc9..0bc7a59 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/AbstractPostBuilder.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/AbstractPostBuilder.java @@ -19,11 +19,10 @@ package net.pterodactylus.sone.data.impl; import static com.google.common.base.Preconditions.checkState; -import org.apache.commons.lang.StringUtils; - import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.database.PostBuilder; -import net.pterodactylus.sone.database.SoneProvider; + +import org.apache.commons.lang.StringUtils; /** * Abstract {@link PostBuilder} implementation. It stores the state of the new @@ -33,9 +32,6 @@ import net.pterodactylus.sone.database.SoneProvider; */ public abstract class AbstractPostBuilder implements PostBuilder { - /** The Sone provider for the created posts. */ - protected final SoneProvider soneProvider; - /** Wether to create a post with a random ID. */ protected boolean randomId; @@ -57,16 +53,6 @@ public abstract class AbstractPostBuilder implements PostBuilder { /** The (optional) recipient of the post. */ protected String recipientId; - /** - * Creates a new abstract post builder. - * - * @param soneProvider - * The Sone provider - */ - public AbstractPostBuilder(SoneProvider soneProvider) { - this.soneProvider = soneProvider; - } - // // POSTBUILDER METHODS // 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 88a2d71..6d5d70f 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java @@ -30,19 +30,19 @@ import net.pterodactylus.sone.database.SoneProvider; */ public class PostBuilderImpl extends AbstractPostBuilder { + private final SoneProvider soneProvider; + /** * Creates a new post builder. * * @param soneProvider - * The Sone provider + * The Sone provider */ public PostBuilderImpl(SoneProvider soneProvider) { - super(soneProvider); + this.soneProvider = soneProvider; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public Post build() { validate(); diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index 6cb0027..34c819d 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -202,7 +202,7 @@ public class MemoryDatabase extends AbstractService implements Database { /** {@inheritDocs} */ @Override public PostBuilder newPostBuilder() { - return new MemoryPostBuilder(this, soneProvider); + return new MemoryPostBuilder(this); } // diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryPost.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPost.java index 22fa7e6..2834951 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryPost.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPost.java @@ -21,7 +21,6 @@ import java.util.UUID; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Sone; -import net.pterodactylus.sone.database.SoneProvider; import com.google.common.base.Optional; @@ -34,10 +33,7 @@ import com.google.common.base.Optional; class MemoryPost implements Post { /** The post database. */ - private final MemoryDatabase postDatabase; - - /** The Sone provider. */ - private final SoneProvider soneProvider; + private final MemoryDatabase memoryDatabase; /** The GUID of the post. */ private final UUID id; @@ -57,24 +53,21 @@ class MemoryPost implements Post { /** * Creates a new post. * - * @param postDatabase - * The post database - * @param soneProvider - * The Sone provider + * @param memoryDatabase + * The database * @param id - * The ID of the post + * The ID of the post * @param soneId - * The ID of the Sone this post belongs to + * The ID of the Sone this post belongs to * @param recipientId - * The ID of the recipient of the post + * The ID of the recipient of the post * @param time - * The time of the post (in milliseconds since Jan 1, 1970 UTC) + * The time of the post (in milliseconds since Jan 1, 1970 UTC) * @param text - * The text of the post + * The text of the post */ - public MemoryPost(MemoryDatabase postDatabase, SoneProvider soneProvider, String id, String soneId, String recipientId, long time, String text) { - this.postDatabase = postDatabase; - this.soneProvider = soneProvider; + public MemoryPost(MemoryDatabase memoryDatabase, String id, String soneId, String recipientId, long time, String text) { + this.memoryDatabase = memoryDatabase; this.id = UUID.fromString(id); this.soneId = soneId; this.recipientId = recipientId; @@ -86,68 +79,52 @@ class MemoryPost implements Post { // ACCESSORS // - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public String getId() { return id.toString(); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public Sone getSone() { - return soneProvider.getSone(soneId).get(); + return memoryDatabase.getSone(soneId).get(); } - /** - * {@inheritDocs} - */ + /** {@inheritDocs} */ @Override public Optional getRecipientId() { return Optional.fromNullable(recipientId); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public Optional getRecipient() { - return soneProvider.getSone(recipientId); + return memoryDatabase.getSone(recipientId); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public long getTime() { return time; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public String getText() { return text; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public boolean isKnown() { - return postDatabase.isPostKnown(this); + return memoryDatabase.isPostKnown(this); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public MemoryPost setKnown(boolean known) { - postDatabase.setPostKnown(this, known); + memoryDatabase.setPostKnown(this, known); return this; } @@ -155,17 +132,13 @@ class MemoryPost implements Post { // OBJECT METHODS // - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public int hashCode() { return id.hashCode(); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public boolean equals(Object object) { if (!(object instanceof MemoryPost)) { @@ -175,9 +148,7 @@ class MemoryPost implements Post { return post.id.equals(id); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public String toString() { return String.format("%s[id=%s,sone=%s,recipient=%s,time=%d,text=%s]", getClass().getName(), id, soneId, recipientId, time, text); diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostBuilder.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostBuilder.java index d0b2c9f..a7afcdc 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostBuilder.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostBuilder.java @@ -42,8 +42,7 @@ class MemoryPostBuilder extends AbstractPostBuilder { * @param soneProvider * The Sone provider */ - public MemoryPostBuilder(MemoryDatabase memoryDatabase, SoneProvider soneProvider) { - super(soneProvider); + public MemoryPostBuilder(MemoryDatabase memoryDatabase) { database = memoryDatabase; } @@ -53,7 +52,7 @@ class MemoryPostBuilder extends AbstractPostBuilder { @Override public Post build() throws IllegalStateException { validate(); - Post post = new MemoryPost(database, soneProvider, randomId ? UUID.randomUUID().toString() : id, senderId, recipientId, currentTime ? System.currentTimeMillis() : time, text); + Post post = new MemoryPost(database, randomId ? UUID.randomUUID().toString() : id, senderId, recipientId, currentTime ? System.currentTimeMillis() : time, text); post.setKnown(database.isPostKnown(post)); return post; }