Author: j16sdiz
Date: 2008-08-14 07:40:13 +0000 (Thu, 14 Aug 2008)
New Revision: 21832

Modified:
   trunk/freenet/src/freenet/config/Config.java
   trunk/freenet/src/freenet/config/PersistentConfig.java
   trunk/freenet/src/freenet/config/SubConfig.java
   trunk/freenet/src/freenet/config/WrapperConfig.java
Log:
Generic

Modified: trunk/freenet/src/freenet/config/Config.java
===================================================================
--- trunk/freenet/src/freenet/config/Config.java        2008-08-14 07:39:51 UTC 
(rev 21831)
+++ trunk/freenet/src/freenet/config/Config.java        2008-08-14 07:40:13 UTC 
(rev 21832)
@@ -14,10 +14,10 @@
                CURRENT_SETTINGS, DEFAULT_SETTINGS, SORT_ORDER, EXPERT_FLAG, 
FORCE_WRITE_FLAG, SHORT_DESCRIPTION, LONG_DESCRIPTION, DATA_TYPE
        };

-       protected final LinkedHashMap configsByPrefix;
+       protected final LinkedHashMap<String, SubConfig> configsByPrefix;

        public Config() {
-               configsByPrefix = new LinkedHashMap();
+               configsByPrefix = new LinkedHashMap<String, SubConfig>();
        }

        public void register(SubConfig sc) {
@@ -45,10 +45,10 @@

        /** Fetch all the SubConfig's. Used by user-facing config thingies. */
        public synchronized SubConfig[] getConfigs() {
-               return (SubConfig[]) configsByPrefix.values().toArray(new 
SubConfig[configsByPrefix.size()]);
+               return configsByPrefix.values().toArray(new 
SubConfig[configsByPrefix.size()]);
        }

        public synchronized SubConfig get(String subConfig){
-               return (SubConfig)configsByPrefix.get(subConfig);
+               return configsByPrefix.get(subConfig);
        }
 }

