Move saving known posts into its own method.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 26 Mar 2014 18:44:34 +0000 (19:44 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 26 Mar 2014 18:44:34 +0000 (19:44 +0100)
src/main/java/net/pterodactylus/sone/database/memory/MemoryPostDatabase.java

index a16a36b..f7bce41 100644 (file)
@@ -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);
+       }
+
 }