X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdatabase%2Fmemory%2FConfigurationLoader.java;h=0e37dabbf57e0e5702f21087bc79e587bc64de22;hb=722b47810ffbe01465f104791c9f660ae161023b;hp=e65cf48117aa5d8ee409b68a2afbd12ed5d01dfd;hpb=b282ae4881da1f8329fded3369bc08d6aaee6e7b;p=Sone.git 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 e65cf48..0e37dab 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/ConfigurationLoader.java @@ -3,7 +3,10 @@ package net.pterodactylus.sone.database.memory; import static java.util.logging.Level.WARNING; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.logging.Logger; @@ -35,6 +38,45 @@ public class ConfigurationLoader { saveIds("Sone/" + soneId + "/Friends", friends); } + public synchronized Set loadKnownSones() { + return loadIds("KnownSones"); + } + + public synchronized void saveKnownSones(Set knownSones) { + saveIds("KnownSones", knownSones); + } + + public synchronized Map loadSoneFollowingTimes() { + Map soneFollowingTimes = new HashMap(); + int counter = 0; + while (true) { + String soneId = configuration.getStringValue("SoneFollowingTimes/" + counter + "/Sone").getValue(null); + if (soneId == null) { + break; + } + long followingTime = configuration.getLongValue("SoneFollowingTimes/" + counter + "/Time").getValue(Long.MAX_VALUE); + soneFollowingTimes.put(soneId, followingTime); + counter++; + } + return soneFollowingTimes; + } + + public synchronized void saveSoneFollowingTimes(Map soneFollowingTimes) { + try { + int counter = 0; + for (Entry soneFollowingTime : soneFollowingTimes.entrySet()) { + configuration.getStringValue("SoneFollowingTimes/" + counter + "/Sone") + .setValue(soneFollowingTime.getKey()); + configuration.getLongValue("SoneFollowingTimes/" + counter + "/Time") + .setValue(soneFollowingTime.getValue()); + counter++; + } + configuration.getStringValue("SoneFollowingTimes/" + counter + "/Sone").setValue(null); + } catch (ConfigurationException ce1) { + logger.log(WARNING, "Could not save Sone following times!", ce1); + } + } + public synchronized Set loadKnownPosts() { return loadIds("KnownPosts"); }