Skip to content

Commit cb2746a

Browse files
committed
Argument validation, linter
1 parent 57eacea commit cb2746a

18 files changed

+453
-181
lines changed

de.zabuza.fastcdc4j.examples/src/de/zabuza/fastcdc4j/examples/CompareFiles.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @author Daniel Tischner {@literal <zabuza.dev@gmail.com>}
1818
*/
19-
@SuppressWarnings({"UseOfSystemOutOrSystemErr", "ClassIndependentOfModule", "ClassOnlyUsedInOneModule"})
19+
@SuppressWarnings({ "UseOfSystemOutOrSystemErr", "ClassIndependentOfModule", "ClassOnlyUsedInOneModule" })
2020
enum CompareFiles {
2121
;
2222

de.zabuza.fastcdc4j.examples/src/de/zabuza/fastcdc4j/examples/LocalChunkCache.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
*
1313
* @author Daniel Tischner {@literal <zabuza.dev@gmail.com>}
1414
*/
15-
@SuppressWarnings({"UseOfSystemOutOrSystemErr", "ClassIndependentOfModule", "ClassOnlyUsedInOneModule"})
15+
@SuppressWarnings({ "UseOfSystemOutOrSystemErr", "ClassIndependentOfModule", "ClassOnlyUsedInOneModule" })
1616
enum LocalChunkCache {
1717
;
1818

1919
/**
2020
* Starts the application.
2121
*
2222
* @param args Two arguments, the path to the build and the path to the local chunk cache
23+
*
24+
* @throws IOException If an IOException occurred
2325
*/
2426
public static void main(final String[] args) throws IOException {
2527
if (args.length != 2) {

de.zabuza.fastcdc4j.examples/src/de/zabuza/fastcdc4j/examples/PatchBenchmark.java

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,59 @@
99
import java.util.*;
1010
import java.util.concurrent.atomic.AtomicLong;
1111
import java.util.stream.Collectors;
12+
import java.util.stream.Stream;
1213

1314
/**
1415
* Class offering a {@link #main(String[])} method that compares builds in a given folder with each other and creates
1516
* files with patch sizes.
1617
*
1718
* @author Daniel Tischner {@literal <zabuza.dev@gmail.com>}
1819
*/
19-
@SuppressWarnings("UseOfSystemOutOrSystemErr")
20-
final class PatchBenchmark {
20+
@SuppressWarnings({ "UseOfSystemOutOrSystemErr", "MagicNumber" })
21+
enum PatchBenchmark {
22+
;
23+
2124
/**
2225
* Starts the application.
2326
*
2427
* @param args One arguments, the path to the builds to benchmark.
28+
*
29+
* @throws IOException If an IOException occurred
2530
*/
2631
public static void main(final String[] args) throws IOException {
2732
if (args.length != 1) {
2833
throw new IllegalArgumentException(
2934
"Expected one arguments denoting the path to the folder containing the builds to benchmark.");
3035
}
3136

32-
Path basePath = Path.of(args[0]);
33-
List<String> builds = Files.list(basePath)
34-
.filter(Files::isDirectory)
35-
.map(Path::getFileName)
36-
.map(Path::toString)
37-
.sorted()
38-
.collect(Collectors.toList());
37+
final Path basePath = Path.of(args[0]);
38+
final List<String> builds;
39+
try (final Stream<Path> stream = Files.list(basePath)) {
40+
builds = stream.filter(Files::isDirectory)
41+
.map(Path::getFileName)
42+
.map(Path::toString)
43+
.sorted()
44+
.collect(Collectors.toList());
45+
}
3946

40-
List<Map.Entry<String, String>> buildsToCompare = new ArrayList<>();
47+
final List<Map.Entry<String, String>> buildsToCompare = new ArrayList<>();
4148
for (int i = 0; i < builds.size() - 1; i++) {
42-
String previous = builds.get(i);
43-
String current = builds.get(i + 1);
49+
final String previous = builds.get(i);
50+
final String current = builds.get(i + 1);
4451

4552
buildsToCompare.add(Map.entry(previous, current));
4653
}
4754

4855
System.out.printf("Comparing %d patch scenarios%n", buildsToCompare.size());
4956

50-
List<String> patchDataLines = new ArrayList<>();
57+
final Collection<String> patchDataLines = new ArrayList<>();
5158
patchDataLines.add("patch,name,fsc2mb,fastcdc2mb,fastcdc8kb");
5259
// patchDataLines.add("patch,name,rtpal262kb");
53-
List<String> buildDataLines = new ArrayList<>();
60+
final Collection<String> buildDataLines = new ArrayList<>();
5461
buildDataLines.add("version,name,size");
5562
int i = 1;
56-
for (Map.Entry<String, String> comparison : buildsToCompare) {
63+
for (final Map.Entry<String, String> comparison : buildsToCompare) {
64+
//noinspection HardcodedFileSeparator
5765
System.out.printf("====================== %d / %d patch scenarios ======================%n", i,
5866
buildsToCompare.size());
5967

@@ -76,11 +84,11 @@ public static void main(final String[] args) throws IOException {
7684
comparison.getValue());
7785
System.out.println();
7886

79-
List<Long> patchSizes = new ArrayList<>();
80-
AtomicLong previousBuildSize = new AtomicLong();
81-
AtomicLong currentBuildSize = new AtomicLong();
87+
final Collection<Long> patchSizes = new ArrayList<>();
88+
final AtomicLong previousBuildSize = new AtomicLong();
89+
final AtomicLong currentBuildSize = new AtomicLong();
8290
descriptionToChunker.forEach((description, chunker) -> {
83-
PatchSummary summary = PatchSummary.computePatchSummary(chunker, previousBuild, currentBuild);
91+
final PatchSummary summary = PatchSummary.computePatchSummary(chunker, previousBuild, currentBuild);
8492

8593
patchSizes.add(summary.getPatchSize());
8694

@@ -90,24 +98,22 @@ public static void main(final String[] args) throws IOException {
9098
.getTotalSize());
9199
});
92100

93-
StringJoiner patchSizesJoiner = new StringJoiner(",");
101+
final StringJoiner patchSizesJoiner = new StringJoiner(",");
94102
patchSizesJoiner.add(String.valueOf(i + 1));
95-
patchSizesJoiner.add(previousBuild.getFileName()
96-
.toString() + "-" + currentBuild.getFileName()
97-
.toString());
103+
patchSizesJoiner.add(previousBuild.getFileName() + "-" + currentBuild.getFileName());
98104
patchSizes.forEach(size -> patchSizesJoiner.add(String.valueOf(size)));
99105
patchDataLines.add(patchSizesJoiner.toString());
100106

101107
if (i == 1) {
102-
StringJoiner buildDataJoiner = new StringJoiner(",");
108+
final StringJoiner buildDataJoiner = new StringJoiner(",");
103109
buildDataJoiner.add("1");
104110
buildDataJoiner.add(previousBuild.getFileName()
105111
.toString());
106112
buildDataJoiner.add(String.valueOf(previousBuildSize.get()));
107113
buildDataLines.add(buildDataJoiner.toString());
108114
}
109115

110-
StringJoiner buildDataJoiner = new StringJoiner(",");
116+
final StringJoiner buildDataJoiner = new StringJoiner(",");
111117
buildDataJoiner.add(String.valueOf(i + 1));
112118
buildDataJoiner.add(currentBuild.getFileName()
113119
.toString());
@@ -116,8 +122,8 @@ public static void main(final String[] args) throws IOException {
116122

117123
i++;
118124

119-
Path buildDataPath = Path.of("benchmark_build_data.csv");
120-
Path patchDataPath = Path.of("benchmark_patch_data.csv");
125+
final Path buildDataPath = Path.of("benchmark_build_data.csv");
126+
final Path patchDataPath = Path.of("benchmark_patch_data.csv");
121127
Files.write(buildDataPath, buildDataLines);
122128
Files.write(patchDataPath, patchDataLines);
123129
System.out.println("Updated benchmark build data: " + buildDataPath);

0 commit comments

Comments
 (0)