directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r566851 - in /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci: ACITuple.java UserClass.java
Date Thu, 16 Aug 2007 21:09:38 GMT
Author: elecharny
Date: Thu Aug 16 14:09:37 2007
New Revision: 566851

URL: http://svn.apache.org/viewvc?view=rev&rev=566851
Log:
Using generic, get rid of some iterator, minor javadoc cleaning

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ACITuple.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserClass.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ACITuple.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ACITuple.java?view=diff&rev=566851&r1=566850&r2=566851
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ACITuple.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/ACITuple.java
Thu Aug 16 14:09:37 2007
@@ -25,7 +25,6 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Set;
 
 
@@ -40,13 +39,13 @@
 {
     private static final long serialVersionUID = 4353150626941232371L;
 
-    private final Collection userClasses;
+    private final Collection<UserClass> userClasses;
 
     private final AuthenticationLevel authenticationLevel;
 
-    private final Collection protectedItems;
+    private final Collection<ProtectedItem> protectedItems;
 
-    private final Set microOperations;
+    private final Set<MicroOperation> microOperations;
 
     private final boolean grant;
 
@@ -69,34 +68,14 @@
      * @param precedence
      *            the precedence of this tuple (<tt>0</tt>-<tt>255</tt>)
      */
-    public ACITuple(Collection userClasses, AuthenticationLevel authenticationLevel, Collection
protectedItems,
-        Set microOperations, boolean grant, int precedence)
+    public ACITuple( 
+            Collection<UserClass> userClasses, 
+            AuthenticationLevel authenticationLevel, 
+            Collection<ProtectedItem> protectedItems,
+            Set<MicroOperation> microOperations, 
+            boolean grant, 
+            int precedence )
     {
-        for ( Iterator i = userClasses.iterator(); i.hasNext(); )
-        {
-            if ( !( i.next() instanceof UserClass ) )
-            {
-                throw new IllegalArgumentException( "userClasses contains an element which
is not a user classs." );
-            }
-        }
-
-        for ( Iterator i = protectedItems.iterator(); i.hasNext(); )
-        {
-            if ( !( i.next() instanceof ProtectedItem ) )
-            {
-                throw new IllegalArgumentException( "protectedItems contains an element which
is not a protected item." );
-            }
-        }
-
-        for ( Iterator i = microOperations.iterator(); i.hasNext(); )
-        {
-            if ( !( i.next() instanceof MicroOperation ) )
-            {
-                throw new IllegalArgumentException(
-                    "microOperations contains an element which is not a micro operation."
);
-            }
-        }
-
         if ( authenticationLevel == null )
         {
             throw new NullPointerException( "authenticationLevel" );
@@ -107,10 +86,10 @@
             throw new IllegalArgumentException( "precedence: " + precedence );
         }
 
-        this.userClasses = Collections.unmodifiableCollection( new ArrayList( userClasses
) );
+        this.userClasses = Collections.unmodifiableCollection( new ArrayList<UserClass>(
userClasses ) );
         this.authenticationLevel = authenticationLevel;
-        this.protectedItems = Collections.unmodifiableCollection( new ArrayList( protectedItems
) );
-        this.microOperations = Collections.unmodifiableSet( new HashSet( microOperations
) );
+        this.protectedItems = Collections.unmodifiableCollection( new ArrayList<ProtectedItem>(
protectedItems ) );
+        this.microOperations = Collections.unmodifiableSet( new HashSet<MicroOperation>(
microOperations ) );
         this.grant = grant;
         this.precedence = precedence;
     }
@@ -119,7 +98,7 @@
     /**
      * Returns the collection of {@link UserClass}es this tuple relates to.
      */
-    public Collection getUserClasses()
+    public Collection<UserClass> getUserClasses()
     {
         return userClasses;
     }
@@ -137,7 +116,7 @@
     /**
      * Returns the collection of {@link ProtectedItem}s this tuple relates.
      */
-    public Collection getProtectedItems()
+    public Collection<ProtectedItem> getProtectedItems()
     {
         return protectedItems;
     }
@@ -146,7 +125,7 @@
     /**
      * Returns the set of {@link MicroOperation}s this tuple relates.
      */
-    public Set getMicroOperations()
+    public Set<MicroOperation> getMicroOperations()
     {
         return microOperations;
     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserClass.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserClass.java?view=diff&rev=566851&r1=566850&r2=566851
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserClass.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserClass.java
Thu Aug 16 14:09:37 2007
@@ -25,7 +25,6 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Set;
 
 import org.apache.directory.shared.ldap.subtree.SubtreeSpecification;
@@ -128,33 +127,24 @@
      */
     private static abstract class NamedUserClass extends UserClass
     {
-        protected final Set names;
+        protected final Set<javax.naming.Name> names;
 
 
         /**
          * Creates a new instance.
          * 
-         * @param names
-         *            a set of names
+         * @param names a set of names
          */
-        protected NamedUserClass(Set names)
+        protected NamedUserClass( Set<javax.naming.Name> names )
         {
-            for ( Iterator i = names.iterator(); i.hasNext(); )
-            {
-                Object val = i.next();
-                if ( !( val instanceof javax.naming.Name ) )
-                {
-                    throw new IllegalArgumentException( "names contains a wrong element."
);
-                }
-            }
-            this.names = Collections.unmodifiableSet( new HashSet( names ) );
+            this.names = Collections.unmodifiableSet( new HashSet<javax.naming.Name>(
names ) );
         }
 
 
         /**
          * Returns the set of all names.
          */
-        public Set getNames()
+        public Set<javax.naming.Name> getNames()
         {
             return names;
         }
@@ -190,24 +180,26 @@
         
         public void printToBuffer( StringBuffer buffer )
         {
-            buffer.append( '{' );
-            buffer.append( ' ' );
+            boolean isFirst = true;
+            buffer.append( "{ " );
             
-            for ( Iterator it = names.iterator(); it.hasNext(); )
+            for ( javax.naming.Name name:names )
             {
-                javax.naming.Name name = ( javax.naming.Name ) it.next();
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    buffer.append( ", " );
+                }
+                
                 buffer.append( '"' );
                 buffer.append( name.toString() );
                 buffer.append( '"' );
-                
-                if(it.hasNext()) {
-                    buffer.append( ',' );
-                    buffer.append( ' ' );
-                }
             }
             
-            buffer.append( ' ' );
-            buffer.append( '}' );
+            buffer.append( " }" );
         }
     }
 
@@ -225,7 +217,7 @@
          * @param usernames
          *            the set of user DNs.
          */
-        public Name(Set usernames)
+        public Name( Set<javax.naming.Name> usernames )
         {
             super( usernames );
         }
@@ -239,8 +231,7 @@
         
         public void printToBuffer( StringBuffer buffer )
         {
-            buffer.append( "name" );
-            buffer.append( ' ' );
+            buffer.append( "name " );
             super.printToBuffer( buffer );
         }
     }
@@ -262,7 +253,7 @@
          * @param groupNames
          *            the set of group DNs.
          */
-        public UserGroup(Set groupNames)
+        public UserGroup( Set<javax.naming.Name> groupNames )
         {
             super( groupNames );
         }
@@ -276,8 +267,7 @@
         
         public void printToBuffer( StringBuffer buffer )
         {
-            buffer.append( "userGroup" );
-            buffer.append( ' ' );
+            buffer.append( "userGroup " );
             super.printToBuffer( buffer );
         }
     }
@@ -290,7 +280,7 @@
     {
         private static final long serialVersionUID = 3949337699049701332L;
 
-        protected final Collection subtreeSpecifications;
+        protected final Collection<SubtreeSpecification> subtreeSpecifications;
 
 
         /**
@@ -299,24 +289,16 @@
          * @param subtreeSpecs
          *            the collection of unrefined {@link SubtreeSpecification}s.
          */
-        public Subtree(Collection subtreeSpecs)
+        public Subtree( Collection<SubtreeSpecification> subtreeSpecs )
         {
-            for ( Iterator i = subtreeSpecs.iterator(); i.hasNext(); )
-            {
-                Object val = i.next();
-                if ( !( val instanceof SubtreeSpecification ) )
-                {
-                    throw new IllegalArgumentException( "subtreeSpecs contains a wrong element."
);
-                }
-            }
-            this.subtreeSpecifications = Collections.unmodifiableCollection( new ArrayList(
subtreeSpecs ) );
+            this.subtreeSpecifications = Collections.unmodifiableCollection( new ArrayList<SubtreeSpecification>(
subtreeSpecs ) );
         }
 
 
         /**
          * Returns the collection of unrefined {@link SubtreeSpecification}s.
          */
-        public Collection getSubtreeSpecifications()
+        public Collection<SubtreeSpecification> getSubtreeSpecifications()
         {
             return subtreeSpecifications;
         }
@@ -347,24 +329,24 @@
         
         public void printToBuffer( StringBuffer buffer )
         {
-            buffer.append( "subtree" );
-            buffer.append( ' ' );
-            buffer.append( '{' );
-            buffer.append( ' ' );
+            boolean isFirst = true;
+            buffer.append( "subtree { " );
             
-            for ( Iterator it = subtreeSpecifications.iterator(); it.hasNext(); )
+            for ( SubtreeSpecification ss:subtreeSpecifications )
             {
-                SubtreeSpecification ss = ( SubtreeSpecification ) it.next();
-                ss.printToBuffer( buffer );
-                
-                if(it.hasNext()) {
-                    buffer.append( ',' );
-                    buffer.append( ' ' );
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    buffer.append( ", " );
                 }
+                
+                ss.printToBuffer( buffer );
             }
             
-            buffer.append( ' ' );
-            buffer.append( '}' );
+            buffer.append( " }" );
         }
     }
 }



Mime
View raw message