Sha256: edf254fbed618a9b6fec89500dc42b136f3f02459c06858e0280baae9a024773

Contents?: true

Size: 1.01 KB

Versions: 208

Compression:

Stored size: 1.01 KB

Contents

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;
    }

}

Version data entries

208 entries across 208 versions & 1 rubygems

Version Path
trackler-2.2.1.9 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.1.8 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.1.7 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.1.6 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.1.5 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.1.4 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.1.3 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.1.2 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.1.1 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.1.0 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.0.6 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.0.5 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.0.4 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.0.3 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.0.2 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.0.1 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.2.0.0 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.1.0.55 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.1.0.54 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.1.0.53 tracks/java/exercises/series/src/example/java/Series.java