File tree Expand file tree Collapse file tree
tcases-lib/src/main/java/org/cornutum/tcases/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77
88package org .cornutum .tcases .util ;
99
10+ import java .util .Arrays ;
1011import java .util .Collection ;
12+ import java .util .Collections ;
1113import java .util .Iterator ;
14+ import java .util .List ;
1215import java .util .Map ;
16+ import java .util .Optional ;
1317import java .util .stream .Stream ;
1418import java .util .stream .StreamSupport ;
1519
@@ -35,6 +39,14 @@ public static <T> Stream<T> toStream( Iterator<T> iterator)
3539 return StreamSupport .stream ( iterable .spliterator (), false );
3640 }
3741
42+ /**
43+ * If the given value is present, returns it as a singleton list. Otherwise, returns an empty list.
44+ */
45+ public static <T > List <T > iterableOf ( Optional <T > value )
46+ {
47+ return value .map ( Arrays ::asList ).orElse ( Collections .emptyList ());
48+ }
49+
3850 /**
3951 * Returns a stream containing the members of the given collection.
4052 */
You can’t perform that action at this time.
0 commit comments