directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r471654 - /directory/branches/apacheds-schema/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java
Date Mon, 06 Nov 2006 07:27:07 GMT
Author: elecharny
Date: Sun Nov  5 23:27:06 2006
New Revision: 471654

URL: http://svn.apache.org/viewvc?view=rev&rev=471654
Log:
Added some javadoc
Used generics

Modified:
    directory/branches/apacheds-schema/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java

Modified: directory/branches/apacheds-schema/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds-schema/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java?view=diff&rev=471654&r1=471653&r2=471654
==============================================================================
--- directory/branches/apacheds-schema/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java
(original)
+++ directory/branches/apacheds-schema/apacheds/core/src/main/java/org/apache/directory/server/core/configuration/ConfigurationUtil.java
Sun Nov  5 23:27:06 2006
@@ -23,7 +23,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -31,7 +30,6 @@
 
 import org.apache.directory.shared.ldap.ldif.Entry;
 
-
 /**
  * A utility class that provides common functionality while validating configuration.
  * 
@@ -42,13 +40,20 @@
 {
     /**
      * Checks all elements of the specified set is of the specified type,
-     * and returns cloned set.
+     * and returns a cloned set. The objects are *not* cloned
+     * 
+     * @param set The set we want to check and to clone. All the members of this set
+     * must be instances of the <code>type</code> parameter
+     * @param type The Class which each elements of the set should be instance of.
+     * 
+     * @return A cloned set of checked objects.
      * 
      * @throws ConfigurationException if the specified set has an element of wrong type
      */
-    public static Set getTypeSafeSet( Set set, Class type )
+    public static <T extends Object> Set<T> getTypeSafeSet( Set<T> set,
Class<T> type )
     {
-        Set newSet = new HashSet();
+        // Note : we can't use the clone() method on Set<T> instances ...
+        Set<T> newSet = new HashSet<T>();
         getTypeSafeCollection( set, type, newSet );
         return newSet;
     }
@@ -56,39 +61,52 @@
 
     /**
      * Checks all elements of the specified list is of the specified type,
-     * and returns cloned list.
+     * and returns a cloned list.  The objects are *not* cloned
      * 
-     * @throws ConfigurationException if the specified set has an element of wrong type
+     * @param list The list we want to check and to clone. All the members of this list
+     * must be instances of the <code>type</code> parameter
+     * @param type The Class which each elements of the list should be instance of.
+     * 
+     * @return A cloned list of checked objects.
+     * 
+     * @throws ConfigurationException if the specified list has an element of wrong type
      */
-    public static List getTypeSafeList( List list, Class type )
+    public static <T extends Object> List<T> getTypeSafeList( List<T> list,
Class<T> type )
     {
-        List newList = new ArrayList();
+        // Note : we can't use the clone() method on List<T> instances ...
+        List<T> newList = new ArrayList<T>();
         getTypeSafeCollection( list, type, newList );
         return newList;
     }
 
-
-    public static void getTypeSafeCollection( Collection collection, Class type, Collection
newCollection )
+    /**
+     * An intern method which check the type of each object into a collection
+     * before copying them into a new collection
+     */
+    private static <T extends Object> void getTypeSafeCollection( Collection<T>
collection, Class<T> type, Collection<T> newCollection )
     {
-        Iterator i = collection.iterator();
-        while ( i.hasNext() )
+        for ( T object:collection )
         {
-            Object e = i.next();
-            if ( !type.isAssignableFrom( e.getClass() ) )
+            if ( !type.isAssignableFrom( object.getClass() ) )
             {
-                throw new ConfigurationException( "Invalid element type: " + e.getClass()
+ " (expected " + type );
+                throw new ConfigurationException( "Invalid element type: " + object.getClass()
+ " (expected " + type + ")" );
             }
-            newCollection.add( e );
+
+            newCollection.add( object );
         }
     }
 
-
     /**
      * Returns the clone of the specified set.
+     *
+     * @param set The set we want to clone.
+     * 
+     * @return A cloned Set
      */
-    public static Set getClonedSet( Set set )
+    public static <T extends Object> Set<T> getClonedSet( Set<T> set )
     {
-        Set newSet = new HashSet();
+        // Note : we can't use the clone() method on List<T> instances ...
+        Set<T> newSet = new HashSet<T>();
         newSet.addAll( set );
         return newSet;
     }
@@ -96,10 +114,15 @@
 
     /**
      * Returns the clone of the specified list.
+     * 
+     * @param list The list we want to clone.
+     * 
+     * @return A cloned list
      */
-    public static List getClonedList( List list )
+    public static <T extends Object>List<T> getClonedList( List<T> list
)
     {
-        List newList = new ArrayList();
+        // Note : we can't use the clone() method on List<T> instances ...
+        List<T> newList = new ArrayList<T>();
         newList.addAll( list );
         return newList;
     }
@@ -107,16 +130,20 @@
 
     /**
      * Returns the deep clone of the specified {@link Attributes} list.
+     * 
+     * @param list The list we want to clone.
+     * 
+     * @return A cloned list of attributes. Attributes themselves are *not* cloned.
      */
-    public static List getClonedAttributesList( List list ) throws CloneNotSupportedException
+    public static List<Entry> getClonedAttributesList( List<Entry> list ) throws
CloneNotSupportedException
     {
-        List newList = new ArrayList();
-        Iterator i = list.iterator();
+        List<Entry> newList = new ArrayList<Entry>();
         
-        while ( i.hasNext() )
+        for ( Entry entry:list )
         {
-            newList.add( ( ( Entry ) i.next() ).clone() );
+            newList.add( entry );
         }
+        
         return newList;
     }
 
@@ -124,6 +151,8 @@
     /**
      * Throws a {@link ConfigurationException} if the specified port number
      * is out of range.
+     * 
+     * @param port The port to validate
      */
     public static void validatePortNumber( int port )
     {
@@ -131,10 +160,5 @@
         {
             throw new ConfigurationException( "Invalid port number: " + port );
         }
-    }
-
-
-    private ConfigurationUtil()
-    {
     }
 }



Mime
View raw message