Author: j16sdiz
Date: 2008-08-14 07:39:51 +0000 (Thu, 14 Aug 2008)
New Revision: 21831

Modified:
   trunk/freenet/src/freenet/config/BooleanOption.java
   trunk/freenet/src/freenet/config/Config.java
   trunk/freenet/src/freenet/config/IntOption.java
   trunk/freenet/src/freenet/config/LongOption.java
   trunk/freenet/src/freenet/config/Option.java
   trunk/freenet/src/freenet/config/PersistentConfig.java
   trunk/freenet/src/freenet/config/ShortOption.java
   trunk/freenet/src/freenet/config/StringArrOption.java
   trunk/freenet/src/freenet/config/StringOption.java
   trunk/freenet/src/freenet/config/SubConfig.java
   trunk/freenet/src/freenet/node/fcp/ConfigData.java
Log:
use enum

Modified: trunk/freenet/src/freenet/config/BooleanOption.java
===================================================================
--- trunk/freenet/src/freenet/config/BooleanOption.java 2008-08-14 00:35:04 UTC 
(rev 21830)
+++ trunk/freenet/src/freenet/config/BooleanOption.java 2008-08-14 07:39:51 UTC 
(rev 21831)
@@ -14,7 +14,7 @@

        public BooleanOption(SubConfig conf, String optionName, boolean 
defaultValue, int sortOrder, 
                        boolean expert, boolean forceWrite, String shortDesc, 
String longDesc, BooleanCallback cb) {
-               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DATA_TYPE_BOOLEAN);
+               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DataType.BOOLEAN);
                this.defaultValue = defaultValue;
                this.cb = cb;
                this.currentValue = defaultValue;

Modified: trunk/freenet/src/freenet/config/Config.java
===================================================================
--- trunk/freenet/src/freenet/config/Config.java        2008-08-14 00:35:04 UTC 
(rev 21830)
+++ trunk/freenet/src/freenet/config/Config.java        2008-08-14 07:39:51 UTC 
(rev 21831)
@@ -3,22 +3,17 @@
  * http://www.gnu.org/ for further details of the GPL. */
 package freenet.config;

+import java.io.IOException;
 import java.util.LinkedHashMap;

 /** Global configuration object for a node. SubConfig's register here.
  * Handles writing to a file etc.
  */
 public class Config {
+       public static enum RequestType {
+               CURRENT_SETTINGS, DEFAULT_SETTINGS, SORT_ORDER, EXPERT_FLAG, 
FORCE_WRITE_FLAG, SHORT_DESCRIPTION, LONG_DESCRIPTION, DATA_TYPE
+       };

-    public static final int CONFIG_REQUEST_TYPE_CURRENT_SETTINGS = 1;
-    public static final int CONFIG_REQUEST_TYPE_DEFAULT_SETTINGS = 2;
-    public static final int CONFIG_REQUEST_TYPE_SORT_ORDER = 3;
-    public static final int CONFIG_REQUEST_TYPE_EXPERT_FLAG = 4;
-    public static final int CONFIG_REQUEST_TYPE_FORCE_WRITE_FLAG = 5;
-    public static final int CONFIG_REQUEST_TYPE_SHORT_DESCRIPTION = 6;
-    public static final int CONFIG_REQUEST_TYPE_LONG_DESCRIPTION = 7;
-    public static final int CONFIG_REQUEST_TYPE_DATA_TYPE = 8;
-
        protected final LinkedHashMap configsByPrefix;

        public Config() {

Modified: trunk/freenet/src/freenet/config/IntOption.java
===================================================================
--- trunk/freenet/src/freenet/config/IntOption.java     2008-08-14 00:35:04 UTC 
(rev 21830)
+++ trunk/freenet/src/freenet/config/IntOption.java     2008-08-14 07:39:51 UTC 
(rev 21831)
@@ -15,10 +15,10 @@
        private int currentValue;
        // Cache it mostly so that we can keep SI units
        private String cachedStringValue;
-       
+
        public IntOption(SubConfig conf, String optionName, int defaultValue, 
String defaultValueString,
                        int sortOrder, boolean expert, boolean forceWrite, 
String shortDesc, String longDesc, IntCallback cb) {
-               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DATA_TYPE_NUMBER);
+               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DataType.NUMBER);
                this.defaultValue = defaultValue;
                this.cb = cb;
                this.currentValue = defaultValue;
@@ -27,7 +27,7 @@

        public IntOption(SubConfig conf, String optionName, String 
defaultValueString,
                        int sortOrder, boolean expert, boolean forceWrite, 
String shortDesc, String longDesc, IntCallback cb) {
-               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DATA_TYPE_NUMBER);
+               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DataType.NUMBER);
                this.defaultValue = Fields.parseInt(defaultValueString);
                this.cb = cb;
                this.currentValue = defaultValue;

