diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 47f921b..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "common-utils"] - path = common-utils - url = https://git.ignuranza.net/tdlight-team/common-utils.git diff --git a/common-utils b/common-utils deleted file mode 160000 index 8da6756..0000000 --- a/common-utils +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8da67564c5a006dd31c2d0528768af8f790c1a67 diff --git a/pom.xml b/pom.xml index 8cc29db..07f4680 100644 --- a/pom.xml +++ b/pom.xml @@ -7,9 +7,6 @@ jar UTF-8 - - 10 - 10 @@ -34,29 +31,6 @@ - - junit - junit - 4.12 - test - - - org.jetbrains - annotations - 17.0.0 - compile - - - org.jetbrains - annotations - 17.0.0 - compile - - - org.warp - common-utils - 1.0.3 - it.tdlight tdlight-natives-linux-amd64 @@ -74,36 +48,36 @@ - - - - maven-clean-plugin - 3.0.0 - - - - maven-resources-plugin - 3.0.2 - - - maven-compiler-plugin - 3.7.0 - - - maven-jar-plugin - 3.0.2 - - - maven-install-plugin - 2.5.2 - - - maven-deploy-plugin - 2.8.2 - - - + + maven-clean-plugin + 3.1.0 + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.1 + + UTF-8 + 8 + 8 + + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 3.0.0-M1 + + + maven-deploy-plugin + 2.8.2 + org.codehaus.mojo templating-maven-plugin diff --git a/src/main/java/it/tdlight/tdlight/Client.java b/src/main/java/it/tdlight/tdlight/Client.java index 6b35598..0a18185 100644 --- a/src/main/java/it/tdlight/tdlight/Client.java +++ b/src/main/java/it/tdlight/tdlight/Client.java @@ -59,7 +59,7 @@ public class Client extends NativeClient implements TelegramClient { throw new IllegalStateException("ClientActor is destroyed"); } - var responseList = new ArrayList(); + ArrayList responseList = new ArrayList<>(); if (eventIds == null) { eventIds = new long[eventSize]; events = new Object[eventSize]; @@ -100,7 +100,7 @@ public class Client extends NativeClient implements TelegramClient { throw new IllegalStateException("ClientActor is destroyed"); } - var responseList = receive(timeout, 1); + List responseList = receive(timeout, 1); if (responseList.size() < 1) { return null; diff --git a/src/main/java/it/tdlight/tdlight/Init.java b/src/main/java/it/tdlight/tdlight/Init.java index b882619..6be5ca0 100644 --- a/src/main/java/it/tdlight/tdlight/Init.java +++ b/src/main/java/it/tdlight/tdlight/Init.java @@ -35,7 +35,7 @@ public class Init { */ public synchronized static void start() throws Throwable { if (!started) { - var os = LoadLibrary.getOs(); + Os os = LoadLibrary.getOs(); if (os == Os.win) { LoadLibrary.load("libeay32"); diff --git a/src/main/java/it/tdlight/tdlight/Log.java b/src/main/java/it/tdlight/tdlight/Log.java index d50a903..ce70437 100644 --- a/src/main/java/it/tdlight/tdlight/Log.java +++ b/src/main/java/it/tdlight/tdlight/Log.java @@ -1,7 +1,7 @@ package it.tdlight.tdlight; import it.tdlight.tdlib.NativeLog; -import java.util.Objects; +import it.tdlight.tdlight.utils.ObjectsUtils; public class Log extends NativeLog { @@ -22,7 +22,7 @@ public class Log extends NativeLog { * @param fatalErrorCallback Callback that will be called when a fatal error happens. Pass null to restore default callback. */ public static void setFatalErrorCallback(FatalErrorCallbackPtr fatalErrorCallback) { - Log.fatalErrorCallback = Objects.requireNonNullElse(fatalErrorCallback, defaultFatalErrorCallbackPtr); + Log.fatalErrorCallback = ObjectsUtils.requireNonNullElse(fatalErrorCallback, defaultFatalErrorCallbackPtr); } private static void onFatalError(String errorMessage) { diff --git a/src/main/java/it/tdlight/tdlight/utils/LoadLibrary.java b/src/main/java/it/tdlight/tdlight/utils/LoadLibrary.java index a17cff6..89373f6 100644 --- a/src/main/java/it/tdlight/tdlight/utils/LoadLibrary.java +++ b/src/main/java/it/tdlight/tdlight/utils/LoadLibrary.java @@ -18,6 +18,7 @@ package it.tdlight.tdlight.utils; import java.io.IOException; +import java.io.InputStream; import java.nio.ByteOrder; import java.nio.file.Files; import java.nio.file.Path; @@ -68,8 +69,8 @@ public class LoadLibrary { return; } - var arch = getCpuArch(); - var os = getOs(); + Arch arch = getCpuArch(); + Os os = getOs(); if (arch == Arch.unknown) { throw new CantLoadLibrary().initCause(new IllegalStateException("Arch: \"" + System.getProperty("os.arch") + "\" is unknown")); @@ -99,7 +100,7 @@ public class LoadLibrary { private static void loadJarLibrary(String libname, Arch arch, Os os) throws IOException, CantLoadLibrary { Path tempPath = Files.createDirectories(librariesPath.resolve("version-" + libsVersion).resolve(libname)); Path tempFile = Paths.get(tempPath.toString(), libname + getExt(os)); - var libInputStream = LoadLibrary.class.getResourceAsStream(createPath("libs", os.name(), arch.name(), libname) + getExt(os)); + InputStream libInputStream = LoadLibrary.class.getResourceAsStream(createPath("libs", os.name(), arch.name(), libname) + getExt(os)); if (Files.notExists(tempFile)) { Files.copy(libInputStream, tempFile); } @@ -109,7 +110,7 @@ public class LoadLibrary { private static Arch getCpuArch() { - var architecture = System.getProperty("os.arch").trim(); + String architecture = System.getProperty("os.arch").trim(); switch (architecture) { case "amd64": case "x86_64": @@ -133,7 +134,7 @@ public class LoadLibrary { } public static Os getOs() { - var os = System.getProperty("os.name").toLowerCase().trim(); + String os = System.getProperty("os.name").toLowerCase().trim(); if (os.contains("linux")) return Os.linux; if (os.contains("windows")) @@ -150,7 +151,7 @@ public class LoadLibrary { } private static String createPath(String... path) { - var stringBuilder = new StringBuilder(); + StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("/"); for (int i = 0; i < path.length; i++) { diff --git a/src/main/java/it/tdlight/tdlight/utils/ObjectsUtils.java b/src/main/java/it/tdlight/tdlight/utils/ObjectsUtils.java new file mode 100644 index 0000000..8696a76 --- /dev/null +++ b/src/main/java/it/tdlight/tdlight/utils/ObjectsUtils.java @@ -0,0 +1,67 @@ +package it.tdlight.tdlight.utils; + +public class ObjectsUtils { + /** + * Returns the first argument if it is non-{@code null} and + * otherwise returns the non-{@code null} second argument. + * + * @param obj an object + * @param defaultObj a non-{@code null} object to return if the first argument + * is {@code null} + * @param the type of the reference + * @return the first argument if it is non-{@code null} and + * otherwise the second argument if it is non-{@code null} + * @throws NullPointerException if both {@code obj} is null and + * {@code defaultObj} is {@code null} + * @since 9 + */ + public static T requireNonNullElse(T obj, T defaultObj) { + return (obj != null) ? obj : requireNonNull(defaultObj, "defaultObj"); + } + + /** + * Checks that the specified object reference is not {@code null}. This + * method is designed primarily for doing parameter validation in methods + * and constructors, as demonstrated below: + *
+	 * public Foo(Bar bar) {
+	 *     this.bar = Objects.requireNonNull(bar);
+	 * }
+	 * 
+ * + * @param obj the object reference to check for nullity + * @param the type of the reference + * @return {@code obj} if not {@code null} + * @throws NullPointerException if {@code obj} is {@code null} + */ + public static T requireNonNull(T obj) { + if (obj == null) + throw new NullPointerException(); + return obj; + } + + /** + * Checks that the specified object reference is not {@code null} and + * throws a customized {@link NullPointerException} if it is. This method + * is designed primarily for doing parameter validation in methods and + * constructors with multiple parameters, as demonstrated below: + *
+	 * public Foo(Bar bar, Baz baz) {
+	 *     this.bar = Objects.requireNonNull(bar, "bar must not be null");
+	 *     this.baz = Objects.requireNonNull(baz, "baz must not be null");
+	 * }
+	 * 
+ * + * @param obj the object reference to check for nullity + * @param message detail message to be used in the event that a {@code + * NullPointerException} is thrown + * @param the type of the reference + * @return {@code obj} if not {@code null} + * @throws NullPointerException if {@code obj} is {@code null} + */ + public static T requireNonNull(T obj, String message) { + if (obj == null) + throw new NullPointerException(message); + return obj; + } +} diff --git a/src/main/java/it/tdlight/tdlight/utils/ScannerUtils.java b/src/main/java/it/tdlight/tdlight/utils/ScannerUtils.java index b690fe1..31609be 100644 --- a/src/main/java/it/tdlight/tdlight/utils/ScannerUtils.java +++ b/src/main/java/it/tdlight/tdlight/utils/ScannerUtils.java @@ -148,12 +148,12 @@ public class ScannerUtils { try { lock.lock(); StringBuilder toPrint = new StringBuilder(); - var oldOut = System.out; - var oldErr = System.err; + PrintStream oldOut = System.out; + PrintStream oldErr = System.err; System.setOut(emptyOut); System.setErr(emptyOut); oldOut.print("[" + displayName + "] " + question + ": "); - var result = scanner.nextLine(); + String result = scanner.nextLine(); System.setOut(oldOut); System.setErr(oldErr); return result;