From: David ‘Bombe’ Roden Date: Thu, 17 Jan 2013 13:13:49 +0000 (+0100) Subject: Extract Reply and PostReply interfaces. X-Git-Tag: 0.8.5^2~3^2~76 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=dc07688d67850c90b7adda025a41d42b62d15f9e;p=Sone.git Extract Reply and PostReply interfaces. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index ce7f0ce..8e20a27 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -63,6 +63,7 @@ import net.pterodactylus.sone.data.Sone.ShowCustomAvatars; import net.pterodactylus.sone.data.Sone.SoneStatus; import net.pterodactylus.sone.data.TemporaryImage; import net.pterodactylus.sone.data.impl.PostImpl; +import net.pterodactylus.sone.data.impl.PostReplyImpl; import net.pterodactylus.sone.fcp.FcpInterface; import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired; import net.pterodactylus.sone.freenet.wot.Identity; @@ -579,7 +580,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider synchronized (replies) { PostReply reply = replies.get(replyId); if (create && (reply == null)) { - reply = new PostReply(replyId); + reply = new PostReplyImpl(replyId); replies.put(replyId, reply); } return reply; @@ -1679,7 +1680,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider logger.log(Level.FINE, String.format("Tried to create reply for non-local Sone: %s", sone)); return null; } - final PostReply reply = new PostReply(sone, post, System.currentTimeMillis(), text.trim()); + final PostReply reply = new PostReplyImpl(sone, post, System.currentTimeMillis(), text.trim()); synchronized (replies) { replies.put(reply.getId(), reply); } diff --git a/src/main/java/net/pterodactylus/sone/data/PostReply.java b/src/main/java/net/pterodactylus/sone/data/PostReply.java index 0f63be1..4c7c8d3 100644 --- a/src/main/java/net/pterodactylus/sone/data/PostReply.java +++ b/src/main/java/net/pterodactylus/sone/data/PostReply.java @@ -1,5 +1,5 @@ /* - * Sone - PostReply.java - Copyright © 2010–2012 David Roden + * Sone - PostReply.java - Copyright © 2010–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 @@ -17,101 +17,28 @@ package net.pterodactylus.sone.data; -import java.util.UUID; - /** * A reply is like a {@link Post} but can never be posted on its own, it always * refers to another {@link Post}. * * @author David ‘Bombe’ Roden */ -public class PostReply extends Reply { - - /** The Post this reply refers to. */ - private volatile Post post; - - /** - * Creates a new reply. - * - * @param id - * The ID of the reply - */ - public PostReply(String id) { - this(id, null, null, 0, null); - } - - /** - * Creates a new reply. - * - * @param sone - * The sone that posted the reply - * @param post - * The post to reply to - * @param text - * The text of the reply - */ - public PostReply(Sone sone, Post post, String text) { - this(sone, post, System.currentTimeMillis(), text); - } - - /** - * Creates a new reply- - * - * @param sone - * The sone that posted the reply - * @param post - * The post to reply to - * @param time - * The time of the reply - * @param text - * The text of the reply - */ - public PostReply(Sone sone, Post post, long time, String text) { - this(UUID.randomUUID().toString(), sone, post, time, text); - } - - /** - * Creates a new reply- - * - * @param sone - * The sone that posted the reply - * @param id - * The ID of the reply - * @param post - * The post to reply to - * @param time - * The time of the reply - * @param text - * The text of the reply - */ - public PostReply(String id, Sone sone, Post post, long time, String text) { - super(id, sone, time, text); - this.post = post; - } - - // - // ACCESSORS - // +public interface PostReply extends Reply { /** * Returns the post this reply refers to. * * @return The post this reply refers to */ - public Post getPost() { - return post; - } + public Post getPost(); /** * Sets the post this reply refers to. * * @param post * The post this reply refers to - * @return This reply (for method chaining) + * @return This reply */ - public PostReply setPost(Post post) { - this.post = post; - return this; - } + public PostReply setPost(Post post); -} +} \ No newline at end of file diff --git a/src/main/java/net/pterodactylus/sone/data/Reply.java b/src/main/java/net/pterodactylus/sone/data/Reply.java index f6e4a2c..cb7ac94 100644 --- a/src/main/java/net/pterodactylus/sone/data/Reply.java +++ b/src/main/java/net/pterodactylus/sone/data/Reply.java @@ -1,5 +1,5 @@ /* - * Sone - Reply.java - Copyright © 2011–2012 David Roden + * Sone - Reply.java - Copyright © 2010–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 @@ -18,21 +18,20 @@ package net.pterodactylus.sone.data; import java.util.Comparator; -import java.util.UUID; import com.google.common.base.Predicate; /** - * Abstract base class for all replies. + * Defines methods common for all replies. * * @param * The type of the reply * @author David ‘Bombe’ Roden */ -public abstract class Reply> { +public interface Reply> { /** Comparator that sorts replies ascending by time. */ - public static final Comparator> TIME_COMPARATOR = new Comparator>() { + public static final Comparator> TIME_COMPARATOR = new Comparator>() { /** * {@inheritDoc} @@ -57,147 +56,67 @@ public abstract class Reply> { }; - /** The ID of the reply. */ - private final String id; - - /** The Sone that created this reply. */ - private volatile Sone sone; - - /** The time of the reply. */ - private volatile long time; - - /** The text of the reply. */ - private volatile String text; - - /** Whether the reply is known. */ - private volatile boolean known; - - /** - * Creates a new reply with the given ID. - * - * @param id - * The ID of the reply - */ - protected Reply(String id) { - this(id, null, 0, null); - } - - /** - * Creates a new reply with a new random ID. - * - * @param sone - * The Sone of the reply - * @param time - * The time of the reply - * @param text - * The text of the reply - */ - protected Reply(Sone sone, long time, String text) { - this(UUID.randomUUID().toString(), sone, time, text); - } - - /** - * Creates a new reply. - * - * @param id - * The ID of the reply - * @param sone - * The Sone of the reply - * @param time - * The time of the reply - * @param text - * The text of the reply - */ - protected Reply(String id, Sone sone, long time, String text) { - this.id = id; - this.sone = sone; - this.time = time; - this.text = text; - } - /** * Returns the ID of the reply. * * @return The ID of the reply */ - public String getId() { - return id; - } + public String getId(); /** * Returns the Sone that posted this reply. * * @return The Sone that posted this reply */ - public Sone getSone() { - return sone; - } + public Sone getSone(); /** * Sets the Sone that posted this reply. * * @param sone * The Sone that posted this reply - * @return This reply (for method chaining) + * @return This reply */ - @SuppressWarnings("unchecked") - public T setSone(Sone sone) { - this.sone = sone; - return (T) this; - } + public T setSone(Sone sone); /** * Returns the time of the reply. * * @return The time of the reply (in milliseconds since Jan 1, 1970 UTC) */ - public long getTime() { - return time; - } + public long getTime(); /** - * Sets the time of this reply. + * Sets the time of the reply. * * @param time - * The time of this reply (in milliseconds since Jan 1, 1970 UTC) - * @return This reply (for method chaining) + * The time of the reply (in milliseconds since Jan 1, 1970 UTC) + * @return This reply */ - @SuppressWarnings("unchecked") - public T setTime(long time) { - this.time = time; - return (T) this; - } + public T setTime(long time); /** * Returns the text of the reply. * * @return The text of the reply */ - public String getText() { - return text; - } + public String getText(); /** - * Sets the text of this reply. + * Sets the text of the reply. * * @param text - * The text of this reply - * @return This reply (for method chaining) + * The text of the reply + * @return This reply */ - @SuppressWarnings("unchecked") - public T setText(String text) { - this.text = text; - return (T) this; - } + public T setText(String text); /** * Returns whether this reply is known. * * @return {@code true} if this reply is known, {@code false} otherwise */ - public boolean isKnown() { - return known; - } + public boolean isKnown(); /** * Sets whether this reply is known. @@ -206,42 +125,6 @@ public abstract class Reply> { * {@code true} if this reply is known, {@code false} otherwise * @return This reply */ - @SuppressWarnings("unchecked") - public T setKnown(boolean known) { - this.known = known; - return (T) this; - } - - // - // OBJECT METHODS - // - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return id.hashCode(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object object) { - if (!(object instanceof Reply)) { - return false; - } - Reply reply = (Reply) object; - return reply.id.equals(id); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return getClass().getName() + "[id=" + id + ",sone=" + sone + ",time=" + time + ",text=" + text + "]"; - } + public T setKnown(boolean known); -} +} \ No newline at end of file diff --git a/src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java new file mode 100644 index 0000000..f06bbf0 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java @@ -0,0 +1,120 @@ +/* + * Sone - PostReplyImpl.java - Copyright © 2010–2012 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.impl; + +import java.util.UUID; + +import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.PostReply; +import net.pterodactylus.sone.data.Sone; + +/** + * Simple {@link PostReply} implementation. + * + * @author David ‘Bombe’ Roden + */ +public class PostReplyImpl extends ReplyImpl implements PostReply { + + /** The Post this reply refers to. */ + private volatile Post post; + + /** + * Creates a new reply. + * + * @param id + * The ID of the reply + */ + public PostReplyImpl(String id) { + this(id, null, null, 0, null); + } + + /** + * Creates a new reply. + * + * @param sone + * The sone that posted the reply + * @param post + * The post to reply to + * @param text + * The text of the reply + */ + public PostReplyImpl(Sone sone, Post post, String text) { + this(sone, post, System.currentTimeMillis(), text); + } + + /** + * Creates a new reply- + * + * @param sone + * The sone that posted the reply + * @param post + * The post to reply to + * @param time + * The time of the reply + * @param text + * The text of the reply + */ + public PostReplyImpl(Sone sone, Post post, long time, String text) { + this(UUID.randomUUID().toString(), sone, post, time, text); + } + + /** + * Creates a new reply- + * + * @param sone + * The sone that posted the reply + * @param id + * The ID of the reply + * @param post + * The post to reply to + * @param time + * The time of the reply + * @param text + * The text of the reply + */ + public PostReplyImpl(String id, Sone sone, Post post, long time, String text) { + super(id, sone, time, text); + this.post = post; + } + + // + // ACCESSORS + // + + /** + * {@inheritDoc} + */ + @Override + public Post getPost() { + return post; + } + + /** + * Sets the post this reply refers to. + * + * @param post + * The post this reply refers to + * @return This reply (for method chaining) + */ + @Override + public PostReply setPost(Post post) { + this.post = post; + return this; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java new file mode 100644 index 0000000..76fd27a --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java @@ -0,0 +1,216 @@ +/* + * Sone - Reply.java - Copyright © 2011–2012 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.impl; + +import java.util.UUID; + +import net.pterodactylus.sone.data.Reply; +import net.pterodactylus.sone.data.Sone; + +/** + * Abstract base class for all replies. + * + * @param + * The type of the reply + * @author David ‘Bombe’ Roden + */ +public abstract class ReplyImpl> implements Reply { + + /** The ID of the reply. */ + private final String id; + + /** The Sone that created this reply. */ + private volatile Sone sone; + + /** The time of the reply. */ + private volatile long time; + + /** The text of the reply. */ + private volatile String text; + + /** Whether the reply is known. */ + private volatile boolean known; + + /** + * Creates a new reply with the given ID. + * + * @param id + * The ID of the reply + */ + protected ReplyImpl(String id) { + this(id, null, 0, null); + } + + /** + * Creates a new reply with a new random ID. + * + * @param sone + * The Sone of the reply + * @param time + * The time of the reply + * @param text + * The text of the reply + */ + protected ReplyImpl(Sone sone, long time, String text) { + this(UUID.randomUUID().toString(), sone, time, text); + } + + /** + * Creates a new reply. + * + * @param id + * The ID of the reply + * @param sone + * The Sone of the reply + * @param time + * The time of the reply + * @param text + * The text of the reply + */ + protected ReplyImpl(String id, Sone sone, long time, String text) { + this.id = id; + this.sone = sone; + this.time = time; + this.text = text; + } + + /** + * {@inheritDoc} + */ + @Override + public String getId() { + return id; + } + + /** + * {@inheritDoc} + */ + @Override + public Sone getSone() { + return sone; + } + + /** + * Sets the Sone that posted this reply. + * + * @param sone + * The Sone that posted this reply + * @return This reply (for method chaining) + */ + @Override + @SuppressWarnings("unchecked") + public T setSone(Sone sone) { + this.sone = sone; + return (T) this; + } + + /** + * {@inheritDoc} + */ + @Override + public long getTime() { + return time; + } + + /** + * Sets the time of this reply. + * + * @param time + * The time of this reply (in milliseconds since Jan 1, 1970 UTC) + * @return This reply (for method chaining) + */ + @Override + @SuppressWarnings("unchecked") + public T setTime(long time) { + this.time = time; + return (T) this; + } + + /** + * {@inheritDoc} + */ + @Override + public String getText() { + return text; + } + + /** + * Sets the text of this reply. + * + * @param text + * The text of this reply + * @return This reply (for method chaining) + */ + @Override + @SuppressWarnings("unchecked") + public T setText(String text) { + this.text = text; + return (T) this; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isKnown() { + return known; + } + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("unchecked") + public T setKnown(boolean known) { + this.known = known; + return (T) this; + } + + // + // OBJECT METHODS + // + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return id.hashCode(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object object) { + if (!(object instanceof Reply)) { + return false; + } + Reply reply = (Reply) object; + return reply.getId().equals(id); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return getClass().getName() + "[id=" + id + ",sone=" + sone + ",time=" + time + ",text=" + text + "]"; + } + +}