Skip to content

Commit

Permalink
Drop trivial Guava usages (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd authored and aikar committed Jul 19, 2018
1 parent 786ebe8 commit 3c979a9
Show file tree
Hide file tree
Showing 26 changed files with 103 additions and 111 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,6 +11,7 @@
.idea/kotlinc.xml
.idea/modules.xml
.idea/usage.statistics.xml
.idea/checkstyle-idea.xml
**/*.iml


Expand Down
Expand Up @@ -26,7 +26,6 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.lang.reflect.Parameter;
import java.util.List;
import java.util.Map;

Expand Down
2 changes: 0 additions & 2 deletions bukkit/src/main/java/co/aikar/commands/BukkitRootCommand.java
Expand Up @@ -23,8 +23,6 @@

package co.aikar.commands;

import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Syntax;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.SetMultimap;
import org.bukkit.command.Command;
Expand Down
Expand Up @@ -26,7 +26,6 @@
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;

import java.lang.reflect.Parameter;
import java.util.List;
import java.util.Map;

Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/co/aikar/commands/ACFUtil.java
Expand Up @@ -35,6 +35,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Random;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -576,6 +577,17 @@ private static <T extends Throwable> T superSneaky(Throwable t) throws T {
throw (T) t;
}

public static <T> List<T> preformOnImmutable(List<T> list, Consumer<List<T>> action) {
try {
action.accept(list);
} catch (UnsupportedOperationException ex) {
list = new ArrayList<>(list);
action.accept(list);
}

return list;
}

private static class ApplyModifierToNumber {
private String num;
private boolean suffixes;
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/java/co/aikar/commands/Annotations.java
Expand Up @@ -33,17 +33,17 @@
@SuppressWarnings("TypeParameterExplicitlyExtendsObject")
class Annotations <M extends CommandManager> extends AnnotationLookups {

public static int NOTHING = 0;
public static int REPLACEMENTS = 1;
public static int LOWERCASE = 1 << 1;
public static int UPPERCASE = 1 << 2;
public static int NO_EMPTY = 1 << 3;
public static int DEFAULT_EMPTY = 1 << 4;
public static final int NOTHING = 0;
public static final int REPLACEMENTS = 1;
public static final int LOWERCASE = 1 << 1;
public static final int UPPERCASE = 1 << 2;
public static final int NO_EMPTY = 1 << 3;
public static final int DEFAULT_EMPTY = 1 << 4;

private final M manager;

private Map<Class<? extends Annotation>, Method> valueMethods = new IdentityHashMap<>();
private Map<Class<? extends Annotation>, Void> noValueAnnotations = new IdentityHashMap<>();
private final Map<Class<? extends Annotation>, Method> valueMethods = new IdentityHashMap<>();
private final Map<Class<? extends Annotation>, Void> noValueAnnotations = new IdentityHashMap<>();

Annotations(M manager) {
this.manager = manager;
Expand Down
15 changes: 5 additions & 10 deletions core/src/main/java/co/aikar/commands/BaseCommand.java
Expand Up @@ -35,13 +35,8 @@
import co.aikar.commands.annotation.UnknownHandler;
import co.aikar.commands.apachecommonslang.ApacheCommonsLangUtil;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.SetMultimap;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Constructor;
Expand Down Expand Up @@ -95,7 +90,7 @@ public abstract class BaseCommand {
/**
* A map of flags to pass to Context Resolution for every parameter of the type. This is like an automatic @Flags on each.
*/
final Map<Class<?>, String> contextFlags = Maps.newHashMap();
final Map<Class<?>, String> contextFlags = new HashMap<>();

/**
* What method was annoated with {@link PreCommand} to execute before commands.
Expand Down Expand Up @@ -653,7 +648,7 @@ private void executeCommand(CommandOperationContext commandOperationContext,
if (checkPrecommand(commandOperationContext, cmd, issuer, args)) {
return;
}
List<String> sargs = Lists.newArrayList(args);
List<String> sargs = Arrays.asList(args);
cmd.invoke(issuer, sargs, commandOperationContext);
} else {
issuer.sendMessage(MessageType.ERROR, MessageKeys.PERMISSION_DENIED);
Expand Down Expand Up @@ -780,7 +775,7 @@ List<String> getCommandsForCompletion(CommandIssuer issuer, String[] args) {
*/
private List<String> completeCommand(CommandIssuer issuer, RegisteredCommand cmd, String[] args, String commandLabel, boolean isAsync) {
if (!cmd.hasPermission(issuer) || args.length > cmd.consumeInputResolvers || args.length == 0 || cmd.complete == null) {
return ImmutableList.of();
return Collections.emptyList();
}

List<String> cmds = manager.getCommandCompletions().of(cmd, issuer, args, isAsync);
Expand Down Expand Up @@ -949,9 +944,9 @@ public boolean hasPermission(CommandIssuer issuer) {

public Set<String> getRequiredPermissions() {
if (this.permission == null || this.permission.isEmpty()) {
return ImmutableSet.of();
return Collections.emptySet();
}
return Sets.newHashSet(ACFPatterns.COMMA.split(this.permission));
return new HashSet<>(Arrays.asList(ACFPatterns.COMMA.split(this.permission)));
}

public boolean requiresPermission(String permission) {
Expand Down
Expand Up @@ -23,10 +23,8 @@

package co.aikar.commands;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.lang.reflect.Parameter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -35,7 +33,7 @@ public class CommandCompletionContext <I extends CommandIssuer> {
protected final I issuer;
private final String input;
private final String config;
private final Map<String, String> configs = Maps.newHashMap();
private final Map<String, String> configs = new HashMap<>();
private final List<String> args;

CommandCompletionContext(RegisteredCommand command, I issuer, String input, String config, String[] args) {
Expand All @@ -53,7 +51,7 @@ public class CommandCompletionContext <I extends CommandIssuer> {
this.config = null;
}

this.args = Lists.newArrayList(args);
this.args = Arrays.asList(args);
}

public Map<String, String> getConfigs() {
Expand Down
22 changes: 12 additions & 10 deletions core/src/main/java/co/aikar/commands/CommandCompletions.java
Expand Up @@ -23,11 +23,12 @@

package co.aikar.commands;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -44,11 +45,11 @@ public class CommandCompletions <C extends CommandCompletionContext> {

public CommandCompletions(CommandManager manager) {
this.manager = manager;
registerAsyncCompletion("nothing", c -> ImmutableList.of());
registerAsyncCompletion("nothing", c -> Collections.emptyList());
registerAsyncCompletion("range", (c) -> {
String config = c.getConfig();
if (config == null) {
return ImmutableList.of();
return Collections.emptyList();
}
final String[] ranges = ACFPatterns.DASH.split(config);
int start;
Expand All @@ -62,7 +63,8 @@ public CommandCompletions(CommandManager manager) {
}
return IntStream.rangeClosed(start, end).mapToObj(Integer::toString).collect(Collectors.toList());
});
registerAsyncCompletion("timeunits", (c) -> ImmutableList.of("minutes", "hours", "days", "weeks", "months", "years"));
List<String> timeunits = Arrays.asList("minutes", "hours", "days", "weeks", "months", "years");
registerAsyncCompletion("timeunits", (c) -> timeunits);
}

/**
Expand Down Expand Up @@ -117,7 +119,7 @@ public CommandCompletionHandler registerStaticCompletion(String id, String list)
* @return
*/
public CommandCompletionHandler registerStaticCompletion(String id, String[] completions) {
return registerStaticCompletion(id, Lists.newArrayList(completions));
return registerStaticCompletion(id, Arrays.asList(completions));
}

/**
Expand Down Expand Up @@ -178,7 +180,7 @@ List<String> of(RegisteredCommand cmd, CommandIssuer sender, String[] args, bool
completion = completions[completions.length - 1];
}
if (completion == null) {
return ImmutableList.of(input);
return Collections.singletonList(input);
}

return getCompletionValues(cmd, sender, completion, args, isAsync);
Expand All @@ -187,7 +189,7 @@ List<String> of(RegisteredCommand cmd, CommandIssuer sender, String[] args, bool
List<String> getCompletionValues(RegisteredCommand command, CommandIssuer sender, String completion, String[] args, boolean isAsync) {
completion = manager.getCommandReplacements().replace(completion);

List<String> allCompletions = Lists.newArrayList();
List<String> allCompletions = new ArrayList<>();
String input = args.length > 0 ? args[args.length - 1] : "";

for (String value : ACFPatterns.PIPE.split(completion)) {
Expand Down Expand Up @@ -215,10 +217,10 @@ List<String> getCompletionValues(RegisteredCommand command, CommandIssuer sender
} catch (CommandCompletionTextLookupException ignored) {
// This should only happen if some other feedback error occured.
} catch (Exception e) {
command.handleException(sender, Lists.newArrayList(args), e);
command.handleException(sender, Arrays.asList(args), e);
}
// Something went wrong in lookup, fall back to input
return ImmutableList.of(input);
return Collections.singletonList(input);
} else {
// Plaintext value
allCompletions.add(value);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/co/aikar/commands/CommandConditions.java
Expand Up @@ -24,9 +24,9 @@
package co.aikar.commands;

import co.aikar.util.Table;
import com.google.common.collect.Maps;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("BooleanMethodIsAlwaysInverted") // No IDEA, you are wrong
Expand All @@ -36,7 +36,7 @@ public class CommandConditions <
CC extends ConditionContext<I>
> {
private CommandManager manager;
private Map<String, Condition<I>> conditions = Maps.newHashMap();
private Map<String, Condition<I>> conditions = new HashMap<>();
private Table<Class<?>, String, ParameterCondition<?, ?, ?>> paramConditions = new Table<>();

CommandConditions(CommandManager manager) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/co/aikar/commands/CommandContexts.java
Expand Up @@ -30,17 +30,17 @@
import co.aikar.commands.contexts.IssuerAwareContextResolver;
import co.aikar.commands.contexts.IssuerOnlyContextResolver;
import co.aikar.commands.contexts.OptionalContextResolver;
import com.google.common.collect.Maps;
import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SuppressWarnings("WeakerAccess")
public class CommandContexts<R extends CommandExecutionContext<?, ? extends CommandIssuer>> {
protected final Map<Class<?>, ContextResolver<?, R>> contextMap = Maps.newHashMap();
protected final Map<Class<?>, ContextResolver<?, R>> contextMap = new HashMap<>();
protected final CommandManager manager;

CommandContexts(CommandManager manager) {
Expand Down
Expand Up @@ -23,8 +23,6 @@

package co.aikar.commands;

import co.aikar.commands.contexts.ContextResolver;

import java.lang.annotation.Annotation;
import java.lang.reflect.Parameter;
import java.util.List;
Expand Down
18 changes: 9 additions & 9 deletions core/src/main/java/co/aikar/commands/CommandManager.java
Expand Up @@ -26,17 +26,16 @@
import co.aikar.commands.annotation.Dependency;
import co.aikar.locales.MessageKeyProvider;
import co.aikar.util.Table;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Locale;
Expand All @@ -45,6 +44,7 @@
import java.util.Set;
import java.util.Stack;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;


@SuppressWarnings("WeakerAccess")
Expand Down Expand Up @@ -75,15 +75,15 @@ public synchronized CommandOperationContext peek() {
protected CommandHelpFormatter helpFormatter = new CommandHelpFormatter(this);

protected boolean usePerIssuerLocale = false;
protected List<IssuerLocaleChangedCallback<I>> localeChangedCallbacks = Lists.newArrayList();
protected Set<Locale> supportedLanguages = Sets.newHashSet(Locales.ENGLISH, Locales.GERMAN, Locales.SPANISH, Locales.CZECH, Locales.PORTUGUESE, Locales.SWEDISH, Locales.NORWEGIAN_BOKMAAL, Locales.NORWEGIAN_NYNORSK, Locales.RUSSIAN);
protected List<IssuerLocaleChangedCallback<I>> localeChangedCallbacks = new ArrayList<>();
protected Set<Locale> supportedLanguages = new HashSet<>(Arrays.asList(Locales.ENGLISH, Locales.GERMAN, Locales.SPANISH, Locales.CZECH, Locales.PORTUGUESE, Locales.SWEDISH, Locales.NORWEGIAN_BOKMAAL, Locales.NORWEGIAN_NYNORSK, Locales.RUSSIAN));
protected Map<MessageType, MF> formatters = new IdentityHashMap<>();
protected MF defaultFormatter;
protected int defaultHelpPerPage = 10;

protected Map<UUID, Locale> issuersLocale = Maps.newConcurrentMap();
protected Map<UUID, Locale> issuersLocale = new ConcurrentHashMap<>();

private Set<String> unstableAPIs = Sets.newHashSet();
private Set<String> unstableAPIs = new HashSet<>();

private Annotations annotations = new Annotations<>(this);

Expand Down Expand Up @@ -287,7 +287,7 @@ public synchronized RootCommand obtainRootCommand(@NotNull String cmd) {
}

public abstract Collection<RootCommand> getRegisteredRootCommands();

public RegisteredCommand createRegisteredCommand(BaseCommand command, String cmdName, Method method, String prefSubCommand) {
return new RegisteredCommand(command, cmdName, method, prefSubCommand);
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/co/aikar/commands/CommandParameter.java
Expand Up @@ -34,9 +34,9 @@
import co.aikar.commands.contexts.IssuerAwareContextResolver;
import co.aikar.commands.contexts.IssuerOnlyContextResolver;
import co.aikar.commands.contexts.OptionalContextResolver;
import com.google.common.collect.Maps;

import java.lang.reflect.Parameter;
import java.util.HashMap;
import java.util.Map;

public class CommandParameter <CEC extends CommandExecutionContext<CEC, ? extends CommandIssuer>> {
Expand Down Expand Up @@ -101,7 +101,7 @@ public CommandParameter(RegisteredCommand<CEC> command, Parameter param, int par
}
}

this.flags = Maps.newHashMap();
this.flags = new HashMap<>();
String flags = annotations.getAnnotationValue(param, Flags.class, Annotations.REPLACEMENTS | Annotations.NO_EMPTY);
if (flags != null) {
parseFlags(flags);
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/co/aikar/commands/ConditionContext.java
Expand Up @@ -23,8 +23,7 @@

package co.aikar.commands;

import com.google.common.collect.Maps;

import java.util.HashMap;
import java.util.Map;

public class ConditionContext <I extends CommandIssuer> {
Expand All @@ -36,7 +35,7 @@ public class ConditionContext <I extends CommandIssuer> {
ConditionContext(I issuer, String config) {
this.issuer = issuer;
this.config = config;
this.configs = Maps.newHashMap();
this.configs = new HashMap<>();
if (config != null) {
for (String s : ACFPatterns.COMMA.split(config)) {
String[] v = ACFPatterns.EQUALS.split(s, 2);
Expand Down

0 comments on commit 3c979a9

Please sign in to comment.