From f07898358fe8608ba2cba6f951d0165cbc09ecb0 Mon Sep 17 00:00:00 2001 From: vil02 Date: Sat, 14 Oct 2023 17:20:12 +0200 Subject: [PATCH] Make some Java classes proper utilities Made the design cleaner by marking Java classes as `final` and explicitly declaring their default constructors as `private`. This change makes the code coverage reports more accurate. Closes #4926. --- changelog.md | 3 +++ .../src/main/java/io/ballerina/stdlib/udp/compiler/Utils.java | 4 +++- native/src/main/java/io/ballerina/stdlib/udp/Constants.java | 4 +++- native/src/main/java/io/ballerina/stdlib/udp/Dispatcher.java | 4 +++- native/src/main/java/io/ballerina/stdlib/udp/Utils.java | 4 +++- .../java/io/ballerina/stdlib/udp/nativeclient/Client.java | 4 +++- .../io/ballerina/stdlib/udp/nativeclient/ConnectClient.java | 4 +++- .../java/io/ballerina/stdlib/udp/nativelistener/Caller.java | 4 +++- .../java/io/ballerina/stdlib/udp/nativelistener/Listener.java | 4 +++- .../io/ballerina/stdlib/udp/testutils/MockServerUtils.java | 4 +++- 10 files changed, 30 insertions(+), 9 deletions(-) diff --git a/changelog.md b/changelog.md index 3769df80..9f8aeaaa 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Changed +- [Make some of the Java classes proper utility classes](https://github.com/ballerina-platform/ballerina-standard-library/issues/4926) + ## [1.9.1] - 2023-10-12 ### Fixed diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/udp/compiler/Utils.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/udp/compiler/Utils.java index daff0a88..67f42fad 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/udp/compiler/Utils.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/udp/compiler/Utils.java @@ -39,7 +39,9 @@ /** * Compiler-plugin utility class. */ -public class Utils { +public final class Utils { + + private Utils() {} public static final String NODE_LOCATION = "node.location"; public static final String LS = System.lineSeparator(); diff --git a/native/src/main/java/io/ballerina/stdlib/udp/Constants.java b/native/src/main/java/io/ballerina/stdlib/udp/Constants.java index 343b423a..1ecc20f8 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/Constants.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/Constants.java @@ -21,7 +21,9 @@ /** * Constant variable for udp related operations. */ -public class Constants { +public final class Constants { + + private Constants() {} // Constant related to ballerina Datagram record public static final String DATAGRAM_RECORD = "Datagram"; diff --git a/native/src/main/java/io/ballerina/stdlib/udp/Dispatcher.java b/native/src/main/java/io/ballerina/stdlib/udp/Dispatcher.java index 41182301..d1efe5ae 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/Dispatcher.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/Dispatcher.java @@ -39,7 +39,9 @@ /** * Dispatch async methods. */ -public class Dispatcher { +public final class Dispatcher { + + private Dispatcher() {} private static final Logger log = LoggerFactory.getLogger(Dispatcher.class); diff --git a/native/src/main/java/io/ballerina/stdlib/udp/Utils.java b/native/src/main/java/io/ballerina/stdlib/udp/Utils.java index 41422627..f82d04ec 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/Utils.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/Utils.java @@ -39,7 +39,9 @@ * * @since 0.985.0 */ -public class Utils { +public final class Utils { + + private Utils() {} /** * udp standard library package ID. diff --git a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java index bd1e1167..495ad41a 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java @@ -39,7 +39,9 @@ * * @since 1.1.0 */ -public class Client { +public final class Client { + + private Client() {} public static Object init(Environment env, BObject client, BMap config) { final Future balFuture = env.markAsync(); diff --git a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java index 06440711..db69d392 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java @@ -39,7 +39,9 @@ * * @since 1.1.0 */ -public class ConnectClient { +public final class ConnectClient { + + private ConnectClient() {} public static Object init(Environment env, BObject client, BString remoteHost, int remotePort, BMap config) { diff --git a/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Caller.java b/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Caller.java index 89deb8f7..83f475de 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Caller.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Caller.java @@ -36,7 +36,9 @@ /** * Native function implementations of the UDP Caller. */ -public class Caller { +public final class Caller { + + private Caller() {} public static Object sendBytes(Environment env, BObject caller, BArray data) { final Future callback = env.markAsync(); diff --git a/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Listener.java b/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Listener.java index 844ee3ab..4cc6d88e 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Listener.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Listener.java @@ -38,7 +38,9 @@ /** * Native function implementations of the UDP Listener. */ -public class Listener { +public final class Listener { + private Listener() {} + private static final Logger log = LoggerFactory.getLogger(Client.class); public static Object init(BObject listener, int localPort, BMap config) { diff --git a/test-utils/src/main/java/io/ballerina/stdlib/udp/testutils/MockServerUtils.java b/test-utils/src/main/java/io/ballerina/stdlib/udp/testutils/MockServerUtils.java index 54245bd3..f1877649 100644 --- a/test-utils/src/main/java/io/ballerina/stdlib/udp/testutils/MockServerUtils.java +++ b/test-utils/src/main/java/io/ballerina/stdlib/udp/testutils/MockServerUtils.java @@ -32,7 +32,9 @@ /** * This UDP server udp will use to mock the backend server. */ -public class MockServerUtils { +public final class MockServerUtils { + + private MockServerUtils() {} private static MockUdpServer mockUdpServer;