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

GSetUtil

public final class GSetUtil extends Object
Utilities for working with sets using JDK 1.5 generics.

Fields Summary
Constructors Summary
private GSetUtil()

		// disallow instantiation
	
Methods Summary
public static voidaddArray(java.util.Set set, T[] array)

		for( final T item : array )
		{
			set.add( item );
		}
	
public static java.util.HashSetcopySet(java.util.Set s1)
Create a new Set containing all members of another. The returned Set is always a HashSet.

		final HashSet<T>	set	= new HashSet<T>();
		
		set.addAll( s1 );
		
		return( set );
	
public static TgetSingleton(java.util.Set s)

		if ( s.size() != 1 )
		{
			throw new IllegalArgumentException( s.toString() );
		}
		return( s.iterator().next() );
	
public static java.util.SetintersectSets(java.util.Set set1, java.util.Set set2)
Return a new Set of all items in both set1 and set2.

		final Set<T>	result	= newSet( set1 );
		result.retainAll( set2 );
		
		return( result );
	
public static java.util.SetnewNotCommonSet(java.util.Set set1, java.util.Set set2)
Return a new Set of all items not common to both sets.

		final Set<T>	result	= newSet( set1, set2 );
		final Set<T>	common	= intersectSets( set1, set2);
		
		result.removeAll( common );
		
		return( result );
	
public static java.util.SetnewSet(java.util.Set s1, java.util.Set s2)

	    final Set<T>    both    = new HashSet<T>();
	    both.addAll( s1 );
	    both.addAll( s2 );
	    
	    return both;
	
public static java.util.SetnewSet(T[] objects, int startIndex, int numItems)
Create a new Set containing all array elements.

		final Set<T>	set	= new HashSet<T>();
		
		for( int i = 0; i < numItems; ++i )
		{
			set.add( objects[ startIndex + i ] );
		}

		return( set );
	
public static java.util.SetnewSet(java.util.Collection c)

		final HashSet<T>	set	= new HashSet<T>();
		
		set.addAll( c );
		
		return( set );
	
public static java.util.SetnewSet(T item)
Create a new Set with one member.

		final Set<T>	set	= new HashSet<T>();
		set.add( item );
		
		return( set );
	
public static java.util.SetnewSet(T m1, T m2)

		final HashSet<T>	set	= new HashSet<T>();
		
		set.add( m1 );
		set.add( m2 );
		
		return( set );
	
public static java.util.SetnewSet(T m1, T m2, T m3, T m4)

		final HashSet<T>	set	= new HashSet<T>();
		
		set.add( m1 );
		set.add( m2 );
		set.add( m3 );
		set.add( m4 );
		
		return( set );
	
public static java.util.SetnewSet(T[] objects)
Create a new Set containing all array elements.

		return( newSet( objects, 0, objects.length ) );
	
public static java.util.SetnewSingletonSet(T m1)
Create a new Set with one member. Additional items may be added.

		final Set<T>	set	= new HashSet<T>();
		
		set.add( m1 );
		
		return( set );
	
public static java.util.SetnewStringSet(java.lang.String args)

	    return newUnmodifiableSet( args );
	
public static java.util.SetnewStringSet(java.lang.Object args)

	    final Set<String>   set   = new HashSet<String>();
	    
	    for( final Object o : args )
	    {
	        set.add( o == null ? null : "" + o );
	    }
	    return set;
	
public static java.util.SetnewUnmodifiableSet(T args)

	    final Set<T>   set   = new HashSet<T>();
	    
	    for( final T s : args )
	    {
	        set.add( s );
	    }
	    return set;
	
public static java.util.SetnewUnmodifiableStringSet(java.lang.String args)

	    return Collections.unmodifiableSet( newStringSet( args ) );
	
public static java.util.SetremoveSet(java.util.Set set1, java.util.Set set2)
Return a new Set of all items in set1 not in set2.

		final Set<T>	result	= SetUtil.newSet( set1 );
		result.removeAll( set2 );
		
		return( result );
	
public static java.lang.String[]toSortedStringArray(java.util.Set s)

		final String[]	strings	= toStringArray( s );
		
		Arrays.sort( strings );
		
		return( strings );
	
public static java.lang.String[]toStringArray(java.util.Set s)
Convert a Set to a String[]

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