-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplit.java
More file actions
98 lines (82 loc) · 2.71 KB
/
Split.java
File metadata and controls
98 lines (82 loc) · 2.71 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
97
98
package de.donnerbart.split.model;
import de.donnerbart.split.FormatOption;
import de.donnerbart.split.util.FormatUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
public final class Split implements Comparable<Split> {
private final @NotNull Set<TestCase> tests = new HashSet<>();
private final @NotNull FormatOption formatOption;
private final int index;
private double totalRecordedTime;
public Split(final @NotNull FormatOption formatOption, final int index) {
this.formatOption = formatOption;
this.index = index;
}
public void add(final @NotNull TestCase testCase) {
tests.add(testCase);
totalRecordedTime += testCase.time();
}
public int index() {
return index;
}
public @NotNull String formatIndex() {
return String.format("%02d", index);
}
public @NotNull Set<TestCase> tests() {
return tests;
}
public @NotNull List<String> sortedTests() {
return tests.stream() //
.sorted(Comparator.reverseOrder()) //
.map(TestCase::name) //
.map(test -> switch (formatOption) {
case LIST -> test;
case GRADLE -> "--tests " + test;
}).collect(Collectors.toList());
}
public double totalRecordedTime() {
return totalRecordedTime;
}
@Override
public int compareTo(final @NotNull Split o) {
final var compareTime = Double.compare(totalRecordedTime, o.totalRecordedTime);
if (compareTime != 0) {
return compareTime;
}
final var compareTestCount = Double.compare(tests.size(), o.tests.size());
if (compareTestCount != 0) {
return compareTestCount;
}
return Double.compare(index, o.index);
}
@Override
public boolean equals(final @Nullable Object o) {
if (!(o instanceof final Split split)) {
return false;
}
return index == split.index;
}
@Override
public int hashCode() {
return Objects.hashCode(index);
}
@Override
public @NotNull String toString() {
return "Split{" +
"index=" +
formatIndex() +
", totalRecordedTime=" +
FormatUtil.formatTime(totalRecordedTime) +
", testCount=" +
tests.size() +
", tests=" +
tests.stream().map(TestCase::name).collect(Collectors.joining(", ")) +
'}';
}
}