projects
/
Sone.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8ee35ad
)
Only store sender and recipient IDs in a post.
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Tue, 22 Jan 2013 09:22:29 +0000
(10:22 +0100)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Tue, 22 Jan 2013 09:22:29 +0000
(10:22 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/core/SoneDownloader.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/data/PostBuilder.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilderFactory.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java
patch
|
blob
|
history
diff --git
a/src/main/java/net/pterodactylus/sone/core/Core.java
b/src/main/java/net/pterodactylus/sone/core/Core.java
index
5e8bc26
..
8faad72
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/core/Core.java
+++ b/
src/main/java/net/pterodactylus/sone/core/Core.java
@@
-1104,7
+1104,7
@@
public class Core extends AbstractService implements SoneProvider, PostProvider,
synchronized (knownPosts) {
for (Post post : sone.getPosts()) {
PostBuilder postBuilder = postBuilderFactory.newPostBuilder();
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)) {
Post newPost = postBuilder.build().setKnown(knownPosts.contains(post.getId()));
if (!storedPosts.contains(newPost)) {
if (newPost.getTime() < getSoneFollowingTime(sone)) {
@@
-1307,9
+1307,9
@@
public class Core extends AbstractService implements SoneProvider, PostProvider,
logger.log(Level.WARNING, "Invalid post found, aborting load!");
return;
}
logger.log(Level.WARNING, "Invalid post found, aborting load!");
return;
}
- PostBuilder postBuilder = postBuilderFactory.newPostBuilder().withId(postId).from(sone).withTime(postTime).withText(postText);
+ PostBuilder postBuilder = postBuilderFactory.newPostBuilder().withId(postId).from(sone
.getId()
).withTime(postTime).withText(postText);
if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
- postBuilder.to(
getSone(postRecipientId)
);
+ postBuilder.to(
postRecipientId
);
}
posts.add(postBuilder.build());
}
}
posts.add(postBuilder.build());
}
@@
-1536,9
+1536,9
@@
public class Core extends AbstractService implements SoneProvider, PostProvider,
return null;
}
PostBuilder postBuilder = postBuilderFactory.newPostBuilder();
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) {
if (recipient != null) {
- postBuilder.to(recipient);
+ postBuilder.to(recipient
.getId()
);
}
final Post post = postBuilder.build();
synchronized (posts) {
}
final Post post = postBuilder.build();
synchronized (posts) {
diff --git
a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java
b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java
index
cf85d03
..
6c61fd8
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/core/SoneDownloader.java
+++ b/
src/main/java/net/pterodactylus/sone/core/SoneDownloader.java
@@
-376,9
+376,9
@@
public class SoneDownloader extends AbstractService {
try {
PostBuilder postBuilder = core.postBuilder();
/* TODO - parse time correctly. */
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)) {
if ((postRecipientId != null) && (postRecipientId.length() == 43)) {
- postBuilder.to(
core.getSone(postRecipientId)
);
+ postBuilder.to(
postRecipientId
);
}
posts.add(postBuilder.build());
} catch (NumberFormatException nfe1) {
}
posts.add(postBuilder.build());
} catch (NumberFormatException nfe1) {
diff --git
a/src/main/java/net/pterodactylus/sone/data/PostBuilder.java
b/src/main/java/net/pterodactylus/sone/data/PostBuilder.java
index
00f7354
..
87d02ee
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/PostBuilder.java
+++ b/
src/main/java/net/pterodactylus/sone/data/PostBuilder.java
@@
-53,11
+53,11
@@
public interface PostBuilder {
/**
* Configures this builder to use the given Sone as sender of the new post.
*
/**
* Configures this builder to use the given Sone as sender of the new post.
*
- * @param sender
- * The sender of the post
+ * @param sender
Id
+ * The
ID of the
sender of the post
* @return This post builder
*/
* @return This post builder
*/
- public PostBuilder from(S
one sender
);
+ public PostBuilder from(S
tring senderId
);
/**
* Configures this builder to use a random ID for the new post. If this
/**
* Configures this builder to use a random ID for the new post. If this
@@
-108,11
+108,11
@@
public interface PostBuilder {
* Configures the builder to use the given {@link Sone} as recipient for the
* post.
*
* Configures the builder to use the given {@link Sone} as recipient for the
* post.
*
- * @param recipient
- * The recipient of the post
+ * @param recipient
Id
+ * The
ID of the
recipient of the post
* @return This post builder
*/
* @return This post builder
*/
- public PostBuilder to(S
one recipient
);
+ public PostBuilder to(S
tring recipientId
);
/**
* Verifies this builder’s configuration and creates a new post.
/**
* Verifies this builder’s configuration and creates a new post.
@@
-122,14
+122,14
@@
public interface PostBuilder {
* <ul>
* <li>Exactly one of {@link #randomId()} or {@link #withId(String)} must
* have been called.</li>
* <ul>
* <li>Exactly one of {@link #randomId()} or {@link #withId(String)} must
* have been called.</li>
- * <li>The {@link #from(S
one
) sender} must not be {@code null}.</li>
+ * <li>The {@link #from(S
tring
) 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>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(S
one) 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(S
tring) 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
* </ul>
*
* @return A new post
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
402b99a
..
25f6a86
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilderFactory.java
+++ b/
src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilderFactory.java
@@
-17,6
+17,7
@@
package net.pterodactylus.sone.data.impl;
package net.pterodactylus.sone.data.impl;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.PostBuilder;
import net.pterodactylus.sone.data.PostBuilderFactory;
import net.pterodactylus.sone.data.PostBuilder;
import net.pterodactylus.sone.data.PostBuilderFactory;
@@
-28,12
+29,25
@@
import net.pterodactylus.sone.data.PostBuilderFactory;
*/
public class DefaultPostBuilderFactory implements 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() {
/**
* {@inheritDoc}
*/
@Override
public PostBuilder newPostBuilder() {
- return new PostBuilderImpl();
+ return new PostBuilderImpl(
soneProvider
);
}
}
}
}
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
92b80c5
..
929f315
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java
+++ b/
src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java
@@
-21,9
+21,9
@@
import static com.google.common.base.Preconditions.checkState;
import java.util.UUID;
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.Post;
import net.pterodactylus.sone.data.PostBuilder;
-import net.pterodactylus.sone.data.Sone;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.StringUtils;
@@
-34,6
+34,9
@@
import org.apache.commons.lang.StringUtils;
*/
public class PostBuilderImpl implements PostBuilder {
*/
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;
/** Wether to create a post with a random ID. */
private boolean randomId;
@@
-41,7
+44,7
@@
public class PostBuilderImpl implements PostBuilder {
private String id;
/** The sender of the post. */
private String id;
/** The sender of the post. */
- private S
one sender
;
+ private S
tring senderId
;
/** Whether to use the current time when creating the post. */
private boolean currentTime;
/** Whether to use the current time when creating the post. */
private boolean currentTime;
@@
-53,7
+56,17
@@
public class PostBuilderImpl implements PostBuilder {
private String text;
/** The (optional) recipient of the post. */
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}
/**
* {@inheritDoc}
@@
-62,11
+75,11
@@
public class PostBuilderImpl implements PostBuilder {
public PostBuilder copyPost(Post post) {
this.randomId = false;
this.id = post.getId();
public PostBuilder copyPost(Post post) {
this.randomId = false;
this.id = post.getId();
- this.sender
= post.getSone
();
+ this.sender
Id = post.getSone().getId
();
this.currentTime = false;
this.time = post.getTime();
this.text = post.getText();
this.currentTime = false;
this.time = post.getTime();
this.text = post.getText();
- this.recipient
= post.getRecipient()
;
+ this.recipient
Id = (post.getRecipient() != null) ? post.getRecipient().getId() : null
;
return this;
}
return this;
}
@@
-92,8
+105,8
@@
public class PostBuilderImpl implements PostBuilder {
* {@inheritDoc}
*/
@Override
* {@inheritDoc}
*/
@Override
- public PostBuilder from(S
one sender
) {
- this.sender
= sender
;
+ public PostBuilder from(S
tring senderId
) {
+ this.sender
Id = senderId
;
return this;
}
return this;
}
@@
-128,8
+141,8
@@
public class PostBuilderImpl implements PostBuilder {
* {@inheritDoc}
*/
@Override
* {@inheritDoc}
*/
@Override
- public PostBuilder to(S
one recipient
) {
- this.recipient
= recipient
;
+ public PostBuilder to(S
tring recipientId
) {
+ this.recipient
Id = recipientId
;
return this;
}
return this;
}
@@
-139,11
+152,11
@@
public class PostBuilderImpl implements PostBuilder {
@Override
public Post build() {
checkState((randomId && (id == null)) || (!randomId && (id != null)), "exactly one of random ID or custom ID must be set");
@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(sender
Id
!= 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((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, recipient
, currentTime ? System.currentTimeMillis() : time, text);
+ checkState((recipient
Id == 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);
}
}
}
}
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
43d7d79
..
bb8a4df
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java
+++ b/
src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java
@@
-19,6
+19,7
@@
package net.pterodactylus.sone.data.impl;
import java.util.UUID;
import java.util.UUID;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
@@
-30,14
+31,17
@@
import net.pterodactylus.sone.data.Sone;
*/
public class PostImpl implements Post {
*/
public class PostImpl implements Post {
+ /** The Sone provider. */
+ private final SoneProvider soneProvider;
+
/** The GUID of the post. */
private final UUID id;
/** The GUID of the post. */
private final UUID id;
- /** The
Sone this post belongs to
. */
- private final S
one sone
;
+ /** The
ID of the owning Sone
. */
+ private final S
tring soneId
;
- /** The
Sone of the recipient
. */
- private final S
one recipient
;
+ /** The
ID of the recipient Sone
. */
+ private final S
tring recipientId
;
/** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
private final long time;
/** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
private final long time;
@@
-51,21
+55,24
@@
public class PostImpl implements Post {
/**
* Creates a new post.
*
/**
* Creates a new post.
*
+ * @param soneProvider
+ * The Sone provider
* @param id
* The ID of the post
* @param id
* The ID of the post
- * @param sone
- * The Sone this post belongs to
- * @param recipient
- * The recipient of the post
+ * @param sone
Id
+ * The
ID of the
Sone this post belongs to
+ * @param recipient
Id
+ * 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
*/
* @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, Sone recipient, 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.id = UUID.fromString(id);
- this.sone
= sone
;
- this.recipient
= recipient
;
+ this.sone
Id = soneId
;
+ this.recipient
Id = recipientId
;
this.time = time;
this.text = text;
}
this.time = time;
this.text = text;
}
@@
-87,7
+94,7
@@
public class PostImpl implements Post {
*/
@Override
public Sone getSone() {
*/
@Override
public Sone getSone() {
- return sone;
+ return sone
Provider.getSone(soneId, false)
;
}
/**
}
/**
@@
-95,7
+102,7
@@
public class PostImpl implements Post {
*/
@Override
public Sone getRecipient() {
*/
@Override
public Sone getRecipient() {
- return
recipient
;
+ return
soneProvider.getSone(recipientId, false)
;
}
/**
}
/**
@@
-160,7
+167,7
@@
public class PostImpl implements Post {
*/
@Override
public String toString() {
*/
@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)
;
}
}
}
}