From 3daa6507da051b82c0e56b2299352e6307288864 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 26 Mar 2014 19:44:34 +0100 Subject: [PATCH] Move saving known posts into its own method. --- .../sone/database/memory/MemoryPostDatabase.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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); + } + } -- 2.7.4