ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1546597 - in /ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent: ConfigurationHandler.java impl/ConfigurationHandlerImpl.java
Date Fri, 29 Nov 2013 16:18:42 GMT
Author: jawi
Date: Fri Nov 29 16:18:42 2013
New Revision: 1546597

URL: http://svn.apache.org/r1546597
Log:
Added method to obtain integer value from configuration and fixed the implementation to return
the default value for invalid configured numbers.


Modified:
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java?rev=1546597&r1=1546596&r2=1546597&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java Fri
Nov 29 16:18:42 2013
@@ -36,13 +36,6 @@ import java.util.Set;
 public interface ConfigurationHandler {
 
     /**
-     * Return an unmodifiable copy of the configuration keys.
-     * 
-     * @return The set of keys
-     */
-    Set<String> keySet();
-
-    /**
      * Retrieve the configuration value associated with the key, or the specified default.
      * 
      * @param key
@@ -54,12 +47,15 @@ public interface ConfigurationHandler {
     String get(String key, String defaultValue);
 
     /**
-     * Store a configuration value.
+     * Retrieve the configuration value associated with the key, or the specified default.
      * 
-     * @param props
-     *            the properties to put, cannot be <code>null</code>.
+     * @param key
+     *            The key, must not be <code>null</code>
+     * @param defaultValue
+     *            The default value
+     * @return The associated value if it exists, otherwise the default value
      */
-    void putAll(Map<String, String> props);
+    boolean getBoolean(String key, boolean defaultValue);
 
     /**
      * Retrieve the configuration value associated with the key, or the specified default.
@@ -70,7 +66,7 @@ public interface ConfigurationHandler {
      *            The default value
      * @return The associated value if it exists, otherwise the default value
      */
-    long getLong(String key, long defaultValue);
+    int getInt(String key, int defaultValue);
 
     /**
      * Retrieve the configuration value associated with the key, or the specified default.
@@ -81,5 +77,20 @@ public interface ConfigurationHandler {
      *            The default value
      * @return The associated value if it exists, otherwise the default value
      */
-    boolean getBoolean(String key, boolean defaultValue);
+    long getLong(String key, long defaultValue);
+
+    /**
+     * Return an unmodifiable copy of the configuration keys.
+     * 
+     * @return The set of keys
+     */
+    Set<String> keySet();
+
+    /**
+     * Store a configuration value.
+     * 
+     * @param props
+     *            the properties to put, cannot be <code>null</code>.
+     */
+    void putAll(Map<String, String> props);
 }

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java?rev=1546597&r1=1546596&r2=1546597&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
(original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
Fri Nov 29 16:18:42 2013
@@ -77,12 +77,31 @@ public class ConfigurationHandlerImpl ex
     }
 
     @Override
+    public int getInt(String key, int defaultValue) {
+        String value = get(key, "");
+        try {
+            if (!"".equals(value)) {
+                return Integer.decode(value);
+            }
+        }
+        catch (NumberFormatException exception) {
+            // Ignore; return default...
+        }
+        return defaultValue;
+    }
+
+    @Override
     public long getLong(String key, long defaultValue) {
         String value = get(key, "");
-        if (value.equals("")) {
-            return defaultValue;
+        try {
+            if (!"".equals(value)) {
+                return Long.decode(value);
+            }
+        }
+        catch (NumberFormatException exception) {
+            // Ignore; return default...
         }
-        return Long.parseLong(value);
+        return defaultValue;
     }
 
     @Override



Mime
View raw message