forked from exercism/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeries.java
More file actions
39 lines (32 loc) · 1.01 KB
/
Series.java
File metadata and controls
39 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Series {
private final int digitsSize;
private List<Integer> digits;
public Series(String string) {
this.digits = Arrays
.asList(string.split(("")))
.stream()
.map(digit -> Integer.parseInt(digit))
.collect(Collectors.toList());
this.digitsSize = this.digits.size();
}
public List<List<Integer>> slices(int num) {
if (num > this.digitsSize) {
throw new IllegalArgumentException("Slice size is too big.");
}
final int limit = this.digitsSize - num + 1;
List<List<Integer>> result = new ArrayList<>(limit);
List<Integer> tmp;
for (int i = 0; i < limit; i++) {
tmp = this.digits.subList(i, i + num);
result.add(tmp);
}
return result;
}
public List<Integer> getDigits() {
return digits;
}
}