Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 34680 invoked from network); 16 Aug 2007 06:52:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Aug 2007 06:52:10 -0000 Received: (qmail 24764 invoked by uid 500); 16 Aug 2007 06:52:08 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 24722 invoked by uid 500); 16 Aug 2007 06:52:08 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 24711 invoked by uid 99); 16 Aug 2007 06:52:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Aug 2007 23:52:08 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Aug 2007 06:52:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 691EC1A981F; Wed, 15 Aug 2007 23:51:48 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r566506 - /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/aci/UserClass.java Date: Thu, 16 Aug 2007 06:51:48 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070816065148.691EC1A981F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Wed Aug 15 23:51:47 2007 New Revision: 566506 URL: http://svn.apache.org/viewvc?view=rev&rev=566506 Log: Using generic get rid of iterators Modified: 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/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=566506&r1=566505&r2=566506 ============================================================================== --- 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 Wed Aug 15 23:51:47 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 names; /** * Creates a new instance. * - * @param names - * a set of names + * @param names a set of names */ - protected NamedUserClass(Set names) + protected NamedUserClass( Set 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( names ) ); } /** * Returns the set of all names. */ - public Set getNames() + public Set 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 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 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 subtreeSpecifications; /** @@ -299,24 +289,16 @@ * @param subtreeSpecs * the collection of unrefined {@link SubtreeSpecification}s. */ - public Subtree(Collection subtreeSpecs) + public Subtree( Collection 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( subtreeSpecs ) ); } /** * Returns the collection of unrefined {@link SubtreeSpecification}s. */ - public Collection getSubtreeSpecifications() + public Collection 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( " }" ); } } }