cleanup
This commit is contained in:
1 parent
868dbea8df
commit
a507b471b4
13 files changed
+122
-184
No files matched your search
@@ -1,4 +1,4 @@
|
||||
package me.bobert.netneutrality.command.basic;
|
||||
package me.bobert.netneutrality.command.bot;
|
||||
/*
|
||||
* Copyright (c) anthorob
|
||||
*
|
||||
|
||||
@@ -14,8 +14,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.function.Predicate.not;
|
||||
|
||||
public class UsageValidator {
|
||||
|
||||
public boolean validate(CommandContext context, CommandContainer container) {
|
||||
|
||||
@@ -100,7 +100,7 @@ public abstract class CommandContext extends AbstractContext {
|
||||
|
||||
public CommandOption getOption(String name) {
|
||||
List<CommandOption> options = getOptionsByName(name);
|
||||
return options.isEmpty() ? null : options.get(0);
|
||||
return options.isEmpty() ? null : options.getFirst();
|
||||
}
|
||||
|
||||
public List<CommandOption> getOptionsByName(String name) {
|
||||
|
||||
@@ -89,7 +89,7 @@ public class ScheduledTaskManager implements Lifecycle {
|
||||
|
||||
public void cancelAll() {
|
||||
logger.info("Cancelling all {} scheduled tasks", scheduledTasks.size());
|
||||
scheduledTasks.forEach((id, future) -> future.cancel(false));
|
||||
scheduledTasks.forEach((_, future) -> future.cancel(false));
|
||||
scheduledTasks.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ public class TaskManagerImpl implements TaskManager {
|
||||
String lockId = task.getLockId();
|
||||
ReentrantLock lock = (task instanceof PersistableTask || task instanceof BuiltInTask)
|
||||
? null
|
||||
: tasksLock.computeIfAbsent(lockId, k -> new ReentrantLock());
|
||||
: tasksLock.computeIfAbsent(lockId, _ -> new ReentrantLock());
|
||||
|
||||
try {
|
||||
if (lock != null) {
|
||||
|
||||
@@ -105,7 +105,7 @@ public class WebModule {
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
long elapsedTime = System.currentTimeMillis() - startTime;
|
||||
Sentry.addBreadcrumb(Breadcrumb.http(url, method.name(), response.code()));
|
||||
String body = response.body() != null ? response.body().string() : null;
|
||||
String body = response.body().string();
|
||||
|
||||
this.cachedResponse = new CachedResponse(
|
||||
response.code(),
|
||||
@@ -168,13 +168,13 @@ public class WebModule {
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return cachedResponse != null && cachedResponse.getStatusCode() >= 200 && cachedResponse.getStatusCode() < 400;
|
||||
return cachedResponse != null && cachedResponse.statusCode() >= 200 && cachedResponse.statusCode() < 400;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private Request request;
|
||||
private final String url;
|
||||
private String version;
|
||||
private final String version;
|
||||
private Method method = Method.GET;
|
||||
private long timeout = 5;
|
||||
private TimeUnit timeUnit = TimeUnit.MINUTES;
|
||||
@@ -328,45 +328,19 @@ public class WebModule {
|
||||
}
|
||||
}
|
||||
|
||||
private static class CachedResponse {
|
||||
private final int statusCode;
|
||||
private final Headers headers;
|
||||
private final long elapsedTime;
|
||||
private final String body;
|
||||
private final long expirationTime;
|
||||
private final String errorMessage;
|
||||
|
||||
public CachedResponse(int statusCode, Headers headers, long elapsedTime, String body, long expirationTime, String errorMessage) {
|
||||
this.statusCode = statusCode;
|
||||
this.headers = headers;
|
||||
this.elapsedTime = elapsedTime;
|
||||
this.body = body;
|
||||
this.expirationTime = expirationTime;
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
private record CachedResponse(int statusCode, Headers headers, long elapsedTime, String body, long expirationTime,
|
||||
String errorMessage) {
|
||||
|
||||
public boolean isExpired() {
|
||||
return System.currentTimeMillis() > expirationTime;
|
||||
}
|
||||
return System.currentTimeMillis() > expirationTime;
|
||||
}
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
public Optional<String> getBody() {
|
||||
return Optional.ofNullable(body);
|
||||
}
|
||||
|
||||
public Headers getHeaders() {
|
||||
return headers;
|
||||
public Optional<String> getErrorMessage() {
|
||||
return Optional.ofNullable(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public long getElapsedTime() {
|
||||
return elapsedTime;
|
||||
}
|
||||
|
||||
public Optional<String> getBody() {
|
||||
return Optional.ofNullable(body);
|
||||
}
|
||||
|
||||
public Optional<String> getErrorMessage() {
|
||||
return Optional.ofNullable(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user