Load bookmarked posts in configuration loader, too.
[Sone.git] / src / main / java / net / pterodactylus / sone / database / memory / ConfigurationLoader.java
1 package net.pterodactylus.sone.database.memory;
2
3 import java.util.HashSet;
4 import java.util.Set;
5
6 import net.pterodactylus.util.config.Configuration;
7
8 /**
9  * Helper class for interacting with a {@link Configuration}.
10  *
11  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
12  */
13 public class ConfigurationLoader {
14
15         private final Configuration configuration;
16
17         public ConfigurationLoader(Configuration configuration) {
18                 this.configuration = configuration;
19         }
20
21         public synchronized Set<String> loadKnownPosts() {
22                 Set<String> knownPosts = new HashSet<String>();
23                 int postCounter = 0;
24                 while (true) {
25                         String knownPostId = configuration
26                                         .getStringValue("KnownPosts/" + postCounter++ + "/ID")
27                                         .getValue(null);
28                         if (knownPostId == null) {
29                                 break;
30                         }
31                         knownPosts.add(knownPostId);
32                 }
33                 return knownPosts;
34         }
35
36         public synchronized Set<String> loadKnownPostReplies() {
37                 Set<String> knownPostReplies = new HashSet<String>();
38                 int replyCounter = 0;
39                 while (true) {
40                         String knownReplyId = configuration
41                                         .getStringValue("KnownReplies/" + replyCounter++ + "/ID")
42                                         .getValue(null);
43                         if (knownReplyId == null) {
44                                 break;
45                         }
46                         knownPostReplies.add(knownReplyId);
47                 }
48                 return knownPostReplies;
49         }
50
51         public synchronized Set<String> loadBookmarkedPosts() {
52                 Set<String> bookmarkedPosts = new HashSet<String>();
53                 int postCounter = 0;
54                 while (true) {
55                         String bookmarkedPostId = configuration
56                                         .getStringValue("Bookmarks/Post/" + postCounter++ + "/ID")
57                                         .getValue(null);
58                         if (bookmarkedPostId == null) {
59                                 break;
60                         }
61                         bookmarkedPosts.add(bookmarkedPostId);
62                 }
63                 return bookmarkedPosts;
64         }
65
66 }