File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import org .junit .jupiter .api .Test ;
44
5+ import java .util .stream .Collectors ;
6+ import java .util .stream .IntStream ;
7+
58import static org .junit .jupiter .api .Assertions .assertEquals ;
69
710public class Accumul {
@@ -36,9 +39,23 @@ public static String accum(String s) {
3639 return result .substring (0 , result .length () - 1 );
3740 }
3841
42+ public static String streamAccum (String s ) {
43+ return s == null || s .isEmpty () ? "" :
44+ IntStream .range (0 , s .length ())
45+ .mapToObj (i -> Character .toUpperCase (s .charAt (i )) +
46+ String .valueOf (Character .toLowerCase (s .charAt (i ))).repeat (i ))
47+ .collect (Collectors .joining ("-" ));
48+ }
49+
3950 @ Test
4051 public void test () {
4152 assertEquals ("Z-Pp-Ggg-Llll-Nnnnn-Rrrrrr-Xxxxxxx-Qqqqqqqq-Eeeeeeeee-Nnnnnnnnnn-Uuuuuuuuuuu" ,
4253 accum ("ZpglnRxqenU" ));
4354 }
55+
56+ @ Test
57+ public void testStreamAccum () {
58+ assertEquals ("Z-Pp-Ggg-Llll-Nnnnn-Rrrrrr-Xxxxxxx-Qqqqqqqq-Eeeeeeeee-Nnnnnnnnnn-Uuuuuuuuuuu" ,
59+ streamAccum ("ZpglnRxqenU" ));
60+ }
4461}
You can’t perform that action at this time.
0 commit comments