From: David ‘Bombe’ Roden Date: Tue, 4 Nov 2014 18:43:10 +0000 (+0100) Subject: Refactor loading of IDs. X-Git-Tag: 0.9-rc1^2~3^2~51 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d9ecda2e1e4411a0b5da8fb760091b6f659e961f;p=Sone.git Refactor loading of IDs. --- 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; } }