From: David ‘Bombe’ Roden Date: Wed, 26 Mar 2014 18:44:34 +0000 (+0100) Subject: Move saving known posts into its own method. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=3daa6507da051b82c0e56b2299352e6307288864;p=Sone.git Move saving known posts into its own method. --- diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostDatabase.java index a16a36b..f7bce41 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostDatabase.java @@ -286,11 +286,7 @@ public class MemoryPostDatabase implements PostDatabase { public void save() throws DatabaseException { readWriteLock.readLock().lock(); try { - int postCounter = 0; - for (String knownPostId : knownPosts) { - configuration.getStringValue("KnownPosts/" + postCounter++ + "/ID").setValue(knownPostId); - } - configuration.getStringValue("KnownPosts/" + postCounter + "/ID").setValue(null); + saveKnownPosts(); } catch (ConfigurationException ce1) { throw new DatabaseException("Could not save database.", ce1); } finally { @@ -298,4 +294,12 @@ public class MemoryPostDatabase implements PostDatabase { } } + private void saveKnownPosts() throws ConfigurationException { + int postCounter = 0; + for (String knownPostId : knownPosts) { + configuration.getStringValue("KnownPosts/" + postCounter++ + "/ID").setValue(knownPostId); + } + configuration.getStringValue("KnownPosts/" + postCounter + "/ID").setValue(null); + } + }