Removed Bloat

Signed-off-by: 5gi <5gi@5servers.us>
This commit is contained in:
5gi 2023-03-24 09:15:03 -04:00
parent 07c30ccf8e
commit 15a75b88cc

View File

@ -1,5 +1,4 @@
package com.the5gi.DeepJ; package com.the5gi.DeepJ;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
@ -11,83 +10,33 @@ import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Objects; import java.util.Objects;
public class Translator { public class Translator {
//REQUEST INSIDE OF TRANSLATOR
protected Request request; protected Request request;
//GLOBAL AUTH KEY (GAK)
public static String globalAPIKey = "null"; public static String globalAPIKey = "null";
//CONSTRUCTORS
public Translator() {
//GAK
if (globalAPIKey == null) {
System.out.println("\n[DeepJ] You are currently using the Global API Key Translator Constructor." +"\n[DeepJ] If you are trying to use global API keys, Call the method \"Translator.setGlobalAuthKey(String key)\" and then re-use this contructor." + "\n[DeepJ] If you want to define an different authkey every time do: \"new Translator(String authKey)\"\n");
} else {
request = new Request(globalAPIKey);
}
}
public Translator(boolean silent) { public Translator(boolean silent) {
//GAK (SILENCABLE)
if (globalAPIKey == null && !silent) { if (globalAPIKey == null && !silent) {
System.out.println("\n[DeepJ] You are currently using the Global API Key Translator Constructor." +"\n[DeepJ] If you are trying to use global API keys, Call the method \"Translator.setGlobalAuthKey(String key)\" and then re-use this contructor." + "\n[DeepJ] If you want to define an different authkey every time do: \"new Translator(String authKey)\"\n"); System.out.println("\n[DeepJ] You are currently using the Global API Key Translator Constructor." +"\n[DeepJ] If you are trying to use global API keys, Call the method \"Translator.setGlobalAuthKey(String key)\" and then re-use this contructor." + "\n[DeepJ] If you want to define an different authkey every time do: \"new Translator(String authKey)\"\n");
} else { } else {
request = new Request(globalAPIKey); request = new Request(globalAPIKey);
} }
} }
public Translator(String authKey) {
//NORMAL REQUEST (GAK Notice) (NO SILENCE)
if (!Objects.equals(globalAPIKey, "null")) {
System.out.println("[DeepJ] Looks like you have defined a global API key already! You can use if by just typing \"new Traslator()\"" + "\n instead of \"new Translator(String authKey)\". NOTE: This will work but just some advice :)");
}
request = new Request(authKey);
}
public Translator(String apiKey, boolean silence) { public Translator(String apiKey, boolean silence) {
//NORMAL REQUEST (GAK SILENCEABLE)
if (!Objects.equals(globalAPIKey, "null") && !silence) { if (!Objects.equals(globalAPIKey, "null") && !silence) {
System.out.println("[DeepJ] Looks like you have defined a global API key already! You can use if by just typing \"new Traslator()\"" + "\n instead of \"new Translator(String authKey)\". NOTE: This will work but this is just some advice :)"); System.out.println("[DeepJ] Looks like you have defined a global API key already! You can use if by just typing \"new Traslator()\"" + "\n instead of \"new Translator(String authKey)\". NOTE: This will work but this is just some advice :)");
} }
request = new Request(apiKey); request = new Request(apiKey);
} }
public static void setGlobalAPIKey(String key) { public static void setGlobalAPIKey(String key) {
//SET GLOBAL API KEY (STATIC)
globalAPIKey = key; globalAPIKey = key;
} }
public static Translator newTranslator(String apiKey) {
//NORMAL REQUEST (NO GAK) (STATIC)
return new Translator(apiKey);
}
public static TranslatorBuilder newBuilder() { public static TranslatorBuilder newBuilder() {
return new TranslatorBuilder(); return new TranslatorBuilder();
} }
public static Translator newTranslator() {
//GAK (STATIC)
if (globalAPIKey == null) {
System.out.println("\n[DeepJ] You are currently using the Global API Key \".of()\" Translator." +
"\n[DeepJ] If you are trying to use global API keys, Call the method \"Translator.setGlobalAPIKey(String key)\" and then re-use this method." +
"\n[DeepJ] If you want to define an different authkey every time do: \"Translator.of(String apiKey)\"\n");
return new Translator("null");
} else {
return new Translator();
}
}
//END CONSTRUCTORS
//API KEYS
public void setAPIKey(String key) { public void setAPIKey(String key) {
request.setAuthKey(key); request.setAuthKey(key);
} }
public String getAPIKey() { public String getAPIKey() {
return request.authKey; return request.authKey;
} }
public void close() {
request = new Request("null");
}
//END API KEYS
//TRANSLATE
public String translate(Language langToTranslateTo, String sourceMessage) { public String translate(Language langToTranslateTo, String sourceMessage) {
if (request.authKey == "null") { if (request.authKey == "null") {
System.out.println("[DeepJ] This translator is closed! Please re-create!"); System.out.println("[DeepJ] This translator is closed! Please re-create!");
@ -109,8 +58,6 @@ public class Translator {
} }
return message; return message;
} }
//API REQUEST CLASS
protected static class Request { protected static class Request {
public String authKey; public String authKey;
public Request(String authKey) { public Request(String authKey) {
@ -134,12 +81,10 @@ public class Translator {
return response.body(); return response.body();
} }
} }
public static class TranslatorBuilder { public static class TranslatorBuilder {
private boolean silent = false; private boolean silent = false;
private String authKey = null; private String authKey = null;
private boolean GAK = false; private boolean GAK = false;
public Translator build() { public Translator build() {
if (GAK) { if (GAK) {
return new Translator(silent); return new Translator(silent);
@ -147,24 +92,19 @@ public class Translator {
return new Translator(authKey, silent); return new Translator(authKey, silent);
} }
} }
public TranslatorBuilder useGAK(boolean bool) { public TranslatorBuilder useGAK(boolean bool) {
this.GAK = bool; this.GAK = bool;
return this; return this;
} }
public TranslatorBuilder setAuthKey(String authKey) { public TranslatorBuilder setAuthKey(String authKey) {
this.authKey = authKey; this.authKey = authKey;
return this; return this;
} }
public TranslatorBuilder setSilent(boolean silent) { public TranslatorBuilder setSilent(boolean silent) {
this.silent = silent; this.silent = silent;
return this; return this;
} }
} }
//DEEPL LANGUAGES
public enum Language { public enum Language {
Bulgarian("BG"), Bulgarian("BG"),
Czech("CS"), Czech("CS"),
@ -192,16 +132,12 @@ public class Translator {
Slovenian("SL"), Slovenian("SL"),
Swedish("SV"), Swedish("SV"),
Chinese("ZH"); Chinese("ZH");
//API STRING IDENTIFIER
private final String apiString; private final String apiString;
Language(String apiString) { Language(String apiString) {
this.apiString = apiString; this.apiString = apiString;
} }
//API STRING IDENTIFIER RETURN
public String getApiString() { public String getApiString() {
return this.apiString; return this.apiString;
} }
} }
} }