Move saving known posts into its own method.
[Sone.git] / 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);
+       }
+
 }