Author: batosai
Date: 2008-09-01 20:27:50 +0000 (Mon, 01 Sep 2008)
New Revision: 22315

Added:
   trunk/apps/WoT/src/plugins/WoT/Config.java
Log:
Oops.

Added: trunk/apps/WoT/src/plugins/WoT/Config.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Config.java                          (rev 0)
+++ trunk/apps/WoT/src/plugins/WoT/Config.java  2008-09-01 20:27:50 UTC (rev 
22315)
@@ -0,0 +1,53 @@
+/**
+ * This code is part of WoT, a plugin for Freenet. It is distributed 
+ * under the GNU General Public License, version 2 (or at your option
+ * any later version). See http://www.gnu.org/ for details of the GPL.
+ */
+package plugins.WoT;
+
+import java.util.HashMap;
+import java.util.Iterator;
+
+import com.db4o.ObjectContainer;
+
+import freenet.support.Logger;
+
+/**
+ * @author Julien Cornuwel (batosai at freenetproject.org)
+ */
+public class Config {
+
+       private ObjectContainer db;
+       private HashMap<String, String> params = new HashMap<String, String>();
+       
+       public Config(ObjectContainer db) {
+               this.db = db;
+               if(params == null) initDefault(false);
+       }
+       
+       public void set(String key, String value) {
+               params.put(key, value);
+               db.store(params);
+       }
+       
+       public String get(String key) {
+               return params.get(key);
+       }
+       
+       public void initDefault(boolean overwrite) {
+               HashMap<String, String> defaults = new HashMap<String, 
String>();
+               
+               defaults.put("delayBetweenInserts", "30");
+               
+               Iterator<String> i = defaults.keySet().iterator();
+               while (i.hasNext()) {
+                       String key = i.next();
+                       if (!params.containsKey(key) || overwrite) {
+                               set(key, defaults.get(key));
+                               Logger.debug(this, "Added new default parameter 
: "+key+"="+defaults.get(key));
+                       }
+               }
+               
+               db.store(this);
+       }
+}


Reply via email to