You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2009/11/12 16:31:17 UTC
svn commit: r835416 -
/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Author: elecharny
Date: Thu Nov 12 15:31:17 2009
New Revision: 835416
URL: http://svn.apache.org/viewvc?rev=835416&view=rev
Log:
o Added a setToString() method
o Used for() instead of an iterator
Modified:
directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=835416&r1=835415&r2=835416&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java (original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java Thu Nov 12 15:31:17 2009
@@ -22,15 +22,15 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileFilter;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.io.FileFilter;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@@ -39,6 +39,8 @@
import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
+import com.sun.org.apache.regexp.internal.RESyntaxException;
+
/**
* Various string manipulation methods that are more efficient then chaining
@@ -3197,9 +3199,43 @@
StringBuilder sb = new StringBuilder();
boolean isFirst = true;
- Iterator<?> iter = list.iterator();
+ for ( Object elem : list )
+ {
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ", " );
+ }
+
+ sb.append( elem );
+ }
- while ( iter.hasNext() )
+ return sb.toString();
+ }
+
+
+
+
+ /**
+ * Utility method that return a String representation of a set
+ *
+ * @param set The set to transform to a string
+ * @return A csv string
+ */
+ public static final String setToString( Set<?> set )
+ {
+ if ( ( set == null ) || ( set.size() == 0 ) )
+ {
+ return "";
+ }
+
+ StringBuilder sb = new StringBuilder();
+ boolean isFirst = true;
+
+ for ( Object elem : set )
{
if ( isFirst )
{
@@ -3210,7 +3246,7 @@
sb.append( ", " );
}
- sb.append( iter.next() );
+ sb.append( elem );
}
return sb.toString();
@@ -3233,12 +3269,10 @@
StringBuffer sb = new StringBuffer();
- Iterator<?> iter = list.iterator();
-
- while ( iter.hasNext() )
+ for ( Object elem : list )
{
sb.append( tabs );
- sb.append( iter.next() );
+ sb.append( elem );
sb.append( '\n' );
}