Use pattern matching switch cases

This commit is contained in:
AsamK 2023-10-17 19:52:35 +02:00
parent 80c1a6d2af
commit 8d55dfb66b
27 changed files with 395 additions and 380 deletions

View file

@ -55,24 +55,26 @@ public class GetUserStatusCommand implements JsonRpcLocalCommand {
}
// Output
if (outputWriter instanceof JsonWriter jsonWriter) {
var jsonUserStatuses = registered.entrySet().stream().map(entry -> {
final var number = entry.getValue().number();
final var uuid = entry.getValue().uuid();
return new JsonUserStatus(entry.getKey(), number, uuid == null ? null : uuid.toString(), uuid != null);
}).toList();
jsonWriter.write(jsonUserStatuses);
} else {
final var writer = (PlainTextWriter) outputWriter;
for (var entry : registered.entrySet()) {
final var userStatus = entry.getValue();
writer.println("{}: {}{}",
entry.getKey(),
userStatus.uuid() != null,
userStatus.unrestrictedUnidentifiedAccess() ? " (unrestricted sealed sender)" : "");
switch (outputWriter) {
case JsonWriter writer -> {
var jsonUserStatuses = registered.entrySet().stream().map(entry -> {
final var number = entry.getValue().number();
final var uuid = entry.getValue().uuid();
return new JsonUserStatus(entry.getKey(),
number,
uuid == null ? null : uuid.toString(),
uuid != null);
}).toList();
writer.write(jsonUserStatuses);
}
case PlainTextWriter writer -> {
for (var entry : registered.entrySet()) {
final var userStatus = entry.getValue();
writer.println("{}: {}{}",
entry.getKey(),
userStatus.uuid() != null,
userStatus.unrestrictedUnidentifiedAccess() ? " (unrestricted sealed sender)" : "");
}
}
}
}