directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 56910 - incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util
Date Mon, 08 Nov 2004 08:04:46 GMT
Author: akarasulu
Date: Mon Nov  8 00:04:45 2004
New Revision: 56910

Modified:
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/PropertiesUtils.java
Log:
Added extra method that works specifically against a hashtable instead
of a properties object.


Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/PropertiesUtils.java
==============================================================================
--- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/PropertiesUtils.java
(original)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/PropertiesUtils.java
Mon Nov  8 00:04:45 2004
@@ -435,14 +435,55 @@
     }
 
 
-    public static int get( Properties props, String key, int defaultValue )
+    /**
+     * Gets a property or entry value from a hashtable and tries to transform
+     * whatever the value may be to an primitive integer.
+     *
+     * @param ht the hashtable to access for the value
+     * @param key the key to use when accessing the ht
+     * @param defval the default value to use if the key is not contained in ht
+     * or if the value cannot be represented as a primitive integer.
+     * @return the primitive integer representation of a hashtable value
+     */
+    public static int get( Hashtable ht, Object key, int defval )
     {
-        if ( props == null || ! props.containsKey( key ) || props.getProperty( key ) == null
)
+        if ( ht == null || ! ht.containsKey( key ) || ht.get( key ) == null )
         {
-            return defaultValue;
+            return defval;
         }
 
-        throw new NotImplementedException();
+        Object obj = ht.get( key );
+
+        if ( obj instanceof Byte )
+        {
+            return ( ( Byte ) obj ).intValue();
+        }
+        if ( obj instanceof Short )
+        {
+            return ( ( Short ) obj ).intValue();
+        }
+        if ( obj instanceof Integer )
+        {
+            return ( ( Integer ) obj ).intValue();
+        }
+        if ( obj instanceof Long )
+        {
+            return ( ( Long ) obj ).intValue();
+        }
+        if ( obj instanceof String )
+        {
+            try
+            {
+                return Integer.parseInt( ( String ) obj );
+            }
+            catch( NumberFormatException ne )
+            {
+                ne.printStackTrace();
+                return defval;
+            }
+        }
+
+        return defval;
     }
 
 

Mime
View raw message