synchronized (knownPosts) {
for (Post post : sone.getPosts()) {
PostBuilder postBuilder = postBuilderFactory.newPostBuilder();
- postBuilder.copyPost(post).from(storedSone);
+ postBuilder.copyPost(post).from(storedSone.getId());
Post newPost = postBuilder.build().setKnown(knownPosts.contains(post.getId()));
if (!storedPosts.contains(newPost)) {
if (newPost.getTime() < getSoneFollowingTime(sone)) {
Set<PostReply> storedReplies = storedSone.getReplies();
synchronized (knownReplies) {
for (PostReply reply : sone.getReplies()) {
- reply.setSone(storedSone).setKnown(knownReplies.contains(reply.getId()));
+ reply.setKnown(knownReplies.contains(reply.getId()));
if (!storedReplies.contains(reply)) {
if (reply.getTime() < getSoneFollowingTime(sone)) {
knownReplies.add(reply.getId());
logger.log(Level.WARNING, "Invalid post found, aborting load!");
return;
}
- PostBuilder postBuilder = postBuilder().withId(postId).from(sone).withTime(postTime).withText(postText);
+ PostBuilder postBuilder = postBuilder().withId(postId).from(sone.getId()).withTime(postTime).withText(postText);
if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
- postBuilder.to(getSone(postRecipientId));
+ postBuilder.to(postRecipientId);
}
posts.add(postBuilder.build());
}
return;
}
PostReplyBuilder postReplyBuilder = postReplyBuilderFactory.newPostReplyBuilder();
- postReplyBuilder.withId(replyId).from(sone).to(postId).withTime(replyTime).withText(replyText);
+ postReplyBuilder.withId(replyId).from(sone.getId()).to(postId).withTime(replyTime).withText(replyText);
replies.add(postReplyBuilder.build());
}
return null;
}
PostBuilder postBuilder = postBuilderFactory.newPostBuilder();
- postBuilder.from(sone).randomId().withTime(time).withText(text.trim());
+ postBuilder.from(sone.getId()).randomId().withTime(time).withText(text.trim());
if (recipient != null) {
- postBuilder.to(recipient);
+ postBuilder.to(recipient.getId());
}
final Post post = postBuilder.build();
synchronized (posts) {
return null;
}
PostReplyBuilder postReplyBuilder = postReplyBuilderFactory.newPostReplyBuilder();
- postReplyBuilder.randomId().from(sone).to(post.getId()).currentTime().withText(text.trim());
+ postReplyBuilder.randomId().from(sone.getId()).to(post.getId()).currentTime().withText(text.trim());
final PostReply reply = postReplyBuilder.build();
synchronized (replies) {
replies.put(reply.getId(), reply);
try {
PostBuilder postBuilder = core.postBuilder();
/* TODO - parse time correctly. */
- postBuilder.withId(postId).from(sone).withTime(Long.parseLong(postTime)).withText(postText);
+ postBuilder.withId(postId).from(sone.getId()).withTime(Long.parseLong(postTime)).withText(postText);
if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
- postBuilder.to(core.getSone(postRecipientId));
+ postBuilder.to(postRecipientId);
}
posts.add(postBuilder.build());
} catch (NumberFormatException nfe1) {
try {
PostReplyBuilder postReplyBuilder = core.postReplyBuilder();
/* TODO - parse time correctly. */
- postReplyBuilder.withId(replyId).from(sone).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
+ postReplyBuilder.withId(replyId).from(sone.getId()).to(replyPostId).withTime(Long.parseLong(replyTime)).withText(replyText);
replies.add(postReplyBuilder.build());
} catch (NumberFormatException nfe1) {
/* TODO - mark Sone as bad. */
/**
* Configures this builder to use the given Sone as sender of the new post.
*
- * @param sender
- * The sender of the post
+ * @param senderId
+ * The ID of the sender of the post
* @return This post builder
*/
- public PostBuilder from(Sone sender);
+ public PostBuilder from(String senderId);
/**
* Configures this builder to use a random ID for the new post. If this
* Configures the builder to use the given {@link Sone} as recipient for the
* post.
*
- * @param recipient
- * The recipient of the post
+ * @param recipientId
+ * The ID of the recipient of the post
* @return This post builder
*/
- public PostBuilder to(Sone recipient);
+ public PostBuilder to(String recipientId);
/**
* Verifies this builder’s configuration and creates a new post.
* <ul>
* <li>Exactly one of {@link #randomId()} or {@link #withId(String)} must
* have been called.</li>
- * <li>The {@link #from(Sone) sender} must not be {@code null}.</li>
+ * <li>The {@link #from(String) sender} must not be {@code null}.</li>
* <li>Exactly one of {@link #currentTime()} or {@link #withTime(long)} must
* have been called.</li>
* <li>The {@link #withText(String) text} must not be {@code null} and must
* contain something other than whitespace.</li>
- * <li>The {@link #to(Sone) recipient} must either not have been set, or it
- * must have been set to a {@link Sone} other than {@link #from(Sone) the
- * sender}.</li>
+ * <li>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}.</li>
* </ul>
*
* @return A new post
*/
public Optional<Post> getPost();
- /**
- * Sets the post this reply refers to.
- *
- * @param postId
- * The ID of the post to reply to
- * @return This reply
- */
- public PostReply setPost(String postId);
-
}
* <ul>
* <li>Exactly one of {@link #randomId()} or {@link #withId(String)} must
* have been called.</li>
- * <li>The {@link #from(Sone) sender} must not be {@code null}.</li>
+ * <li>The {@link #from(String) sender} must not be {@code null}.</li>
* <li>Exactly one of {@link #currentTime()} or {@link #withTime(long)} must
* have been called.</li>
* <li>The {@link #withText(String) text} must not be {@code null} and must
public Sone getSone();
/**
- * Sets the Sone that posted this reply.
- *
- * @param sone
- * The Sone that posted this reply
- * @return This reply
- */
- 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();
/**
- * Sets the time of the reply.
- *
- * @param time
- * The time of the reply (in milliseconds since Jan 1, 1970 UTC)
- * @return This reply
- */
- public T setTime(long time);
-
- /**
* Returns the text of the reply.
*
* @return The text of the reply
public String getText();
/**
- * Sets the text of the reply.
- *
- * @param text
- * The text of the reply
- * @return This reply
- */
- public T setText(String text);
-
- /**
* Returns whether this reply is known.
*
* @return {@code true} if this reply is known, {@code false} otherwise
public B withId(String id);
/**
- * Configures this builder to use the given {@link Sone} as sender of the
- * reply.
+ * Configures this builder to use the ID of the given {@link Sone} as sender
+ * of the reply.
*
- * @param sender
- * The sender of the reply
+ * @param senderId
+ * The ID of the sender of the reply
* @return This builder
*/
- public B from(Sone sender);
+ public B from(String senderId);
/**
* Configures this builder to use the current time when creating the reply.
package net.pterodactylus.sone.data.impl;
import net.pterodactylus.sone.data.ReplyBuilder;
-import net.pterodactylus.sone.data.Sone;
/**
* Abstract implementation of a {@link ReplyBuilder}.
protected String id;
/** The sender of the reply. */
- protected Sone sender;
+ protected String senderId;
/** Whether to use the current time when creating the reply. */
protected boolean currentTime;
*/
@Override
@SuppressWarnings("unchecked")
- public B from(Sone sender) {
- this.sender = sender;
+ public B from(String senderId) {
+ this.senderId = senderId;
return (B) this;
}
package net.pterodactylus.sone.data.impl;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.PostBuilder;
import net.pterodactylus.sone.data.PostBuilderFactory;
*/
public class DefaultPostBuilderFactory implements PostBuilderFactory {
+ /** The Sone provider. */
+ private final SoneProvider soneProvider;
+
+ /**
+ * Creates a new default post builder factory.
+ *
+ * @param soneProvider
+ * The Sone provider
+ */
+ public DefaultPostBuilderFactory(SoneProvider soneProvider) {
+ this.soneProvider = soneProvider;
+ }
+
/**
* {@inheritDoc}
*/
@Override
public PostBuilder newPostBuilder() {
- return new PostBuilderImpl();
+ return new PostBuilderImpl(soneProvider);
}
}
package net.pterodactylus.sone.data.impl;
import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.PostReplyBuilder;
import net.pterodactylus.sone.data.PostReplyBuilderFactory;
*/
public class DefaultPostReplyBuilderFactory implements PostReplyBuilderFactory {
+ /** The Sone provider. */
+ private final SoneProvider soneProvider;
+
/** The post provider. */
private final PostProvider postProvider;
/**
* Creates a new default post reply builder factory.
*
+ * @param soneProvider
+ * The Sone provider
* @param postProvider
* The post provider
*/
@Inject
- public DefaultPostReplyBuilderFactory(PostProvider postProvider) {
+ public DefaultPostReplyBuilderFactory(SoneProvider soneProvider, PostProvider postProvider) {
+ this.soneProvider = soneProvider;
this.postProvider = postProvider;
}
*/
@Override
public PostReplyBuilder newPostReplyBuilder() {
- return new PostReplyBuilderImpl(postProvider);
+ return new PostReplyBuilderImpl(soneProvider, postProvider);
}
}
import java.util.UUID;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostBuilder;
-import net.pterodactylus.sone.data.Sone;
import org.apache.commons.lang.StringUtils;
*/
public class PostBuilderImpl implements PostBuilder {
+ /** The Sone provider for the created posts. */
+ private final SoneProvider soneProvider;
+
/** Wether to create a post with a random ID. */
private boolean randomId;
private String id;
/** The sender of the post. */
- private Sone sender;
+ private String senderId;
/** Whether to use the current time when creating the post. */
private boolean currentTime;
private String text;
/** The (optional) recipient of the post. */
- private Sone recipient;
+ private String recipientId;
+
+ /**
+ * Creates a new post builder.
+ *
+ * @param soneProvider
+ * The Sone provider
+ */
+ public PostBuilderImpl(SoneProvider soneProvider) {
+ this.soneProvider = soneProvider;
+ }
/**
* {@inheritDoc}
public PostBuilder copyPost(Post post) {
this.randomId = false;
this.id = post.getId();
- this.sender = post.getSone();
+ this.senderId = post.getSone().getId();
this.currentTime = false;
this.time = post.getTime();
this.text = post.getText();
- this.recipient = post.getRecipient();
+ this.recipientId = (post.getRecipient() != null) ? post.getRecipient().getId() : null;
return this;
}
* {@inheritDoc}
*/
@Override
- public PostBuilder from(Sone sender) {
- this.sender = sender;
+ public PostBuilder from(String senderId) {
+ this.senderId = senderId;
return this;
}
* {@inheritDoc}
*/
@Override
- public PostBuilder to(Sone recipient) {
- this.recipient = recipient;
+ public PostBuilder to(String recipientId) {
+ this.recipientId = recipientId;
return this;
}
@Override
public Post build() {
checkState((randomId && (id == null)) || (!randomId && (id != null)), "exactly one of random ID or custom ID must be set");
- checkState(sender != null, "sender must not be null");
+ checkState(senderId != null, "sender must not be null");
checkState((currentTime && (time == 0)) || (!currentTime && (time > 0)), "one of current time or custom time must be set");
checkState(!StringUtils.isBlank(text), "text must not be empty");
- checkState((recipient == null) || !recipient.equals(sender), "sender and recipient must not be the same");
- return new PostImpl(randomId ? UUID.randomUUID().toString() : id, sender, currentTime ? System.currentTimeMillis() : time, text).setRecipient(recipient);
+ checkState((recipientId == null) || !recipientId.equals(senderId), "sender and recipient must not be the same");
+ return new PostImpl(soneProvider, randomId ? UUID.randomUUID().toString() : id, senderId, recipientId, currentTime ? System.currentTimeMillis() : time, text);
}
}
import java.util.UUID;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
*/
public class PostImpl implements Post {
+ /** The Sone provider. */
+ private final SoneProvider soneProvider;
+
/** The GUID of the post. */
private final UUID id;
- /** The Sone this post belongs to. */
- private volatile Sone sone;
+ /** The ID of the owning Sone. */
+ private final String soneId;
- /** The Sone of the recipient. */
- private volatile Sone recipient;
+ /** The ID of the recipient Sone. */
+ private final String recipientId;
/** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
- private volatile long time;
+ private final long time;
/** The text of the post. */
- private volatile String text;
+ private final String text;
/** Whether the post is known. */
private volatile boolean known;
/**
* Creates a new post.
*
+ * @param soneProvider
+ * The Sone provider
* @param id
* The ID of the post
- */
- public PostImpl(String id) {
- this(id, null, 0, null);
- }
-
- /**
- * Creates a new post.
- *
- * @param sone
- * The Sone this post belongs to
- * @param text
- * The text of the post
- */
- public PostImpl(Sone sone, String text) {
- this(sone, System.currentTimeMillis(), text);
- }
-
- /**
- * Creates a new post.
- *
- * @param sone
- * The Sone this post belongs to
- * @param time
- * The time of the post (in milliseconds since Jan 1, 1970 UTC)
- * @param text
- * The text of the post
- */
- public PostImpl(Sone sone, long time, String text) {
- this(UUID.randomUUID().toString(), sone, time, text);
- }
-
- /**
- * Creates a new post.
- *
- * @param id
- * The ID of the post
- * @param sone
- * The Sone this post belongs to
+ * @param soneId
+ * The ID of the Sone this post belongs to
+ * @param recipientId
+ * The ID of the recipient of the post
* @param time
* The time of the post (in milliseconds since Jan 1, 1970 UTC)
* @param text
* The text of the post
*/
- public PostImpl(String id, Sone sone, long time, String text) {
+ public PostImpl(SoneProvider soneProvider, String id, String soneId, String recipientId, long time, String text) {
+ this.soneProvider = soneProvider;
this.id = UUID.fromString(id);
- this.sone = sone;
+ this.soneId = soneId;
+ this.recipientId = recipientId;
this.time = time;
this.text = text;
}
*/
@Override
public Sone getSone() {
- return sone;
- }
-
- /**
- * Sets the Sone of this post.
- *
- * @param sone
- * The Sone of this post
- * @return This post (for method chaining)
- */
- public PostImpl setSone(Sone sone) {
- this.sone = sone;
- return this;
+ return soneProvider.getSone(soneId, false);
}
/**
*/
@Override
public Sone getRecipient() {
- return recipient;
- }
-
- /**
- * Sets the recipient of this post.
- *
- * @param recipient
- * The recipient of this post, or {@code null}
- * @return This post (for method chaining)
- */
- public PostImpl setRecipient(Sone recipient) {
- if (!sone.equals(recipient)) {
- this.recipient = recipient;
- }
- return this;
+ return soneProvider.getSone(recipientId, false);
}
/**
}
/**
- * Sets the time of this post.
- *
- * @param time
- * The time of this post (in milliseconds since Jan 1, 1970 UTC)
- * @return This post (for method chaining)
- */
- public PostImpl setTime(long time) {
- this.time = time;
- return this;
- }
-
- /**
* {@inheritDoc}
*/
@Override
}
/**
- * Sets the text of this post.
- *
- * @param text
- * The text of this post
- * @return This post (for method chaining)
- */
- public PostImpl setText(String text) {
- this.text = text;
- return this;
- }
-
- /**
* {@inheritDoc}
*/
@Override
*/
@Override
public String toString() {
- return getClass().getName() + "[id=" + id + ",sone=" + sone + ",time=" + time + ",text=" + text + "]";
+ return String.format("%s[id=%s,sone=%s,recipient=%s,time=%d,text=%s]", getClass().getName(), id, soneId, recipientId, time, text);
}
}
import java.util.UUID;
import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.PostReplyBuilder;
*/
public class PostReplyBuilderImpl extends AbstractReplyBuilder<PostReplyBuilder> implements PostReplyBuilder {
- /** The post builder. */
+ /** The Sone provider. */
+ private final SoneProvider soneProvider;
+
+ /** The post provider. */
private final PostProvider postProvider;
/** The ID of the post the created reply refers to. */
/**
* Creates a new post reply builder.
*
+ * @param soneProvider
+ * The Sone provider
* @param postProvider
* The post provider
*/
- public PostReplyBuilderImpl(PostProvider postProvider) {
+ public PostReplyBuilderImpl(SoneProvider soneProvider, PostProvider postProvider) {
+ this.soneProvider = soneProvider;
this.postProvider = postProvider;
}
@Override
public PostReply build() {
checkState((randomId && (id == null)) || (!randomId && (id != null)), "either random ID nor custom ID must be set");
- checkState(sender != null, "sender must not be null");
+ checkState(senderId != null, "sender must not be null");
checkState((currentTime && (time == 0)) || (!currentTime && (time >= 0)), "either current time or custom time must be set");
checkState(!StringUtils.isBlank(text), "text must not be empty");
checkState(postId != null, "post must not be null");
/* create new post reply. */
- PostReplyImpl postReplyImpl = new PostReplyImpl(postProvider, randomId ? UUID.randomUUID().toString() : id);
- postReplyImpl.setSone(sender);
- postReplyImpl.setPost(postId);
- postReplyImpl.setTime(currentTime ? System.currentTimeMillis() : time);
- postReplyImpl.setText(text);
- return postReplyImpl;
+ return new PostReplyImpl(soneProvider, postProvider, randomId ? UUID.randomUUID().toString() : id, senderId, currentTime ? System.currentTimeMillis() : time, text, postId);
}
}
package net.pterodactylus.sone.data.impl;
import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
private final PostProvider postProvider;
/** The Post this reply refers to. */
- private volatile String postId;
+ private final String postId;
/**
* Creates a new reply.
*
+ * @param soneProvider
+ * The Sone provider
* @param postProvider
* The post provider
* @param id
* The ID of the reply
+ * @param soneId
+ * The ID of the Sone of the reply
+ * @param time
+ * The time of the reply
+ * @param text
+ * The text of the reply
+ * @param postId
+ * The ID of the post this reply refers to
*/
- public PostReplyImpl(PostProvider postProvider, String id) {
- super(id);
+ public PostReplyImpl(SoneProvider soneProvider, PostProvider postProvider, String id, String soneId, long time, String text, String postId) {
+ super(soneProvider, id, soneId, time, text);
this.postProvider = postProvider;
this.postId = postId;
}
return postProvider.getPost(postId);
}
- /**
- * Sets the post this reply refers to.
- *
- * @param postId
- * The ID of the post to reply to
- * @return This reply (for method chaining)
- */
- @Override
- public PostReply setPost(String postId) {
- this.postId = postId;
- return this;
- }
-
}
package net.pterodactylus.sone.data.impl;
-import java.util.UUID;
-
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
*/
public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
+ /** The Sone provider. */
+ private final SoneProvider soneProvider;
+
/** The ID of the reply. */
private final String id;
/** The Sone that created this reply. */
- private volatile Sone sone;
+ private final String soneId;
/** The time of the reply. */
- private volatile long time;
+ private final long time;
/** The text of the reply. */
- private volatile String text;
+ private final 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 soneProvider
+ * The Sone provider
* @param id
* The ID of the reply
- * @param sone
- * The Sone of the reply
+ * @param soneId
+ * The ID of 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) {
+ protected ReplyImpl(SoneProvider soneProvider, String id, String soneId, long time, String text) {
+ this.soneProvider = soneProvider;
this.id = id;
- this.sone = sone;
+ this.soneId = soneId;
this.time = time;
this.text = text;
}
*/
@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;
+ return soneProvider.getSone(soneId, false);
}
/**
}
/**
- * 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
}
/**
- * 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
*/
@Override
public String toString() {
- return getClass().getName() + "[id=" + id + ",sone=" + sone + ",time=" + time + ",text=" + text + "]";
+ return String.format("%s[id=%s,sone=%s,time=%d,text=%s]", getClass().getName(), id, soneId, time, text);
}
}
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.core.FreenetInterface;
import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.core.WebOfTrustUpdater;
import net.pterodactylus.sone.data.PostBuilderFactory;
import net.pterodactylus.sone.data.PostReplyBuilderFactory;
bind(FcpInterface.class).in(Singleton.class);
bind(PostBuilderFactory.class).to(DefaultPostBuilderFactory.class).in(Singleton.class);
bind(PostReplyBuilderFactory.class).to(DefaultPostReplyBuilderFactory.class).in(Singleton.class);
+ bind(SoneProvider.class).to(Core.class).in(Singleton.class);
bind(PostProvider.class).to(Core.class).in(Singleton.class);
bindListener(Matchers.any(), new TypeListener() {