FileDocCategorySizeDatePackage
CollectionUtil.javaAPI DocGlassfish v2 API3994Fri May 04 22:31:06 BST 2007com.sun.appserv.management.util.misc

CollectionUtil

public final class CollectionUtil extends Object
Various helper utilities for Collections.

Fields Summary
Constructors Summary
private CollectionUtil()

		// disallow instantiation
	
Methods Summary
public static voidaddArray(java.util.Collection c, T[] array)
Add all items in an array to a set.

		for( int i = 0; i < array.length; ++i )
		{
			c.add( array[ i ] );
		}
	
public static TgetSingleton(java.util.Collection s)

		if ( s.size() != 1 )
		{
			throw new IllegalArgumentException();
		}
		return( s.iterator().next() );
	
public static booleanisAllStrings(java.util.Collection c)

return
true if all elements are String, and there is at least one element

	    return IteratorUtil.getUniformClass( c.iterator() ) == String.class;
	
public static T[]toArray(java.util.Collection c, java.lang.Class elementClass)

param
c the Collection
param
elementClass the type of the element, must be non-primitive
return
array of [] elements

	    final T[]  items  = ArrayUtil.newArray( elementClass, c.size() );
	    
		c.toArray( items );
		
		return items;
	
public static java.lang.StringtoString(java.util.Collection c, java.lang.String delim)

return
a String

	    final String[]  strings   = toStringArray( c );
	    Arrays.sort( strings );
	    
		return StringUtil.toString( delim, (Object[])strings );
	
public static java.lang.StringtoString(java.util.Collection c)

	    return toString( c, ", " );
	
public static java.lang.String[]toStringArray(java.util.Collection c)

return
String[]

		final String[]	strings	= new String[ c.size() ];
		
		int	i = 0;
		for( final Object o : c )
		{
			strings[ i ]	= SmartStringifier.toString( o );
			++i;
		}
		
		return( strings );