Modified: trunk/freenet/src/freenet/config/LongOption.java
===================================================================
--- trunk/freenet/src/freenet/config/LongOption.java    2008-08-14 00:35:04 UTC 
(rev 21830)
+++ trunk/freenet/src/freenet/config/LongOption.java    2008-08-14 07:39:51 UTC 
(rev 21831)
@@ -5,7 +5,6 @@

 import freenet.l10n.L10n;
 import freenet.support.Fields;
-import freenet.support.SizeUtil;
 import freenet.support.api.LongCallback;

 /** Long config variable */
@@ -19,7 +18,7 @@

        public LongOption(SubConfig conf, String optionName, long defaultValue, 
String defaultValueString, 
                        int sortOrder, boolean expert, boolean forceWrite, 
String shortDesc, String longDesc, LongCallback cb) {
-               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DATA_TYPE_NUMBER);
+               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DataType.NUMBER);
                this.defaultValue = defaultValue;
                this.cb = cb;
                this.currentValue = defaultValue;
@@ -28,7 +27,7 @@

        public LongOption(SubConfig conf, String optionName, String 
defaultValueString, 
                        int sortOrder, boolean expert, boolean forceWrite, 
String shortDesc, String longDesc, LongCallback cb) {
-               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DATA_TYPE_NUMBER);
+               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DataType.NUMBER);
                this.defaultValue = Fields.parseLong(defaultValueString);
                this.cb = cb;
                this.currentValue = defaultValue;

Modified: trunk/freenet/src/freenet/config/Option.java
===================================================================
--- trunk/freenet/src/freenet/config/Option.java        2008-08-14 00:35:04 UTC 
(rev 21830)
+++ trunk/freenet/src/freenet/config/Option.java        2008-08-14 07:39:51 UTC 
(rev 21831)
@@ -25,15 +25,15 @@
        /** The configCallback associated to the Option */
        protected final ConfigCallback cb;

-       public final static int DATA_TYPE_STRING = 0;
-       public final static int DATA_TYPE_NUMBER = 1;
-       public final static int DATA_TYPE_BOOLEAN = 2;
-       public final static int DATA_TYPE_STRING_ARRAY = 3;
+       public static enum DataType {
+               STRING, NUMBER, BOOLEAN, STRING_ARRAY
+       };

        /** Data type : used to make it possible to make user inputs more 
friendly in FCP apps */
-       final int dataType;
+       final DataType dataType;

