-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSequence.java
More file actions
96 lines (81 loc) · 2.88 KB
/
Sequence.java
File metadata and controls
96 lines (81 loc) · 2.88 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2020-2025 nanoseeds
package tests;
import java.util.*;
public final class Sequence {
private String prefixOfFileName = "";
private static final String postfixOfTestout = "test.out";
private static final String postfixOfDatain = "data.in";
private static final String postfixOfDataout = "data.out";
private final int begin;
private final int end;
private final int maxLength;
public Sequence(int begin, int end) {
this(begin, end, 2);
}
public Sequence(int begin, int end, int maxLength) {
this.begin = begin;
this.end = end;
this.maxLength = maxLength;
}
public List<String> getSequence() {
final List<String> result = new ArrayList<>();
for (int i = begin; i <= end; ++i) {
result.add(Integer.toString(i));
}
return result;
}
public List<String> getSameLengthSequence() {
final int maxLen = maxLength == -1 ? getLength(end) : Math.max(maxLength, getLength(end));
final List<String> result = getSequence();
for (int i = 0; i < result.size(); ++i) {
final String item = result.get(i);
if (item.length() < maxLen) {
result.set(i, "0".repeat(maxLen - item.length()) + item);
}
}
return result;
}
private static int getLength(int value) {
int len = 0;
while (value > 0) {
len++;
value /= 10;
}
return len;
}
public List<FileTriple> getFiles(boolean sameLength) {
final List<String> seq = sameLength ? getSameLengthSequence() : getSequence();
final List<FileTriple> result = new ArrayList<>();
for (String item : seq) {
final String datain = prefixOfFileName + item + "." + postfixOfDatain;
final String dataout = prefixOfFileName + item + "." + postfixOfDataout;
final String testout = prefixOfFileName + item + "." + postfixOfTestout;
result.add(new FileTriple(datain, dataout, testout));
}
return result;
}
public static class FileTriple {
public final Triple<String, String, String> data;
public String datain() {
return data.getFirst();
}
public String dataout() {
return data.getSecond();
}
public String testout() {
return data.getThird();
}
public FileTriple(final String datain, final String dataout, final String testout) {
data = new Triple<>(datain, dataout, testout);
}
@Override
public String toString() {
return "FileTriple{" +
"datain='" + datain() + '\'' +
", dataout='" + dataout() + '\'' +
", testout='" + testout() + '\'' +
'}';
}
}
}