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.0.8.47 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.46 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.45 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.44 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.43 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.42 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.41 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.40 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.39 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.38 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.37 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.36 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.35 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.34 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.33 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.32 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.31 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.30 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.29 tracks/java/exercises/series/src/example/java/Series.java
trackler-2.0.8.28 tracks/java/exercises/series/src/example/java/Series.java