Code cleanup

This commit is contained in:
Andrea Cavalli 2020-08-30 00:46:28 +02:00
parent 4de5f47b95
commit c313cb8fa2
4 changed files with 7 additions and 153 deletions

View File

@ -33,7 +33,7 @@ public class Init {
*
* @throws CantLoadLibrary An exception that is thrown when the LoadLibrary class fails to load the library.
*/
public synchronized static void start() throws Throwable {
public synchronized static void start() throws CantLoadLibrary {
if (!started) {
Os os = LoadLibrary.getOs();

View File

@ -1,146 +0,0 @@
/*
* Copyright (c) 2018. Ernesto Castellotti <erny.castell@gmail.com>
* This file is part of JTdlib.
*
* JTdlib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* JTdlib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JTdlib. If not, see <http://www.gnu.org/licenses/>.
*/
package it.tdlight.tdlight;
import it.tdlight.tdlight.utils.CloseCallback;
import it.tdlight.tdlight.utils.ErrorCallback;
import it.tdlight.tdlight.utils.ReceiveCallback;
/**
* Interface of callback for interaction with TDLib.
*/
public class TdCallback {
private ReceiveCallback receiveCallback;
private ErrorCallback errorCallback;
private CloseCallback closeCallback;
/**
* Creates a new TdCallback.
*
* @param receiveCallback Interface of callback for receive incoming update or request response.
* @param errorCallback Interface of callback for receive incoming error response.
* @param closeCallback Interface of callback for receive notification of closing Tdlib.
*/
public TdCallback(ReceiveCallback receiveCallback, ErrorCallback errorCallback, CloseCallback closeCallback) {
this.receiveCallback = receiveCallback;
this.errorCallback = errorCallback;
this.closeCallback = closeCallback;
}
/**
* Creates a new TdCallback.
*
* @param receiveCallback Interface of callback for receive incoming update or request response.
*/
public TdCallback(ReceiveCallback receiveCallback) {
this.receiveCallback = receiveCallback;
}
/**
* Creates a new TdCallback.
*
* @param errorCallback Interface of callback for receive incoming error response.
*/
public TdCallback(ErrorCallback errorCallback) {
this.errorCallback = errorCallback;
}
/**
* Creates a new TdCallback.
*
* @param closeCallback Interface of callback for receive notification of closing Tdlib.
*/
public TdCallback(CloseCallback closeCallback) {
this.closeCallback = closeCallback;
}
/**
* Creates a new TdCallback.
*
* @param receiveCallback Interface of callback for receive incoming update or request response.
* @param errorCallback Interface of callback for receive incoming error response.
*/
public TdCallback(ReceiveCallback receiveCallback, ErrorCallback errorCallback) {
this.receiveCallback = receiveCallback;
this.errorCallback = errorCallback;
}
/**
* Creates a new TdCallback.
*
* @param errorCallback Interface of callback for receive incoming error response.
* @param closeCallback Interface of callback for receive notification of closing Tdlib.
*/
public TdCallback(ErrorCallback errorCallback, CloseCallback closeCallback) {
this.errorCallback = errorCallback;
this.closeCallback = closeCallback;
}
/**
* Creates a new TdCallback.
*
* @param receiveCallback Interface of callback for receive incoming update or request response.
* @param closeCallback Interface of callback for receive notification of closing Tdlib.
*/
public TdCallback(ReceiveCallback receiveCallback, CloseCallback closeCallback) {
this.receiveCallback = receiveCallback;
this.closeCallback = closeCallback;
}
/**
* Get ReceiveCallback.
*
* @return This method return ReceiveCallback or "null callback" (a callback that receives records from tdlib but does not perform any operation) if is null.
*/
public ReceiveCallback getReceiveCallback() {
if (this.receiveCallback == null) {
return response -> {
};
}
return this.receiveCallback;
}
/**
* Get ErrorCallback.
*
* @return This method return ErrorCallback or "null callback" (a callback that receives records from tdlib but does not perform any operation) if is null.
*/
public ErrorCallback getErrorCallback() {
if (this.errorCallback == null) {
return error -> {
};
}
return this.errorCallback;
}
/**
* Get CloseCallback.
*
* @return This method return CloseCallback or "null callback" (a callback that receives records from tdlib but does not perform any operation) if is null.
*/
public CloseCallback getCloseCallback() {
if (this.closeCallback == null) {
return () -> {
};
}
return this.closeCallback;
}
}

View File

@ -20,7 +20,7 @@ package it.tdlight.tdlight.utils;
/**
* An exception that is thrown when the LoadLibrary class fails to load the library.
*/
public class CantLoadLibrary extends RuntimeException {
public class CantLoadLibrary extends Exception {
/**
* Creates a new CantLoadLibrary exception.
*/

View File

@ -49,7 +49,7 @@ public class LoadLibrary {
* @param libname The name of the library.
* @throws CantLoadLibrary An exception that is thrown when the LoadLibrary class fails to load the library.
*/
public static void load(String libname) throws Throwable {
public static void load(String libname) throws CantLoadLibrary {
if (libname == null || libname.trim().isEmpty()) {
throw new IllegalArgumentException();
}
@ -64,16 +64,16 @@ public class LoadLibrary {
libraryLoaded.put(libname, true);
}
private static void loadLibrary(String libname) throws Throwable {
private static void loadLibrary(String libname) throws CantLoadLibrary {
Arch arch = getCpuArch();
Os os = getOs();
if (arch == Arch.unknown) {
throw new CantLoadLibrary().initCause(new IllegalStateException("Arch: \"" + System.getProperty("os.arch") + "\" is unknown"));
throw (CantLoadLibrary) new CantLoadLibrary().initCause(new IllegalStateException("Arch: \"" + System.getProperty("os.arch") + "\" is unknown"));
}
if (os == Os.unknown) {
throw new CantLoadLibrary().initCause(new IllegalStateException("Os: \"" + System.getProperty("os.name") + "\" is unknown"));
throw (CantLoadLibrary) new CantLoadLibrary().initCause(new IllegalStateException("Os: \"" + System.getProperty("os.name") + "\" is unknown"));
}
try {
@ -82,7 +82,7 @@ public class LoadLibrary {
if (loadSysLibrary(libname)) {
return;
}
throw new CantLoadLibrary().initCause(e);
throw (CantLoadLibrary) new CantLoadLibrary().initCause(e);
}
}