diff --git a/build.gradle b/build.gradle index ff97915c..0e1bde89 100644 --- a/build.gradle +++ b/build.gradle @@ -155,6 +155,9 @@ subprojects { } compileJava { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + source = sourcesForRelease.destinationDir classpath = sourceSets.main.compileClasspath diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java b/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java index e5943713..a206355b 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java @@ -19,8 +19,9 @@ import net.dv8tion.jda.api.Permission; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; +import java.util.List; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -50,8 +51,8 @@ public class CommandBuilder private int cooldown = 0; private Permission[] userPermissions = new Permission[0]; private Permission[] botPermissions = new Permission[0]; - private final LinkedList aliases = new LinkedList<>(); - private final LinkedList children = new LinkedList<>(); + private final List aliases = new ArrayList<>(); + private final List children = new ArrayList<>(); private BiConsumer helpBiConsumer = null; private boolean usesTopicTags = true; private CooldownScope cooldownScope = CooldownScope.USER; @@ -215,7 +216,7 @@ public CommandBuilder setUserPermissions(Collection userPermissions) if(userPermissions == null) this.userPermissions = new Permission[0]; else - this.userPermissions = (Permission[]) userPermissions.toArray(); + this.userPermissions = userPermissions.toArray(new Permission[0]); return this; } @@ -251,7 +252,7 @@ public CommandBuilder setBotPermissions(Collection botPermissions) if(botPermissions == null) this.botPermissions = new Permission[0]; else - this.botPermissions = (Permission[]) botPermissions.toArray(); + this.botPermissions = botPermissions.toArray(new Permission[0]); return this; } @@ -490,8 +491,8 @@ public Command build(BiConsumer execution) { return new BlankCommand(name, help, category, arguments, guildOnly, requiredRole, ownerCommand, cooldown, - userPermissions, botPermissions, aliases.toArray(new String[aliases.size()]), - children.toArray(new Command[children.size()]), helpBiConsumer, usesTopicTags, + userPermissions, botPermissions, aliases.toArray(new String[0]), + children.toArray(new Command[0]), helpBiConsumer, usesTopicTags, cooldownScope, hidden) { @Override @@ -502,7 +503,7 @@ protected void execute(CommandEvent event) }; } - private abstract class BlankCommand extends Command + private abstract static class BlankCommand extends Command { BlankCommand(String name, String help, Category category, String arguments, boolean guildOnly, String requiredRole, diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/CommandClient.java b/command/src/main/java/com/jagrosh/jdautilities/command/CommandClient.java index 02b3f895..476b2e8f 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/CommandClient.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/CommandClient.java @@ -593,7 +593,7 @@ public interface CommandClient * * @return The GuildSettingsManager, or {@code null} if one was not provided when building this CommandClient. */ - M getSettingsManager(); + > M getSettingsManager(); /** * Shuts down internals of the Command Client, such as the threadpool and guild settings manager diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/CommandClientBuilder.java b/command/src/main/java/com/jagrosh/jdautilities/command/CommandClientBuilder.java index 27824a2f..3d7ea1ff 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/CommandClientBuilder.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/CommandClientBuilder.java @@ -17,7 +17,7 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedList; +import java.util.List; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -58,9 +58,9 @@ public class CommandClientBuilder private String error; private String carbonKey; private String botsKey; - private final LinkedList commands = new LinkedList<>(); - private final LinkedList slashCommands = new LinkedList<>(); - private final LinkedList contextMenus = new LinkedList<>(); + private final List commands = new ArrayList<>(); + private final List slashCommands = new ArrayList<>(); + private final List contextMenus = new ArrayList<>(); private String forcedGuildId = null; private boolean manualUpsert = false; private CommandListener listener; @@ -71,7 +71,7 @@ public class CommandClientBuilder private ScheduledExecutorService executor; private int linkedCacheSize = 0; private AnnotatedModuleCompiler compiler = new AnnotatedModuleCompilerImpl(); - private GuildSettingsManager manager = null; + private GuildSettingsManager manager = null; /** * Builds a {@link com.jagrosh.jdautilities.command.impl.CommandClientImpl CommandClientImpl} @@ -707,7 +707,7 @@ public CommandClientBuilder setLinkedCacheSize(int linkedCacheSize) * * @return This builder */ - public CommandClientBuilder setGuildSettingsManager(GuildSettingsManager manager) + public CommandClientBuilder setGuildSettingsManager(GuildSettingsManager manager) { this.manager = manager; return this; diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java index 87c83523..7a1852e4 100644 --- a/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java +++ b/command/src/main/java/com/jagrosh/jdautilities/command/impl/CommandClientImpl.java @@ -142,7 +142,7 @@ public class CommandClientImpl implements CommandClient, EventListener private final String helpWord; private final ScheduledExecutorService executor; private final AnnotatedModuleCompiler compiler; - private final GuildSettingsManager manager; + private final GuildSettingsManager manager; private String textPrefix; private CommandListener listener = null; @@ -151,7 +151,7 @@ public class CommandClientImpl implements CommandClient, EventListener public CommandClientImpl(String ownerId, String[] coOwnerIds, String prefix, String altprefix, String[] prefixes, Function prefixFunction, Function commandPreProcessFunction, BiFunction commandPreProcessBiFunction, Activity activity, OnlineStatus status, String serverInvite, String success, String warning, String error, String carbonKey, String botsKey, ArrayList commands, ArrayList slashCommands, ArrayList contextMenus, String forcedGuildId, boolean manualUpsert, boolean useHelp, boolean shutdownAutomatically, Consumer helpConsumer, String helpWord, ScheduledExecutorService executor, - int linkedCacheSize, AnnotatedModuleCompiler compiler, GuildSettingsManager manager) + int linkedCacheSize, AnnotatedModuleCompiler compiler, GuildSettingsManager manager) { Checks.check(ownerId != null, "Owner ID was set null or not set! Please provide an User ID to register as the owner!"); @@ -602,7 +602,7 @@ public S getSettingsFor(Guild guild) @SuppressWarnings("unchecked") @Override - public M getSettingsManager() + public > M getSettingsManager() { return (M) manager; } diff --git a/commons/src/main/java/com/jagrosh/jdautilities/commons/waiter/EventWaiter.java b/commons/src/main/java/com/jagrosh/jdautilities/commons/waiter/EventWaiter.java index e6ab44b3..b570056e 100644 --- a/commons/src/main/java/com/jagrosh/jdautilities/commons/waiter/EventWaiter.java +++ b/commons/src/main/java/com/jagrosh/jdautilities/commons/waiter/EventWaiter.java @@ -234,7 +234,7 @@ public void waitForEvent(Class classType, Predicate cond @SuppressWarnings("unchecked") public final void onEvent(GenericEvent event) { - Class c = event.getClass(); + Class c = event.getClass(); // Runs at least once for the fired Event, at most // once for each superclass (excluding Object) because @@ -275,7 +275,7 @@ public void shutdown() threadpool.shutdown(); } - private class WaitingEvent + private static class WaitingEvent { final Predicate condition; final Consumer action; diff --git a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java index 68e28eef..378dc11f 100644 --- a/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java +++ b/examples/src/main/java/com/jagrosh/jdautilities/examples/command/RoleinfoCommand.java @@ -108,11 +108,11 @@ else if(found.size()>1) private static String listOfRoles(List list, String query) { - String out = String.format("**Multiple roles found matching \"%s\":**", query); + StringBuilder out = new StringBuilder(String.format("**Multiple roles found matching \"%s\":**", query)); for(int i = 0; i < 6 && i < list.size(); i++) - out += "\n - " + list.get(i).getName() + " (ID:" + list.get(i).getId() + ")"; + out.append("\n - ").append(list.get(i).getName()).append(" (ID:").append(list.get(i).getId()).append(")"); if(list.size() > 6) - out += "\n**And " + (list.size() - 6) + " more...**"; - return out; + out.append("\n**And ").append(list.size() - 6).append(" more...**"); + return out.toString(); } } diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonEmbedPaginator.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonEmbedPaginator.java index e70e5d5d..95c8688e 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonEmbedPaginator.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonEmbedPaginator.java @@ -37,7 +37,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -295,7 +294,7 @@ public static class Builder extends Menu.Builder private boolean wrapPageEnds = false; private ButtonStyle style = ButtonStyle.SECONDARY; - private final List embeds = new LinkedList<>(); + private final List embeds = new ArrayList<>(); /** * Builds the {@link ButtonEmbedPaginator} with this Builder. diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java index 1053453f..e4ef1ca5 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/ButtonMenu.java @@ -30,7 +30,7 @@ import net.dv8tion.jda.internal.utils.Checks; import java.awt.Color; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -115,34 +115,32 @@ private void initialize(RestAction ra) else { // This is the last reaction added. - r.queue(v -> { - waiter.waitForEvent(MessageReactionAddEvent.class, event -> { - // If the message is not the same as the ButtonMenu - // currently being displayed. - if(!event.getMessageId().equals(m.getId())) - return false; + r.queue(v -> waiter.waitForEvent(MessageReactionAddEvent.class, event -> { + // If the message is not the same as the ButtonMenu + // currently being displayed. + if(!event.getMessageId().equals(m.getId())) + return false; - // If the reaction is an Emote we get the Snowflake, - // otherwise we get the unicode value. - String re = event.getReaction().getEmoji().getName(); + // If the reaction is an Emote we get the Snowflake, + // otherwise we get the unicode value. + String re = event.getReaction().getEmoji().getName(); - // If the value we got is not registered as a button to - // the ButtonMenu being displayed we return false. - if(!choices.contains(re)) - return false; + // If the value we got is not registered as a button to + // the ButtonMenu being displayed we return false. + if(!choices.contains(re)) + return false; - // Last check is that the person who added the reaction - // is a valid user. - return isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); - }, (MessageReactionAddEvent event) -> { - // What happens next is after a valid event - // is fired and processed above. + // Last check is that the person who added the reaction + // is a valid user. + return isValidUser(event.getUser(), event.isFromGuild() ? event.getGuild() : null); + }, (MessageReactionAddEvent event) -> { + // What happens next is after a valid event + // is fired and processed above. - // Preform the specified action with the ReactionEmote - action.accept(event.getReaction().getEmoji()); - finalAction.accept(m); - }, timeout, unit, () -> finalAction.accept(m)); - }); + // Preform the specified action with the ReactionEmote + action.accept(event.getReaction().getEmoji()); + finalAction.accept(m); + }, timeout, unit, () -> finalAction.accept(m))); } } }); @@ -170,7 +168,7 @@ public static class Builder extends Menu.Builder private Color color; private String text; private String description; - private final List choices = new LinkedList<>(); + private final List choices = new ArrayList<>(); private Consumer action; private Consumer finalAction = (m) -> {}; diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/EmbedPaginator.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/EmbedPaginator.java index 7f66e344..811985ff 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/EmbedPaginator.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/EmbedPaginator.java @@ -252,9 +252,9 @@ else if(event instanceof MessageReceivedEvent) int pages = embeds.size(); final int targetPage; - if(leftText != null && rawContent.equalsIgnoreCase(leftText) && (1 < pageNum || wrapPageEnds)) - targetPage = pageNum - 1 < 1 && wrapPageEnds ? pages : pageNum - 1; - else if(rightText != null && rawContent.equalsIgnoreCase(rightText) && (pageNum < pages || wrapPageEnds)) + if(rawContent.equalsIgnoreCase(leftText) && (1 < pageNum || wrapPageEnds)) + targetPage = pageNum - 1 < 1 ? pages : pageNum - 1; + else if(rawContent.equalsIgnoreCase(rightText) && (pageNum < pages || wrapPageEnds)) targetPage = pageNum + 1 > pages && wrapPageEnds ? 1 : pageNum + 1; else targetPage = Integer.parseInt(rawContent); diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java index e01e4fe9..b095d04d 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/OrderedMenu.java @@ -15,6 +15,15 @@ */ package com.jagrosh.jdautilities.menu; +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; +import java.util.function.Consumer; + import com.jagrosh.jdautilities.commons.waiter.EventWaiter; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; @@ -35,15 +44,6 @@ import net.dv8tion.jda.api.utils.messages.MessageEditData; import net.dv8tion.jda.internal.utils.Checks; -import java.awt.Color; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.function.BiConsumer; -import java.util.function.Consumer; - /** * A {@link com.jagrosh.jdautilities.menu.Menu Menu} of ordered buttons signified * by numbers or letters, each with a reaction linked to it for users to click. @@ -251,9 +251,7 @@ else if (e instanceof MessageReceivedEvent) private void waitReactionOnly(Message m) { // This one is only for reactions - waiter.waitForEvent(MessageReactionAddEvent.class, e -> { - return isValidReaction(m, e); - }, e -> { + waiter.waitForEvent(MessageReactionAddEvent.class, e -> isValidReaction(m, e), e -> { m.delete().queue(); if(e.getReaction().getEmoji().getName().equals(CANCEL)) cancel.accept(m); @@ -275,7 +273,7 @@ private MessageEditData getMessage() for(int i=0; i private Color color; private String text; private String description; - private final List choices = new LinkedList<>(); + private final List choices = new ArrayList<>(); private BiConsumer selection; private Consumer cancel = (m) -> {}; private boolean useLetters = false; diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java index 0d4e4d8b..ab49e48e 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/Paginator.java @@ -15,6 +15,15 @@ */ package com.jagrosh.jdautilities.menu; +import java.awt.Color; +import java.util.Arrays; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.function.BiFunction; +import java.util.function.Consumer; + import com.jagrosh.jdautilities.commons.waiter.EventWaiter; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Message; @@ -33,15 +42,6 @@ import net.dv8tion.jda.api.utils.messages.MessageEditData; import net.dv8tion.jda.internal.utils.Checks; -import java.awt.Color; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.function.BiFunction; -import java.util.function.Consumer; - /** * A {@link com.jagrosh.jdautilities.menu.Menu Menu} implementation that paginates a * set of one or more text items across one or more pages. @@ -291,9 +291,9 @@ else if(event instanceof MessageReceivedEvent) final int targetPage; - if(leftText != null && rawContent.equalsIgnoreCase(leftText) && (1 < pageNum || wrapPageEnds)) - targetPage = pageNum - 1 < 1 && wrapPageEnds? pages : pageNum - 1; - else if(rightText != null && rawContent.equalsIgnoreCase(rightText) && (pageNum < pages || wrapPageEnds)) + if(rawContent.equalsIgnoreCase(leftText) && (1 < pageNum || wrapPageEnds)) + targetPage = pageNum - 1 < 1 ? pages : pageNum - 1; + else if(rawContent.equalsIgnoreCase(rightText) && (pageNum < pages || wrapPageEnds)) targetPage = pageNum + 1 > pages && wrapPageEnds? 1 : pageNum + 1; else { @@ -448,7 +448,7 @@ public static class Builder extends Menu.Builder private String textToRight = null; private boolean allowTextInput = false; - private final List strings = new LinkedList<>(); + private final List strings = new ArrayList<>(); /** * Builds the {@link com.jagrosh.jdautilities.menu.Paginator Paginator} diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/SelectionDialog.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/SelectionDialog.java index ad9a29bd..bbd41206 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/SelectionDialog.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/SelectionDialog.java @@ -32,7 +32,7 @@ import java.awt.Color; import java.util.Arrays; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -254,7 +254,7 @@ private MessageEditData render(int selection) */ public static class Builder extends Menu.Builder { - private final List choices = new LinkedList<>(); + private final List choices = new ArrayList<>(); private String leftEnd = ""; private String rightEnd = ""; private String defaultLeft = ""; diff --git a/menu/src/main/java/com/jagrosh/jdautilities/menu/Slideshow.java b/menu/src/main/java/com/jagrosh/jdautilities/menu/Slideshow.java index 38a5b3ca..7fa31356 100644 --- a/menu/src/main/java/com/jagrosh/jdautilities/menu/Slideshow.java +++ b/menu/src/main/java/com/jagrosh/jdautilities/menu/Slideshow.java @@ -15,6 +15,15 @@ */ package com.jagrosh.jdautilities.menu; +import java.awt.Color; +import java.util.Arrays; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.function.BiFunction; +import java.util.function.Consumer; + import com.jagrosh.jdautilities.commons.waiter.EventWaiter; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Message; @@ -32,15 +41,6 @@ import net.dv8tion.jda.api.utils.messages.MessageEditData; import net.dv8tion.jda.internal.utils.Checks; -import java.awt.Color; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.function.BiFunction; -import java.util.function.Consumer; - /** * A {@link com.jagrosh.jdautilities.menu.Menu Menu} implementation, nearly identical * to {@link com.jagrosh.jdautilities.menu.Paginator Paginator}, that displays an @@ -237,9 +237,9 @@ else if(event instanceof MessageReceivedEvent) int pages = urls.size(); final int targetPage; - if(leftText != null && rawContent.equalsIgnoreCase(leftText) && (1 < pageNum || wrapPageEnds)) + if(rawContent.equalsIgnoreCase(leftText) && (1 < pageNum || wrapPageEnds)) targetPage = pageNum - 1 < 1 && wrapPageEnds? pages : pageNum - 1; - else if(rightText != null && rawContent.equalsIgnoreCase(rightText) && (pageNum < pages || wrapPageEnds)) + else if(rawContent.equalsIgnoreCase(rightText) && (pageNum < pages || wrapPageEnds)) targetPage = pageNum + 1 > pages && wrapPageEnds? 1 : pageNum + 1; else { @@ -374,7 +374,7 @@ public static class Builder extends Menu.Builder private String textToRight = null; private boolean allowTextInput = false; - private final List strings = new LinkedList<>(); + private final List strings = new ArrayList<>(); /** * Builds the {@link com.jagrosh.jdautilities.menu.Slideshow Slideshow} diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/OAuth2Client.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/OAuth2Client.java index 81a782de..a43ae41a 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/OAuth2Client.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/OAuth2Client.java @@ -153,7 +153,7 @@ public interface OAuth2Client * * @return The client's SessionController. */ - SessionController getSessionController(); + SessionController getSessionController(); /** * Builder for creating OAuth2Client instances. @@ -165,7 +165,7 @@ class Builder { private long clientId = -1; private String clientSecret; - private SessionController sessionController; + private SessionController sessionController; private StateController stateController; private OkHttpClient client; @@ -225,7 +225,7 @@ public Builder setClientSecret(String clientSecret) * * @return This builder. */ - public Builder setSessionController(SessionController sessionController) + public Builder setSessionController(SessionController sessionController) { this.sessionController = sessionController; return this; diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2ClientImpl.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2ClientImpl.java index 158263d8..66176f26 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2ClientImpl.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/entities/impl/OAuth2ClientImpl.java @@ -45,7 +45,7 @@ import java.io.IOException; import java.io.InputStream; import java.time.OffsetDateTime; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; /** @@ -58,12 +58,12 @@ public class OAuth2ClientImpl implements OAuth2Client private final long clientId; private final String clientSecret; - private final SessionController sessionController; + private final SessionController sessionController; private final StateController stateController; private final OkHttpClient httpClient; private final OAuth2Requester requester; - public OAuth2ClientImpl(long clientId, String clientSecret, SessionController sessionController, + public OAuth2ClientImpl(long clientId, String clientSecret, SessionController sessionController, StateController stateController, OkHttpClient httpClient) { Checks.check(clientId >= 0, "Invalid Client ID"); @@ -181,7 +181,7 @@ protected List handle(Response response) throws IOException throw failure(response); JSONArray body = new JSONArray(new JSONTokener(IOUtil.getBody(response))); - List list = new LinkedList<>(); + List list = new ArrayList<>(); JSONObject obj; for(int i = 0; i < body.length(); i++) { @@ -214,7 +214,7 @@ public StateController getStateController() } @Override - public SessionController getSessionController() + public SessionController getSessionController() { return sessionController; } diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Action.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Action.java index 70873c7e..b5eb6a11 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Action.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Action.java @@ -40,9 +40,7 @@ public abstract class OAuth2Action { protected static final Consumer DEFAULT_SUCCESS = t -> {}; - protected static final Consumer DEFAULT_FAILURE = t -> { - OAuth2Requester.LOGGER.error("Requester encountered an error while processing response!", t); - }; + protected static final Consumer DEFAULT_FAILURE = t -> OAuth2Requester.LOGGER.error("Requester encountered an error while processing response!", t); protected final OAuth2ClientImpl client; protected final Method method; diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Requester.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Requester.java index 42a78cfc..640eb017 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Requester.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2Requester.java @@ -18,6 +18,7 @@ import com.jagrosh.jdautilities.commons.JDAUtilitiesInfo; import net.dv8tion.jda.internal.utils.JDALogger; import okhttp3.*; +import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import java.io.IOException; @@ -44,7 +45,7 @@ void submitAsync(OAuth2Action request, Consumer success, Consumer T submitSync(OAuth2Action request) throws IOException } } - private static void logSuccessfulRequest(OAuth2Action request) + private static void logSuccessfulRequest(OAuth2Action request) { LOGGER.debug("Got a response for {} - {}\nHeaders: {}", request.getMethod(), request.getUrl(), request.getHeaders()); diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2URL.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2URL.java index 87314239..feade3f1 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2URL.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/requests/OAuth2URL.java @@ -62,7 +62,7 @@ public enum OAuth2URL b.append(queryParams[i]); } - this.formattableRoute = route + b.toString(); + this.formattableRoute = route + b; this.queryParams = b.toString(); } else diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/DefaultSessionController.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/DefaultSessionController.java index 1ff4ea1b..ef206c60 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/DefaultSessionController.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/DefaultSessionController.java @@ -43,7 +43,7 @@ public DefaultSession createSession(SessionData data) return created; } - public class DefaultSession implements Session + public static class DefaultSession implements Session { private final String accessToken, refreshToken, tokenType; private final OffsetDateTime expiration; diff --git a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/SessionData.java b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/SessionData.java index 6a0fe93d..6a129a48 100644 --- a/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/SessionData.java +++ b/oauth2/src/main/java/com/jagrosh/jdautilities/oauth2/session/SessionData.java @@ -105,12 +105,18 @@ public Scope[] getScopes() @Override public boolean equals(Object obj) { - if(!(obj instanceof SessionData)) - return false; + if (obj instanceof SessionData) { + SessionData data = ((SessionData) obj); - SessionData data = ((SessionData) obj); + return getIdentifier().equals(data.getIdentifier()) && getTokenType().equals(data.getTokenType()); + } else { + return false; + } + } - return getIdentifier().equals(data.getIdentifier()) && getTokenType().equals(data.getTokenType()); + @Override + public int hashCode() { + return getIdentifier().hashCode() + getTokenType().hashCode(); } @Override