Modified: trunk/freenet/src/freenet/config/PersistentConfig.java
===================================================================
--- trunk/freenet/src/freenet/config/PersistentConfig.java      2008-08-14 
07:39:51 UTC (rev 21831)
+++ trunk/freenet/src/freenet/config/PersistentConfig.java      2008-08-14 
07:40:13 UTC (rev 21832)
@@ -44,7 +44,7 @@
                SubConfig[] configs;
                synchronized(this) {
                        // FIXME maybe keep a cache of this?
-                       configs = (SubConfig[]) 
configsByPrefix.values().toArray(new SubConfig[configsByPrefix.size()]);
+                       configs = configsByPrefix.values().toArray(new 
SubConfig[configsByPrefix.size()]);
                }
                SubConfig current;
                for(int i=0;i<configs.length;i++) {

Modified: trunk/freenet/src/freenet/config/SubConfig.java
===================================================================
--- trunk/freenet/src/freenet/config/SubConfig.java     2008-08-14 07:39:51 UTC 
(rev 21831)
+++ trunk/freenet/src/freenet/config/SubConfig.java     2008-08-14 07:40:13 UTC 
(rev 21832)
@@ -22,9 +22,9 @@
 /**
  * A specific configuration block.
  */
-public class SubConfig implements Comparable {
+public class SubConfig implements Comparable<SubConfig> {

-       private final LinkedHashMap map;
+       private final LinkedHashMap<String, Option> map;
        public final Config config;
        final String prefix;
        private boolean hasInitialized;
@@ -32,7 +32,7 @@
        public SubConfig(String prefix, Config config) {
                this.config = config;
                this.prefix = prefix;
-               map = new LinkedHashMap();
+               map = new LinkedHashMap<String, Option>();
                hasInitialized = false;
                config.register(this);
        }
@@ -42,11 +42,11 @@
         * Used by e.g. webconfig.
         */
        public synchronized Option[] getOptions() {
-               return (Option[]) map.values().toArray(new Option[map.size()]);
+               return map.values().toArray(new Option[map.size()]);
        }

        public synchronized Option getOption(String option){
-               return (Option)map.get(option);
+               return map.get(option);
        }

        public void register(Option o) {
@@ -171,12 +171,12 @@
         * Set options from a SimpleFieldSet. Once we process an option, we 
must remove it.
         */
        public void setOptions(SimpleFieldSet sfs) {
-               Set entrySet = map.entrySet();
-               Iterator i = entrySet.iterator();
+               Set<Map.Entry<String, Option>> entrySet = map.entrySet();
+               Iterator<Entry<String, Option>> i = entrySet.iterator();
                while(i.hasNext()) {
-                       Map.Entry entry = (Map.Entry) i.next();
-                       String key = (String) entry.getKey();
-                       Option o = (Option) entry.getValue();
+                       Entry<String, Option> entry = i.next();
+                       String key = entry.getKey();
+                       Option o = entry.getValue();
                        String val = sfs.get(key);
                        if(val != null) {
                                try {
@@ -198,18 +198,18 @@
                return exportFieldSet(Config.RequestType.CURRENT_SETTINGS, 
withDefaults);
        }

-       public SimpleFieldSet exportFieldSet(Config.RequestType 
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;
+               Map.Entry<String, Option>[] entries;
                synchronized(this) {
-                       entries = (Entry[]) map.entrySet().toArray(new 
Map.Entry[map.size()]);
+                       entries = map.entrySet().toArray(new 
Map.Entry[map.size()]);
                }
                boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
                if(logMINOR)
                        Logger.minor(this, "Prefix="+prefix);
                for(int i=0;i<entries.length;i++) {
-                       Map.Entry entry = (Map.Entry) entries[i];
+                       Map.Entry<String, Option> entry = entries[i];
                        String key = (String) entry.getKey();
                        Option o = (Option) entry.getValue();
 //                     if(logMINOR)
@@ -260,12 +260,12 @@
         * @throws InvalidConfigValueException 
         */
        public void forceUpdate(String optionName) throws 
InvalidConfigValueException {
-               Option o = (Option) map.get(optionName);
+               Option o = map.get(optionName);
                o.forceUpdate();
        }

        public void set(String name, String value) throws 
InvalidConfigValueException {
-               Option o = (Option) map.get(name);
+               Option o = map.get(name);
                o.setValue(value);
        }

@@ -282,7 +282,7 @@
         * @param value The value of the option.
         */
        public void fixOldDefault(String name, String value) {
-               Option o = (Option) map.get(name);
+               Option o = map.get(name);
                if(o.getValueString().equals(value))
                        o.setDefault();
        }
@@ -295,7 +295,7 @@
         * @param value The value of the option.
         */
        public void fixOldDefaultRegex(String name, String value) {
-               Option o = (Option) map.get(name);
+               Option o = map.get(name);
                if(o.getValueString().matches(value))
                        o.setDefault();
        }
@@ -304,15 +304,11 @@
                return prefix;
        }

-       public int compareTo(Object o){
-               if((o == null) || !(o instanceof SubConfig)) return 0;
-               else{
-                       SubConfig second = (SubConfig) o;
-                       if(this.getPrefix().compareTo(second.getPrefix())>0)
-                               return 1;
-                       else
-                               return -1;
-               }
+       public int compareTo(SubConfig second) {
+               if (this.getPrefix().compareTo(second.getPrefix()) > 0)
+                       return 1;
+               else
+                       return -1;
        }

        public String getRawOption(String name) {

Modified: trunk/freenet/src/freenet/config/WrapperConfig.java
===================================================================
--- trunk/freenet/src/freenet/config/WrapperConfig.java 2008-08-14 07:39:51 UTC 
(rev 21831)
+++ trunk/freenet/src/freenet/config/WrapperConfig.java 2008-08-14 07:40:13 UTC 
(rev 21832)
@@ -24,12 +24,12 @@
  */
 public class WrapperConfig {

-       private static HashMap overrides = new HashMap();
+       private static HashMap<String, String> overrides = new HashMap<String, 
String>();

        public static String getWrapperProperty(String name) {
                synchronized(WrapperConfig.class) {
                        if(overrides.containsKey(name))
-                               return (String) overrides.get(name);
+                               return overrides.get(name);
                }
                return WrapperManager.getProperties().getProperty(name, null);
        }


Reply via email to