Skip to content

Commit 355a4e4

Browse files
Ovcharenko.AAOvcharenko.AA
authored andcommitted
Accumul
1 parent 53b437e commit 355a4e4

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/main/java/kyu7/Accumul.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import org.junit.jupiter.api.Test;
44

5+
import java.util.stream.Collectors;
6+
import java.util.stream.IntStream;
7+
58
import static org.junit.jupiter.api.Assertions.assertEquals;
69

710
public 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
}

0 commit comments

Comments
 (0)