protected static void writeList ( Output out , List < ? > list ) { if ( ! list . isEmpty ( ) ) { int size = list . size ( ) ; // if its a small list, write it as an array if ( size < 100 ) { out . writeArray ( list ) ; return ; } // else we should check for lots of null values, // if there are over 80% then its probably best to do it as a map int nullCount = 0 ; for ( int i = 0 ; i < size ; i ++ ) { if ( list . get ( i ) == null ) { nullCount ++ ; } } if ( nullCount > ( size * 0.8 ) ) { out . writeMap ( list ) ; } else { out . writeArray ( list ) ; } } else { out . writeArray ( new Object [ ] { } ) ; } }
Writes a List out as an Object