From 23821e3a6bbdaad88b018e8ff9c9488dea94d4ea Mon Sep 17 00:00:00 2001 From: Brutus5000 Date: Wed, 27 Nov 2024 00:22:00 +0100 Subject: [PATCH] Apply OpenRewrite Java17 migration --- .../faforever/iceadapter/debug/DebugWindow.java | 16 ++++++++-------- .../iceadapter/debug/TextAreaLogAppender.java | 5 ++--- .../java/com/faforever/iceadapter/ice/Peer.java | 2 +- .../faforever/iceadapter/ice/PeerIceModule.java | 8 ++++++-- ice-adapter/src/test/java/IceTest.java | 2 +- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindow.java b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindow.java index 1de7bae..481aba0 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindow.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindow.java @@ -68,7 +68,7 @@ public void start(Stage stage) { scene = new Scene(root, WIDTH, HEIGHT); stage.setScene(scene); - stage.setTitle(String.format("FAF ICE adapter - Debugger - Build: %s", IceAdapter.VERSION)); + stage.setTitle("FAF ICE adapter - Debugger - Build: %s".formatted(IceAdapter.VERSION)); // stage.setOnCloseRequest(Event::consume); // stage.show(); @@ -98,11 +98,11 @@ public void startupComplete() { public void initStaticVariables() { runOnUIThread(() -> { - controller.versionLabel.setText(String.format("Version: %s", IceAdapter.VERSION)); - controller.userLabel.setText(String.format("User: %s(%d)", IceAdapter.login, IceAdapter.id)); - controller.rpcPortLabel.setText(String.format("RPC_PORT: %d", IceAdapter.RPC_PORT)); - controller.gpgnetPortLabel.setText(String.format("GPGNET_PORT: %d", IceAdapter.GPGNET_PORT)); - controller.lobbyPortLabel.setText(String.format("LOBBY_PORT: %d", IceAdapter.LOBBY_PORT)); + controller.versionLabel.setText("Version: %s".formatted(IceAdapter.VERSION)); + controller.userLabel.setText("User: %s(%d)".formatted(IceAdapter.login, IceAdapter.id)); + controller.rpcPortLabel.setText("RPC_PORT: %d".formatted(IceAdapter.RPC_PORT)); + controller.gpgnetPortLabel.setText("GPGNET_PORT: %d".formatted(IceAdapter.GPGNET_PORT)); + controller.lobbyPortLabel.setText("LOBBY_PORT: %d".formatted(IceAdapter.LOBBY_PORT)); }); } @@ -127,7 +127,7 @@ public void rpcStarted(CompletableFuture peerFuture) { }); peerFuture.thenAccept(peer -> runOnUIThread(() -> { controller.rpcClientStatus.setText( - String.format("RPCClient: %s", peer.getSocket().getInetAddress())); + "RPCClient: %s".formatted(peer.getSocket().getInetAddress())); })); } @@ -142,7 +142,7 @@ public void gpgnetStarted() { public void gpgnetConnectedDisconnected() { runOnUIThread(() -> { controller.gpgnetServerStatus.setText( - String.format("GPGNetClient: %s", GPGNetServer.isConnected() ? "connected" : "-")); + "GPGNetClient: %s".formatted(GPGNetServer.isConnected() ? "connected" : "-")); gameStateChanged(); }); } diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/TextAreaLogAppender.java b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/TextAreaLogAppender.java index 9f63bc1..7cfdb28 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/TextAreaLogAppender.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/TextAreaLogAppender.java @@ -64,9 +64,8 @@ private void appendText(String text) { public void setTextArea(Object textArea) { if (!textArea.getClass().getCanonicalName().equals("javafx.scene.control.TextArea")) { - throw new RuntimeException(String.format( - "Object is of class %s, expected javafx.scene.control.TextArea", - textArea.getClass().getCanonicalName())); + throw new RuntimeException("Object is of class %s, expected javafx.scene.control.TextArea" + .formatted(textArea.getClass().getCanonicalName())); } this.textArea = textArea; try { diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/Peer.java b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/Peer.java index e09c222..8aa11c7 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/Peer.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/Peer.java @@ -131,6 +131,6 @@ public void close() { * @return %username%(%id%) */ public String getPeerIdentifier() { - return String.format("%s(%d)", this.remoteLogin, this.remoteId); + return "%s(%d)".formatted(this.remoteLogin, this.remoteId); } } diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java index 058ab08..6488809 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java @@ -15,6 +15,7 @@ import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; +import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import lombok.Getter; @@ -121,7 +122,10 @@ a, new LongTermCredential(iceServer.getTurnUsername(), iceServer.getTurnCredenti CompletableFuture gatheringFuture = CompletableFuture.runAsync(() -> { try { component = agent.createComponent( - mediaStream, MINIMUM_PORT + (int) (Math.random() * 999.0), MINIMUM_PORT, MINIMUM_PORT + 1000); + mediaStream, + MINIMUM_PORT + (int) (ThreadLocalRandom.current().nextDouble() * 999.0), + MINIMUM_PORT, + MINIMUM_PORT + 1000); } catch (IOException e) { throw new RuntimeException(e); } @@ -513,6 +517,6 @@ public int getConnectivityAttempsInThePast(final long millis) { } public String getLogPrefix() { - return String.format("ICE %s: ", peer.getPeerIdentifier()); + return "ICE %s: ".formatted(peer.getPeerIdentifier()); } } diff --git a/ice-adapter/src/test/java/IceTest.java b/ice-adapter/src/test/java/IceTest.java index 1fe726a..5db856d 100644 --- a/ice-adapter/src/test/java/IceTest.java +++ b/ice-adapter/src/test/java/IceTest.java @@ -43,7 +43,7 @@ public static void main(String args[]) throws IOException { System.out.printf("Username: %s\n", username); int timestamp = (int) (System.currentTimeMillis() / 1000) + 3600 * 24; - String tokenName = String.format("%s:%s", timestamp, username); + String tokenName = "%s:%s".formatted(timestamp, username); byte[] secret = null; try { Mac mac = Mac.getInstance("HmacSHA1");