Skip to content

Commit 4f0d5eb

Browse files
Refactor: Use Java 17 features (records, pattern matching, var, lambdas)
Co-authored-by: ChristianHoesel <[email protected]>
1 parent 9e930b0 commit 4f0d5eb

File tree

3 files changed

+24
-125
lines changed

3 files changed

+24
-125
lines changed

de.bitctrl.dav.toolset.appanalyzer/src/main/java/de/bitctrl/dav/toolset/appanalyzer/Exporter.java

Lines changed: 9 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -58,74 +58,15 @@
5858
*/
5959
public class Exporter extends Thread {
6060

61-
private static class SummaryKey {
62-
63-
private final String rolle;
64-
private final SystemObjectType type;
65-
private final AttributeGroup atg;
66-
private final Aspect asp;
67-
68-
SummaryKey(final String rolle, final SystemObjectType type, final AttributeGroup atg, final Aspect asp) {
69-
this.rolle = rolle;
70-
this.type = type;
71-
this.atg = atg;
72-
this.asp = asp;
73-
}
74-
75-
@Override
76-
public int hashCode() {
77-
final int prime = 31;
78-
int result = 1;
79-
result = (prime * result) + ((asp == null) ? 0 : asp.hashCode());
80-
result = (prime * result) + ((atg == null) ? 0 : atg.hashCode());
81-
result = (prime * result) + ((rolle == null) ? 0 : rolle.hashCode());
82-
result = (prime * result) + ((type == null) ? 0 : type.hashCode());
83-
return result;
84-
}
85-
86-
@Override
87-
public boolean equals(final Object obj) {
88-
if (this == obj) {
89-
return true;
90-
}
91-
if (obj == null) {
92-
return false;
93-
}
94-
if (!(obj instanceof SummaryKey)) {
95-
return false;
96-
}
97-
final SummaryKey other = (SummaryKey) obj;
98-
if (asp == null) {
99-
if (other.asp != null) {
100-
return false;
101-
}
102-
} else if (!asp.equals(other.asp)) {
103-
return false;
104-
}
105-
if (atg == null) {
106-
if (other.atg != null) {
107-
return false;
108-
}
109-
} else if (!atg.equals(other.atg)) {
110-
return false;
111-
}
112-
if (rolle == null) {
113-
if (other.rolle != null) {
114-
return false;
115-
}
116-
} else if (!rolle.equals(other.rolle)) {
117-
return false;
118-
}
119-
if (type == null) {
120-
if (other.type != null) {
121-
return false;
122-
}
123-
} else if (!type.equals(other.type)) {
124-
return false;
125-
}
126-
return true;
127-
}
128-
61+
/**
62+
* Key for summarizing export data by role, type, attribute group and aspect.
63+
*
64+
* @param rolle the role
65+
* @param type the system object type
66+
* @param atg the attribute group
67+
* @param asp the aspect
68+
*/
69+
private record SummaryKey(String rolle, SystemObjectType type, AttributeGroup atg, Aspect asp) {
12970
}
13071

13172
private final Set<SystemObject> exportApplications = new HashSet<>();

de.bitctrl.dav.toolset.archivcheck/src/main/java/de/bitctrl/dav/toolset/archivcheck/AkkumulationKey.java

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,48 +26,11 @@
2626

2727
package de.bitctrl.dav.toolset.archivcheck;
2828

29-
import java.util.Objects;
30-
31-
class AkkumulationKey {
32-
33-
private Object atg;
34-
private Object asp;
35-
36-
AkkumulationKey(final Object atg, final Object aspect) {
37-
this.atg = atg;
38-
this.asp = aspect;
39-
}
40-
41-
@Override
42-
public boolean equals(final Object obj) {
43-
44-
if (this == obj) {
45-
return true;
46-
}
47-
if (obj instanceof AkkumulationKey) {
48-
final AkkumulationKey akkKey = (AkkumulationKey) obj;
49-
return Objects.equals(asp, akkKey.asp) && Objects.equals(atg, akkKey.atg);
50-
}
51-
52-
return false;
53-
}
54-
55-
public Object getAsp() {
56-
return asp;
57-
}
58-
59-
public Object getAtg() {
60-
return atg;
61-
}
62-
63-
@Override
64-
public int hashCode() {
65-
return Objects.hash(asp, atg);
66-
}
67-
68-
@Override
69-
public String toString() {
70-
return "AkkumulationKey [atg=" + atg + ", asp=" + asp + "]";
71-
}
72-
29+
/**
30+
* Key for accumulating archive data by attribute group and aspect.
31+
*
32+
* @param atg the attribute group
33+
* @param asp the aspect
34+
*/
35+
record AkkumulationKey(Object atg, Object asp) {
7336
}

de.bitctrl.dav.toolset.archivcheck/src/main/java/de/bitctrl/dav/toolset/archivcheck/ArchivSizer.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private static class ResultSet {
7272
}
7373

7474
private boolean isValid() {
75-
return (this.object instanceof SystemObject) && ((SystemObject) this.object).isValid();
75+
return (this.object instanceof SystemObject sysObj) && sysObj.isValid();
7676
}
7777

7878
private boolean isMissed() {
@@ -113,12 +113,12 @@ public void initialize(final ClientDavInterface connection) throws Exception {
113113

114114
model = connection.getDataModel();
115115

116-
final File startDir = new File(baseDir);
116+
var startDir = new File(baseDir);
117117
if (!startDir.isDirectory()) {
118118
throw new InvalidArgumentException(baseDir + " ist kein Verzeichnis");
119119
}
120120

121-
final File[] listFiles = startDir.listFiles();
121+
var listFiles = startDir.listFiles();
122122
if (listFiles != null) {
123123
for (final File child : listFiles) {
124124
if (child.getName().startsWith(ArchivSizer.OBJ_DIR_PREFIX)) {
@@ -127,12 +127,7 @@ public void initialize(final ClientDavInterface connection) throws Exception {
127127
}
128128
}
129129

130-
Collections.sort(results, new Comparator<ResultSet>() {
131-
@Override
132-
public int compare(final ResultSet o1, final ResultSet o2) {
133-
return ((Long) o2.size.getSize()).compareTo(o1.size.getSize());
134-
}
135-
});
130+
Collections.sort(results, (o1, o2) -> ((Long) o2.size.getSize()).compareTo(o1.size.getSize()));
136131

137132
try (PrintWriter output = new PrintWriter(new FileWriter(outputFile))) {
138133
printheader(output);
@@ -153,7 +148,7 @@ public int compare(final ResultSet o1, final ResultSet o2) {
153148

154149
private void printResult(final PrintWriter output, final ResultSet set) {
155150

156-
final StringBuffer result = new StringBuffer(200);
151+
var result = new StringBuilder(200);
157152
if (set.isMissed()) {
158153
result.append('-');
159154
} else if (!set.isValid()) {
@@ -191,12 +186,12 @@ private void printheader(final PrintWriter output) {
191186
}
192187

193188
private void printAkkResult(final PrintWriter output, final AkkumulationKey key, final SizeSet value) {
194-
final StringBuffer result = new StringBuffer(200);
189+
var result = new StringBuilder(200);
195190
result.append(value.getSetCount());
196191
result.append(';');
197-
result.append(key.getAtg());
192+
result.append(key.atg());
198193
result.append(';');
199-
result.append(key.getAsp());
194+
result.append(key.asp());
200195
result.append(';');
201196
result.append(value.getSize());
202197
result.append(';');

0 commit comments

Comments
 (0)