Replace Guava Iterables (#158)

Goes under #120

After this, only MultiMaps remain.
This commit is contained in:
Mark Vainomaa
2018-08-03 16:57:38 +03:00
committed by Daniel Ennis
parent 8fda944311
commit 65ff5a5500
4 changed files with 16 additions and 8 deletions
@@ -23,7 +23,6 @@
package co.aikar.commands;
import com.google.common.collect.Iterables;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@@ -281,7 +280,7 @@ public class ACFBukkitUtil {
"{search}", name);
return null;
} else {
Player player = Iterables.getOnlyElement(confirmList);
Player player = ACFUtil.getFirstElement(confirmList);
issuer.sendInfo(MinecraftMessageKeys.PLAYER_IS_VANISHED_CONFIRM, "{vanished}", player.getName());
return null;
}
@@ -33,6 +33,7 @@ import java.text.Normalizer.Form;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.function.Consumer;
@@ -588,6 +589,16 @@ public final class ACFUtil {
return list;
}
public static <T> T getFirstElement(Iterable<T> iterable) {
Iterator<T> iterator = iterable.iterator();
T first = iterator.next();
if (!iterator.hasNext()) {
return first;
}
throw new IllegalArgumentException("Expected one element in iterable");
}
private static class ApplyModifierToNumber {
private String num;
private boolean suffixes;
@@ -35,7 +35,6 @@ import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.UnknownHandler;
import co.aikar.commands.apachecommonslang.ApacheCommonsLangUtil;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.SetMultimap;
import org.jetbrains.annotations.Nullable;
@@ -614,7 +613,7 @@ public abstract class BaseCommand {
if (!cmds.isEmpty()) {
RegisteredCommand cmd = null;
if (cmds.size() == 1) {
cmd = Iterables.getOnlyElement(cmds);
cmd = ACFUtil.getFirstElement(cmds);
} else {
Optional<RegisteredCommand> optCmd = cmds.stream().filter(c -> {
int required = c.requiredResolvers;
@@ -718,9 +717,9 @@ public abstract class BaseCommand {
if (search != null) {
cmds.addAll(completeCommand(issuer, search.cmd, Arrays.copyOfRange(args, search.argIndex, args.length), commandLabel, isAsync));
} else if (subCommands.get(CATCHUNKNOWN).size() == 1) {
cmds.addAll(completeCommand(issuer, Iterables.getOnlyElement(subCommands.get(CATCHUNKNOWN)), args, commandLabel, isAsync));
cmds.addAll(completeCommand(issuer, ACFUtil.getFirstElement(subCommands.get(CATCHUNKNOWN)), args, commandLabel, isAsync));
} else if (subCommands.get(DEFAULT).size() == 1) {
cmds.addAll(completeCommand(issuer, Iterables.getOnlyElement(subCommands.get(DEFAULT)), args, commandLabel, isAsync));
cmds.addAll(completeCommand(issuer, ACFUtil.getFirstElement(subCommands.get(DEFAULT)), args, commandLabel, isAsync));
}
return filterTabComplete(args[args.length - 1], cmds);
@@ -1,6 +1,5 @@
package co.aikar.commands;
import com.google.common.collect.Iterables;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.entity.living.player.Player;
@@ -45,7 +44,7 @@ public class ACFSpongeUtil {
"{search}", name);
return null;
} else {
Player player = Iterables.getOnlyElement(confirmList);
Player player = ACFUtil.getFirstElement(confirmList);
issuer.sendInfo(MinecraftMessageKeys.PLAYER_IS_VANISHED_CONFIRM, "{vanished}", player.getName());
return null;
}