@Test public void testListUtils() { List<?> l = Arrays.asList( 1, 2, 3 ); l = Arrays.asList( l, 4, 5, 6 ); l = Arrays.asList( l, 7, 8, 9 ); l = ListUtils.flatten( l ); assertEquals( 9, l.size() ); logger.info( JsonUtils.mapToFormattedJsonString( l ) ); l = Arrays.asList( Arrays.asList( 1, 2, 3 ), 4, 5, 6, Arrays.asList( 7, 8, 9 ) ); l = ListUtils.flatten( l ); assertEquals( 9, l.size() ); logger.info( JsonUtils.mapToFormattedJsonString( l ) ); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public static List<?> flatten( Collection<?> l ) { boolean hasCollection = false; for ( Object o : l ) { if ( o instanceof Collection ) { hasCollection = true; break; } } if ( !hasCollection && ( l instanceof List ) ) { return ( List<?> ) l; } List newList = new ArrayList(); for ( Object o : l ) { if ( o instanceof List ) { newList.addAll( flatten( ( List ) o ) ); } else { newList.add( o ); } } return newList; }
ListUtils extends org.apache.commons.collections.ListUtils { @SuppressWarnings({ "unchecked", "rawtypes" }) public static List<?> flatten( Collection<?> l ) { boolean hasCollection = false; for ( Object o : l ) { if ( o instanceof Collection ) { hasCollection = true; break; } } if ( !hasCollection && ( l instanceof List ) ) { return ( List<?> ) l; } List newList = new ArrayList(); for ( Object o : l ) { if ( o instanceof List ) { newList.addAll( flatten( ( List ) o ) ); } else { newList.add( o ); } } return newList; } }
ListUtils extends org.apache.commons.collections.ListUtils { @SuppressWarnings({ "unchecked", "rawtypes" }) public static List<?> flatten( Collection<?> l ) { boolean hasCollection = false; for ( Object o : l ) { if ( o instanceof Collection ) { hasCollection = true; break; } } if ( !hasCollection && ( l instanceof List ) ) { return ( List<?> ) l; } List newList = new ArrayList(); for ( Object o : l ) { if ( o instanceof List ) { newList.addAll( flatten( ( List ) o ) ); } else { newList.add( o ); } } return newList; }  }
ListUtils extends org.apache.commons.collections.ListUtils { @SuppressWarnings({ "unchecked", "rawtypes" }) public static List<?> flatten( Collection<?> l ) { boolean hasCollection = false; for ( Object o : l ) { if ( o instanceof Collection ) { hasCollection = true; break; } } if ( !hasCollection && ( l instanceof List ) ) { return ( List<?> ) l; } List newList = new ArrayList(); for ( Object o : l ) { if ( o instanceof List ) { newList.addAll( flatten( ( List ) o ) ); } else { newList.add( o ); } } return newList; }  static A first( List<A> list ); static A last( List<A> list ); static Integer firstInteger( List<A> list ); static Long firstLong( List<A> list ); static Boolean firstBoolean( List<A> list ); static UUID firstUuid( List<A> list ); static boolean isEmpty( List<?> list ); static List<T> dequeueCopy( List<T> list ); static List<T> initCopy( List<T> list ); static T dequeue( List<T> list ); static List<T> queue( List<T> list, T item ); static List<T> requeue( List<T> list, T item ); @SuppressWarnings({ "unchecked", "rawtypes" }) static List<?> flatten( Collection<?> l ); static boolean anyNull( List<?> l ); static boolean anyNull( Object... objects ); }
ListUtils extends org.apache.commons.collections.ListUtils { @SuppressWarnings({ "unchecked", "rawtypes" }) public static List<?> flatten( Collection<?> l ) { boolean hasCollection = false; for ( Object o : l ) { if ( o instanceof Collection ) { hasCollection = true; break; } } if ( !hasCollection && ( l instanceof List ) ) { return ( List<?> ) l; } List newList = new ArrayList(); for ( Object o : l ) { if ( o instanceof List ) { newList.addAll( flatten( ( List ) o ) ); } else { newList.add( o ); } } return newList; }  static A first( List<A> list ); static A last( List<A> list ); static Integer firstInteger( List<A> list ); static Long firstLong( List<A> list ); static Boolean firstBoolean( List<A> list ); static UUID firstUuid( List<A> list ); static boolean isEmpty( List<?> list ); static List<T> dequeueCopy( List<T> list ); static List<T> initCopy( List<T> list ); static T dequeue( List<T> list ); static List<T> queue( List<T> list, T item ); static List<T> requeue( List<T> list, T item ); @SuppressWarnings({ "unchecked", "rawtypes" }) static List<?> flatten( Collection<?> l ); static boolean anyNull( List<?> l ); static boolean anyNull( Object... objects );  }