From d9ecda2e1e4411a0b5da8fb760091b6f659e961f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 4 Nov 2014 19:43:10 +0100 Subject: [PATCH] Refactor loading of IDs. --- .../sone/database/memory/ConfigurationLoader.java | 44 +++++++--------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java b/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java index 24505ac..b9ac859 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java @@ -19,48 +19,30 @@ public class ConfigurationLoader { } public synchronized Set loadKnownPosts() { - Set knownPosts = new HashSet(); - int postCounter = 0; - while (true) { - String knownPostId = configuration - .getStringValue("KnownPosts/" + postCounter++ + "/ID") - .getValue(null); - if (knownPostId == null) { - break; - } - knownPosts.add(knownPostId); - } - return knownPosts; + return loadIds("KnownPosts"); } public synchronized Set loadKnownPostReplies() { - Set knownPostReplies = new HashSet(); - int replyCounter = 0; - while (true) { - String knownReplyId = configuration - .getStringValue("KnownReplies/" + replyCounter++ + "/ID") - .getValue(null); - if (knownReplyId == null) { - break; - } - knownPostReplies.add(knownReplyId); - } - return knownPostReplies; + return loadIds("KnownReplies"); } public synchronized Set loadBookmarkedPosts() { - Set bookmarkedPosts = new HashSet(); - int postCounter = 0; + return loadIds("Bookmarks/Post"); + } + + private Set loadIds(String prefix) { + Set ids = new HashSet(); + int idCounter = 0; while (true) { - String bookmarkedPostId = configuration - .getStringValue("Bookmarks/Post/" + postCounter++ + "/ID") + String id = configuration + .getStringValue(prefix + "/" + idCounter++ + "/ID") .getValue(null); - if (bookmarkedPostId == null) { + if (id == null) { break; } - bookmarkedPosts.add(bookmarkedPostId); + ids.add(id); } - return bookmarkedPosts; + return ids; } } -- 2.7.4