-       Option(SubConfig config, String name, ConfigCallback cb, int sortOrder, 
boolean expert, boolean forceWrite, String shortDesc, String longDesc, int 
dataType) {
+       Option(SubConfig config, String name, ConfigCallback cb, int sortOrder, 
boolean expert, boolean forceWrite,
+               String shortDesc, String longDesc, DataType dataType) {
                this.config = config;
                this.name = name;
                this.cb = cb;
@@ -94,16 +94,20 @@
                return sortOrder;
        }

-       public int getDataType() {
+       public DataType getDataType() {
                return dataType;
        }

        public String getDataTypeStr() {
                switch(dataType) {
-               case(DATA_TYPE_STRING): return "string";
-               case(DATA_TYPE_NUMBER): return "number";
-               case(DATA_TYPE_BOOLEAN): return "boolean";
-               case(DATA_TYPE_STRING_ARRAY): return "stringArray";
+               case STRING:
+                       return "string";
+               case NUMBER:
+                       return "number";
+               case BOOLEAN:
+                       return "boolean";
+               case STRING_ARRAY:
+                       return "stringArray";
                default: return null;
                }
        }

Modified: trunk/freenet/src/freenet/config/PersistentConfig.java
===================================================================
--- trunk/freenet/src/freenet/config/PersistentConfig.java      2008-08-14 
00:35:04 UTC (rev 21830)
+++ trunk/freenet/src/freenet/config/PersistentConfig.java      2008-08-14 
07:39:51 UTC (rev 21831)
@@ -36,10 +36,10 @@
        }

        public SimpleFieldSet exportFieldSet(boolean withDefaults) {
-               return 
exportFieldSet(Config.CONFIG_REQUEST_TYPE_CURRENT_SETTINGS, withDefaults);
+               return exportFieldSet(Config.RequestType.CURRENT_SETTINGS, 
withDefaults);
        }

-       public SimpleFieldSet exportFieldSet(int configRequestType, boolean 
withDefaults) {
+       public SimpleFieldSet exportFieldSet(Config.RequestType 
configRequestType, boolean withDefaults) {
                SimpleFieldSet fs = new SimpleFieldSet(true);
                SubConfig[] configs;
                synchronized(this) {

Modified: trunk/freenet/src/freenet/config/ShortOption.java
===================================================================
--- trunk/freenet/src/freenet/config/ShortOption.java   2008-08-14 00:35:04 UTC 
(rev 21830)
+++ trunk/freenet/src/freenet/config/ShortOption.java   2008-08-14 07:39:51 UTC 
(rev 21831)
@@ -12,7 +12,7 @@

        public ShortOption(SubConfig conf, String optionName, short 
defaultValue, int sortOrder, 
                        boolean expert, boolean forceWrite, String shortDesc, 
String longDesc, ShortCallback cb) {
-               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DATA_TYPE_NUMBER);
+               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DataType.NUMBER);
                this.defaultValue = defaultValue;
                this.cb = cb;
                this.currentValue = defaultValue;

Modified: trunk/freenet/src/freenet/config/StringArrOption.java
===================================================================
--- trunk/freenet/src/freenet/config/StringArrOption.java       2008-08-14 
00:35:04 UTC (rev 21830)
+++ trunk/freenet/src/freenet/config/StringArrOption.java       2008-08-14 
07:39:51 UTC (rev 21831)
@@ -18,7 +18,7 @@

        public StringArrOption(SubConfig conf, String optionName, String[] 
defaultValue, int sortOrder, 
                        boolean expert, boolean forceWrite, String shortDesc, 
String longDesc, StringArrCallback cb) {
-               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DATA_TYPE_STRING_ARRAY);
+               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DataType.STRING_ARRAY);
                this.defaultValue = (defaultValue==null)?new 
String[0]:defaultValue;
                this.cb = cb;
                this.currentValue = (defaultValue==null)?new 
String[0]:defaultValue;

Modified: trunk/freenet/src/freenet/config/StringOption.java
===================================================================
--- trunk/freenet/src/freenet/config/StringOption.java  2008-08-14 00:35:04 UTC 
(rev 21830)
+++ trunk/freenet/src/freenet/config/StringOption.java  2008-08-14 07:39:51 UTC 
(rev 21831)
@@ -13,7 +13,7 @@

        public StringOption(SubConfig conf, String optionName, String 
defaultValue, int sortOrder, 
                        boolean expert, boolean forceWrite, String shortDesc, 
String longDesc, StringCallback cb) {
-               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DATA_TYPE_STRING);
+               super(conf, optionName, cb, sortOrder, expert, forceWrite, 
shortDesc, longDesc, Option.DataType.STRING);
                this.defaultValue = defaultValue;
                this.cb = cb;
                this.currentValue = defaultValue;

Modified: trunk/freenet/src/freenet/config/SubConfig.java
===================================================================
--- trunk/freenet/src/freenet/config/SubConfig.java     2008-08-14 00:35:04 UTC 
(rev 21830)
+++ trunk/freenet/src/freenet/config/SubConfig.java     2008-08-14 07:39:51 UTC 
(rev 21831)
@@ -3,8 +3,8 @@
  * http://www.gnu.org/ for further details of the GPL. */
 package freenet.config;

+import java.util.Iterator;
 import java.util.LinkedHashMap;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.Map.Entry;
@@ -195,10 +195,10 @@
        }

        public SimpleFieldSet exportFieldSet(boolean withDefaults) {
-               return 
exportFieldSet(Config.CONFIG_REQUEST_TYPE_CURRENT_SETTINGS, withDefaults);
+               return exportFieldSet(Config.RequestType.CURRENT_SETTINGS, 
withDefaults);
        }

-       public SimpleFieldSet exportFieldSet(int configRequestType, boolean 
withDefaults) {
+       public SimpleFieldSet exportFieldSet(Config.RequestType 
configRequestType, boolean withDefaults) {
                SimpleFieldSet fs = new SimpleFieldSet(true);
                // FIXME is any locking at all necessary here? After it has 
finished init, it's constant...
                Map.Entry[] entries;
@@ -214,34 +214,35 @@
                        Option o = (Option) entry.getValue();
 //                     if(logMINOR)
 //                             Logger.minor(this, "Key="+key+" 
value="+o.getValueString()+" default="+o.isDefault());
-                       if(configRequestType == 
Config.CONFIG_REQUEST_TYPE_CURRENT_SETTINGS && (!withDefaults) && o.isDefault() 
&& (!o.forceWrite)) {
+                       if (configRequestType == 
Config.RequestType.CURRENT_SETTINGS && (!withDefaults) && o.isDefault()
+                               && (!o.forceWrite)) {
                                if(logMINOR)
                                        Logger.minor(this, "Skipping "+key+" - 
"+o.isDefault());
                                continue;
                        }
                        switch (configRequestType) {
-                               case 
Config.CONFIG_REQUEST_TYPE_CURRENT_SETTINGS:
+                               case CURRENT_SETTINGS:
                                        fs.putSingle(key, o.getValueString());
                                        break;
-                               case 
Config.CONFIG_REQUEST_TYPE_DEFAULT_SETTINGS:
+                               case DEFAULT_SETTINGS:
                                        fs.putSingle(key, o.getDefault());
                                        break;
-                               case Config.CONFIG_REQUEST_TYPE_SORT_ORDER:
+                               case SORT_ORDER:
                                        fs.put(key, o.getSortOrder());
                                        break;
-                               case Config.CONFIG_REQUEST_TYPE_EXPERT_FLAG:
+                               case EXPERT_FLAG:
                                        fs.put(key, o.isExpert());
                                        break;
-                               case 
Config.CONFIG_REQUEST_TYPE_FORCE_WRITE_FLAG:
+                               case FORCE_WRITE_FLAG:
                                        fs.put(key, o.isForcedWrite());
                                        break;
-                               case 
Config.CONFIG_REQUEST_TYPE_SHORT_DESCRIPTION:
+                               case SHORT_DESCRIPTION:
                                        fs.putSingle(key, 
L10n.getString(o.getShortDesc()));
                                        break;
-                               case 
Config.CONFIG_REQUEST_TYPE_LONG_DESCRIPTION:
+                               case LONG_DESCRIPTION:
                                        fs.putSingle(key, 
L10n.getString(o.getLongDesc()));
                                        break;
-                               case Config.CONFIG_REQUEST_TYPE_DATA_TYPE:
+                               case DATA_TYPE:
                                        fs.putSingle(key, o.getDataTypeStr());
                                        break;
                                default:

Modified: trunk/freenet/src/freenet/node/fcp/ConfigData.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ConfigData.java  2008-08-14 00:35:04 UTC 
(rev 21830)
+++ trunk/freenet/src/freenet/node/fcp/ConfigData.java  2008-08-14 07:39:51 UTC 
(rev 21831)
@@ -38,49 +38,49 @@
        public SimpleFieldSet getFieldSet() {
                SimpleFieldSet fs = new SimpleFieldSet(true);
                if(withCurrent) {
-                       SimpleFieldSet current = 
node.config.exportFieldSet(Config.CONFIG_REQUEST_TYPE_CURRENT_SETTINGS, true);
+                       SimpleFieldSet current = 
node.config.exportFieldSet(Config.RequestType.CURRENT_SETTINGS, true);
                        if(!current.isEmpty()) {
                                fs.put("current", current);
                        }
                }
                if(withDefaults) {
-                       SimpleFieldSet defaultSettings = 
node.config.exportFieldSet(Config.CONFIG_REQUEST_TYPE_DEFAULT_SETTINGS, false);
+                       SimpleFieldSet defaultSettings = 
node.config.exportFieldSet(Config.RequestType.DEFAULT_SETTINGS, false);
                        if(!defaultSettings.isEmpty()) {
                                fs.put("default", defaultSettings);
                        }
                }
                if(withSortOrder) {
-                       SimpleFieldSet sortOrder = 
node.config.exportFieldSet(Config.CONFIG_REQUEST_TYPE_SORT_ORDER, false);
+                       SimpleFieldSet sortOrder = 
node.config.exportFieldSet(Config.RequestType.SORT_ORDER, false);
                        if(!sortOrder.isEmpty()) {
                                fs.put("sortOrder", sortOrder);
                        }
                }
                if(withExpertFlag) {
-                       SimpleFieldSet expertFlag = 
node.config.exportFieldSet(Config.CONFIG_REQUEST_TYPE_EXPERT_FLAG, false);
+                       SimpleFieldSet expertFlag = 
node.config.exportFieldSet(Config.RequestType.EXPERT_FLAG, false);
                        if(!expertFlag.isEmpty()) {
                                fs.put("expertFlag", expertFlag);
                        }
                }
                if(withForceWriteFlag) {
-                       SimpleFieldSet forceWriteFlag = 
node.config.exportFieldSet(Config.CONFIG_REQUEST_TYPE_FORCE_WRITE_FLAG, false);
+                       SimpleFieldSet forceWriteFlag = 
node.config.exportFieldSet(Config.RequestType.FORCE_WRITE_FLAG, false);
                        if(!forceWriteFlag.isEmpty()) {
                                fs.put("forceWriteFlag", forceWriteFlag);
                        }
                }
                if(withShortDescription) {
-                       SimpleFieldSet shortDescription = 
node.config.exportFieldSet(Config.CONFIG_REQUEST_TYPE_SHORT_DESCRIPTION, false);
+                       SimpleFieldSet shortDescription = 
node.config.exportFieldSet(Config.RequestType.SHORT_DESCRIPTION, false);
                        if(!shortDescription.isEmpty()) {
                                fs.put("shortDescription", shortDescription);
                        }
                }
                if(withLongDescription) {
-                       SimpleFieldSet longDescription = 
node.config.exportFieldSet(Config.CONFIG_REQUEST_TYPE_LONG_DESCRIPTION, false);
+                       SimpleFieldSet longDescription = 
node.config.exportFieldSet(Config.RequestType.LONG_DESCRIPTION, false);
                        if(!longDescription.isEmpty()) {
                                fs.put("longDescription", longDescription);
                        }
                }
                if(withDataTypes) {
-                       SimpleFieldSet type = 
node.config.exportFieldSet(Config.CONFIG_REQUEST_TYPE_DATA_TYPE, false);
+                       SimpleFieldSet type = 
node.config.exportFieldSet(Config.RequestType.DATA_TYPE, false);
                        if(!type.isEmpty()) {
                                fs.put("dataType", type);
                        }


Reply via email to