diff --git a/src/main/java/de/joshicodes/rja/RJABuilder.java b/src/main/java/de/joshicodes/rja/RJABuilder.java index ca37bf6..9767d53 100644 --- a/src/main/java/de/joshicodes/rja/RJABuilder.java +++ b/src/main/java/de/joshicodes/rja/RJABuilder.java @@ -17,7 +17,7 @@ import de.joshicodes.rja.requests.rest.RestRequest; import de.joshicodes.rja.util.HttpUtil; import de.joshicodes.rja.util.JsonUtil; -import de.joshicodes.rja.util.MultiObject; +import de.joshicodes.rja.util.Pair; import javax.annotation.Nullable; import java.io.IOException; @@ -304,7 +304,7 @@ public void run() { } - public MultiObject makeRequest(RestRequest request) { + public Pair makeRequest(RestRequest request) { try { return HttpUtil.sendRequest( apiUrl + request.getEndpoint(), diff --git a/src/main/java/de/joshicodes/rja/cache/CacheMap.java b/src/main/java/de/joshicodes/rja/cache/CacheMap.java index 7dbfe5a..307a708 100644 --- a/src/main/java/de/joshicodes/rja/cache/CacheMap.java +++ b/src/main/java/de/joshicodes/rja/cache/CacheMap.java @@ -1,6 +1,6 @@ package de.joshicodes.rja.cache; -import de.joshicodes.rja.util.MultiObject; +import de.joshicodes.rja.util.Pair; import de.joshicodes.rja.util.TrippleMap; import java.util.HashMap; @@ -23,13 +23,13 @@ public void put(K key, T t, long lifespan) { } public T get(K key) { - MultiObject multiObject = map.get(key); - if(multiObject == null) return null; - if(multiObject.getSecond() < System.currentTimeMillis()) { + Pair pair = map.get(key); + if(pair == null) return null; + if(pair.getSecond() < System.currentTimeMillis()) { map.remove(key); return null; } - return multiObject.getFirst(); + return pair.getFirst(); } public void remove(K key) { diff --git a/src/main/java/de/joshicodes/rja/requests/RequestHandler.java b/src/main/java/de/joshicodes/rja/requests/RequestHandler.java index cd386d6..b5d1a69 100644 --- a/src/main/java/de/joshicodes/rja/requests/RequestHandler.java +++ b/src/main/java/de/joshicodes/rja/requests/RequestHandler.java @@ -12,7 +12,7 @@ import de.joshicodes.rja.requests.packet.PingRequest; import de.joshicodes.rja.requests.rest.RestRequest; import de.joshicodes.rja.rest.RestAction; -import de.joshicodes.rja.util.MultiObject; +import de.joshicodes.rja.util.Pair; import org.java_websocket.exceptions.WebsocketNotConnectedException; import org.java_websocket.framing.CloseFrame; @@ -68,7 +68,7 @@ public void run() { */ public T sendRequest(final RJA rja, RestRequest request) { final RJABuilder builder = this.rja; - MultiObject multi = builder.makeRequest(request); + Pair multi = builder.makeRequest(request); JsonElement e = multi.getSecond(); int code = multi.getFirst(); if(e == null && (code < 200 || code >= 300)) { diff --git a/src/main/java/de/joshicodes/rja/util/HttpUtil.java b/src/main/java/de/joshicodes/rja/util/HttpUtil.java index c2afbf3..c629331 100644 --- a/src/main/java/de/joshicodes/rja/util/HttpUtil.java +++ b/src/main/java/de/joshicodes/rja/util/HttpUtil.java @@ -20,11 +20,11 @@ public class HttpUtil { public static final String AUTH_HEADER_BOT = "X-Bot-Token"; public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 OPR/77.0.4054.203"; - public static MultiObject sendRequest(String url, String method, @Nullable String authHeader, @Nullable String auth, JsonElement body) throws IOException, InterruptedException { + public static Pair sendRequest(String url, String method, @Nullable String authHeader, @Nullable String auth, JsonElement body) throws IOException, InterruptedException { return sendRequest(url, method, authHeader, auth, body, null); } - public static MultiObject sendRequest(String url, String method, @Nullable String authHeader, @Nullable String auth, JsonElement body, @Nullable HashMap headers) throws IOException, InterruptedException { + public static Pair sendRequest(String url, String method, @Nullable String authHeader, @Nullable String auth, JsonElement body, @Nullable HashMap headers) throws IOException, InterruptedException { HttpClient client = HttpClient.newHttpClient(); HttpRequest.Builder request = HttpRequest.newBuilder(); @@ -53,10 +53,10 @@ public static MultiObject sendRequest(String url, String m String res = response.body(); if(res == null || res.isEmpty() && (code < 200 || code >= 300)) { - return new MultiObject<>(code, null); + return new Pair<>(code, null); } if(!res.startsWith("{") && !res.startsWith("[")) { - return new MultiObject<>(code, null); + return new Pair<>(code, null); } JsonElement e = JsonParser.parseString(res); @@ -64,7 +64,7 @@ public static MultiObject sendRequest(String url, String m e = new JsonObject(); } - return new MultiObject<>(code, e); + return new Pair<>(code, e); } diff --git a/src/main/java/de/joshicodes/rja/util/MultiObject.java b/src/main/java/de/joshicodes/rja/util/Pair.java similarity index 82% rename from src/main/java/de/joshicodes/rja/util/MultiObject.java rename to src/main/java/de/joshicodes/rja/util/Pair.java index 921f9e2..055534d 100644 --- a/src/main/java/de/joshicodes/rja/util/MultiObject.java +++ b/src/main/java/de/joshicodes/rja/util/Pair.java @@ -5,7 +5,7 @@ * @param The first value * @param The second value */ -public record MultiObject(B first, C second) { +public record Pair(B first, C second) { public B getFirst() { return first; diff --git a/src/main/java/de/joshicodes/rja/util/TrippleMap.java b/src/main/java/de/joshicodes/rja/util/TrippleMap.java index 51d639b..0b34133 100644 --- a/src/main/java/de/joshicodes/rja/util/TrippleMap.java +++ b/src/main/java/de/joshicodes/rja/util/TrippleMap.java @@ -10,18 +10,18 @@ */ public class TrippleMap { - private final HashMap> map; + private final HashMap> map; public TrippleMap() { map = new HashMap<>(); } public void put(K key, B b, C c) { - map.put(key, new MultiObject<>(b, c)); + map.put(key, new Pair<>(b, c)); } - public void put(K key, MultiObject multiObject) { - map.put(key, multiObject); + public void put(K key, Pair pair) { + map.put(key, pair); } public void remove(K key) { @@ -33,38 +33,38 @@ public boolean containsKey(K key) { } public boolean containsFirst(K key, B b) { - MultiObject multiObject = map.get(key); - if(multiObject == null) return false; - return multiObject.getFirst().equals(b); + Pair pair = map.get(key); + if(pair == null) return false; + return pair.getFirst().equals(b); } public boolean containsSecond(K key, C c) { - MultiObject multiObject = map.get(key); - if(multiObject == null) return false; - return multiObject.getSecond().equals(c); + Pair pair = map.get(key); + if(pair == null) return false; + return pair.getSecond().equals(c); } public B getFirst(K key) { - MultiObject multiObject = map.get(key); - if(multiObject == null) return null; - return multiObject.getFirst(); + Pair pair = map.get(key); + if(pair == null) return null; + return pair.getFirst(); } public C getSecond(K key) { - MultiObject multiObject = map.get(key); - if(multiObject == null) return null; - return multiObject.getSecond(); + Pair pair = map.get(key); + if(pair == null) return null; + return pair.getSecond(); } public void clear() { map.clear(); } - public MultiObject get(K key) { + public Pair get(K key) { return map.get(key); } - public HashMap> getMap() { + public HashMap> getMap() { return map; }