@ SuppressWarnings ( "unchecked" ) protected static boolean sameType ( Collection [ ] cols ) { List all = new LinkedList ( ) ; for ( Collection col : cols ) { all . addAll ( col ) ; } if ( all . isEmpty ( ) ) return true ; Object first = all . get ( 0 ) ; //trying to determine the base class of the collections //special case for Numbers Class baseClass ; if ( first instanceof Number ) { baseClass = Number . class ; } else if ( first == null ) { baseClass = NullObject . class ; } else { baseClass = first . getClass ( ) ; } for ( Collection col : cols ) { for ( Object o : col ) { if ( ! baseClass . isInstance ( o ) ) { return false ; } } } return true ; }
Determines if all items of this array are of the same type .