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

IteratorUtil

public final class IteratorUtil extends Object

Fields Summary
Constructors Summary
private IteratorUtil()

		// disallow instantiation
	
Methods Summary
public static java.lang.ClassgetUniformClass(java.util.Iterator iter)

param
iter
return
the Class of the elements, or null if all null or different

		Class	theClass	= null;
		
        Object next;
		if ( iter.hasNext() )
		{
            next   = iter.next();
			theClass	= (next == null) ? null : next.getClass();
		}

		while ( iter.hasNext() )
		{
            next    = iter.next();
            
			if ( next != null && next.getClass() != theClass )
			{
				theClass	= null;
				break;
			}
		}
		
		return( theClass );
	
public static booleanisUniformClass(java.util.Iterator iter, java.lang.Class theClass, boolean exactMatch)

param
iter
param
theClass
param
exactMatch if true, then subclasses are considered to be different
return
true if all items are of the same class

		boolean	isUniform	= true;
		
		while ( iter.hasNext() )
		{
            Object next = iter.next();
			final Class	nextClass	= (next == null) ? null : next.getClass();
			
			if ( nextClass != theClass && nextClass != null )
			{
				if ( exactMatch )
				{
					isUniform	= false;
					break;
				}
				
				if ( ! theClass.isAssignableFrom( nextClass ) )
				{
					isUniform	= false;
					break;
				}
			}
		}
		
		return( isUniform );
	
public static java.lang.Object[]toArray(java.util.Iterator iter)

		final List<T> list	= new ArrayList<T>();
		
		while ( iter.hasNext() )
		{
			final T	elem	= iter.next();
			list.add( elem );
		}
		
		final Object[]	result	= new Object[ list.size() ];
		list.toArray( result );
		
		return( ArrayConversion.specializeArray( result ) );