*
* @return A list of COSBase.
*/
public static COSArray converterToCOSArray( List<?> cosObjectableList )
{
COSArray array = null;
if( cosObjectableList != null )
{
if( cosObjectableList instanceof COSArrayList )
{
//if it is already a COSArrayList then we don't want to recreate the array, we want to reuse it.
array = ((COSArrayList<?>)cosObjectableList).array;
}
else
{
array = new COSArray();
Iterator<?> iter = cosObjectableList.iterator();
while( iter.hasNext() )
{
Object next = iter.next();
if( next instanceof String )
{
array.add( new COSString( (String)next ) );
}
else if( next instanceof Integer || next instanceof Long )
{
array.add( COSInteger.get( ((Number)next).longValue() ) );
}
else if( next instanceof Float || next instanceof Double )
{
array.add( new COSFloat( ((Number)next).floatValue() ) );
}
else if( next instanceof COSObjectable )
{
COSObjectable object = (COSObjectable)next;
array.add( object.getCOSObject() );
}
else if( next instanceof DualCOSObjectable )
{
DualCOSObjectable object = (DualCOSObjectable)next;
array.add( object.getFirstCOSObject() );
array.add( object.getSecondCOSObject() );
}
else if( next == null )
{
array.add( COSNull.NULL );
}
else
{
throw new RuntimeException( "Error: Don't know how to convert type to COSBase '" +
next.getClass().getName() + "'" );