From 6004444a6a2f604b46d1440cd7f0fbe6502245d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 21 Jan 2011 12:40:51 +0100 Subject: [PATCH] =?utf8?q?Checking=20for=20the=20=E2=80=9Cnewness=E2=80=9D?= =?utf8?q?=20of=20an=20item=20will=20never=20mark=20it=20as=20known=20anym?= =?utf8?q?ore.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/core/Core.java | 82 ++-------------------- .../pterodactylus/sone/template/PostAccessor.java | 2 +- .../pterodactylus/sone/template/ReplyAccessor.java | 2 +- .../pterodactylus/sone/template/SoneAccessor.java | 2 +- 4 files changed, 8 insertions(+), 80 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 00e7deb..dbda28d 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -494,40 +494,15 @@ public class Core implements IdentityListener, UpdateListener { } /** - * Returns whether the Sone with the given ID is a new Sone. After this - * check, the Sone is marked as known, i.e. a second call with the same - * parameters will always yield {@code false}. + * Returns whether the Sone with the given ID is a new Sone. * * @param soneId * The ID of the sone to check for * @return {@code true} if the given Sone is new, false otherwise */ public boolean isNewSone(String soneId) { - return isNewSone(soneId, true); - } - - /** - * Returns whether the Sone with the given ID is a new Sone. The Sone will - * be marked as known if {@code markAsKnown} is {@code true}, otherwise the - * Sone will keep its current “new” state. - * - * @param soneId - * The ID of the sone to check for - * @param markAsKnown - * {@code true} to mark the Sone as known in any case, - * {@code false} to not mark it as known - * @return {@code true} if the given Sone is new, false otherwise - */ - public boolean isNewSone(String soneId, boolean markAsKnown) { synchronized (newSones) { - boolean isNew = !knownSones.contains(soneId) && newSones.contains(soneId); - if (markAsKnown) { - Sone sone = getSone(soneId, false); - if (sone != null) { - markSoneKnown(sone); - } - } - return isNew; + return !knownSones.contains(soneId) && newSones.contains(soneId); } } @@ -589,8 +564,7 @@ public class Core implements IdentityListener, UpdateListener { } /** - * Returns whether the given post ID is new. After this method returns it is - * marked a known post ID. + * Returns whether the given post ID is new. * * @param postId * The post ID @@ -598,32 +572,8 @@ public class Core implements IdentityListener, UpdateListener { * otherwise */ public boolean isNewPost(String postId) { - return isNewPost(postId, true); - } - - /** - * Returns whether the given post ID is new. If {@code markAsKnown} is - * {@code true} then after this method returns the post ID is marked a known - * post ID. - * - * @param postId - * The post ID - * @param markAsKnown - * {@code true} to mark the post ID as known, {@code false} to - * not to mark it as known - * @return {@code true} if the post is considered to be new, {@code false} - * otherwise - */ - public boolean isNewPost(String postId, boolean markAsKnown) { synchronized (newPosts) { - boolean isNew = !knownPosts.contains(postId) && newPosts.contains(postId); - if (markAsKnown) { - Post post = getPost(postId, false); - if (post != null) { - markPostKnown(post); - } - } - return isNew; + return !knownPosts.contains(postId) && newPosts.contains(postId); } } @@ -692,30 +642,8 @@ public class Core implements IdentityListener, UpdateListener { * otherwise */ public boolean isNewReply(String replyId) { - return isNewReply(replyId, true); - } - - /** - * Returns whether the reply with the given ID is new. - * - * @param replyId - * The ID of the reply to check - * @param markAsKnown - * {@code true} to mark the reply as known, {@code false} to not - * to mark it as known - * @return {@code true} if the reply is considered to be new, {@code false} - * otherwise - */ - public boolean isNewReply(String replyId, boolean markAsKnown) { synchronized (newReplies) { - boolean isNew = !knownReplies.contains(replyId) && newReplies.contains(replyId); - if (markAsKnown) { - Reply reply = getReply(replyId, false); - if (reply != null) { - markReplyKnown(reply); - } - } - return isNew; + return !knownReplies.contains(replyId) && newReplies.contains(replyId); } } diff --git a/src/main/java/net/pterodactylus/sone/template/PostAccessor.java b/src/main/java/net/pterodactylus/sone/template/PostAccessor.java index abdc4c8..f6a9c06 100644 --- a/src/main/java/net/pterodactylus/sone/template/PostAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/PostAccessor.java @@ -61,7 +61,7 @@ public class PostAccessor extends ReflectionAccessor { Sone currentSone = (Sone) templateContext.get("currentSone"); return (currentSone != null) && (currentSone.isLikedPostId(post.getId())); } else if (member.equals("new")) { - return core.isNewPost(post.getId(), false); + return core.isNewPost(post.getId()); } return super.get(templateContext, object, member); } diff --git a/src/main/java/net/pterodactylus/sone/template/ReplyAccessor.java b/src/main/java/net/pterodactylus/sone/template/ReplyAccessor.java index efba587..f439abe 100644 --- a/src/main/java/net/pterodactylus/sone/template/ReplyAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/ReplyAccessor.java @@ -57,7 +57,7 @@ public class ReplyAccessor extends ReflectionAccessor { Sone currentSone = (Sone) templateContext.get("currentSone"); return (currentSone != null) && (currentSone.isLikedReplyId(reply.getId())); } else if (member.equals("new")) { - return core.isNewReply(reply.getId(), false); + return core.isNewReply(reply.getId()); } return super.get(templateContext, object, member); } diff --git a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java index 27b4c24..23b2227 100644 --- a/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/SoneAccessor.java @@ -94,7 +94,7 @@ public class SoneAccessor extends ReflectionAccessor { } else if (member.equals("downloading")) { return core.getSoneStatus(sone) == SoneStatus.downloading; } else if (member.equals("new")) { - return core.isNewSone(sone.getId(), false); + return core.isNewSone(sone.getId()); } else if (member.equals("locked")) { return core.isLocked(sone); } else if (member.equals("trust")) { -- 2.7.4