Search in sources :

Example 1 with Cell

use of com.google.common.collect.Table.Cell in project VotingPlugin by Ben12345rocks.

the class CommandLoader method loadAdminVoteCommand.

/**
 * Load admin vote command.
 */
private void loadAdminVoteCommand() {
    plugin.adminVoteCommand = new ArrayList<CommandHandler>();
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "ConvertFrom", "GAL" }, "VotingPlugin.Commands.AdminVote.ConvertFrom.GAL|" + adminPerm, "Convert from GAL") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (Bukkit.getServer().getPluginManager().getPlugin("GAListener") != null) {
                sender.sendMessage("Starting to convert");
                Table<String, Integer, Long> totals = GAL.p.db.getTotals();
                for (Cell<String, Integer, Long> entry : totals.cellSet()) {
                    String name = entry.getRowKey();
                    int total = entry.getColumnKey();
                    User user = UserManager.getInstance().getVotingPluginUser(name);
                    user.setAllTimeTotal(user.getAllTimeTotal() + total);
                }
                sender.sendMessage("Totals added");
                ListMultimap<VoteType, GALVote> votes = GAL.p.galVote;
                for (Entry<VoteType, GALVote> entry : votes.entries()) {
                    if (entry.getKey().equals(VoteType.NORMAL)) {
                        String msg = entry.getValue().message;
                        List<String> cmds = entry.getValue().commands;
                        String service = entry.getValue().key;
                        if (service.equalsIgnoreCase("default")) {
                        } else {
                            VoteSite site = plugin.getVoteSite(service);
                            if (site == null) {
                                sender.sendMessage("Failed to create vote site, autogeneratesites false?");
                                return;
                            }
                            ConfigurationSection data = configVoteSites.getData().getConfigurationSection(configVoteSites.getRewardsPath(site.getKey()));
                            data.set("Commands.Console", cmds);
                            data.set("Messages.Player", msg);
                            configVoteSites.saveData();
                            sender.sendMessage("created vote site: " + site.getKey());
                        }
                    }
                }
            } else {
                sender.sendMessage("GAL not loaded");
            }
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "ConvertFrom", "VoteRoulette" }, "VotingPlugin.Commands.AdminVote.ConvertFrom.GAL|" + adminPerm, "Convert from VoteRoulette") {

        @SuppressWarnings("static-access")
        @Override
        public void execute(CommandSender sender, String[] args) {
            if (Bukkit.getServer().getPluginManager().getPlugin("VoteRoulette") != null) {
                for (OfflinePlayer offPlayer : Bukkit.getOfflinePlayers()) {
                    VoteRoulette.getInstance();
                    Voter voter = VoteRoulette.getVoterManager().getVoter(offPlayer.getUniqueId(), offPlayer.getName());
                    User user = UserManager.getInstance().getVotingPluginUser(offPlayer);
                    user.setAllTimeTotal(user.getAllTimeTotal() + voter.getStatSheet().getLifetimeVotes());
                    user.setMonthTotal(user.getMonthTotal() + voter.getStatSheet().getCurrentMonthVotes());
                }
            } else {
                sender.sendMessage("VoteRoulette not loaded");
            }
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "SetPoints", "(player)", "(number)" }, "VotingPlugin.Commands.AdminVote.SetPoints|" + adminPerm, "Set players voting points") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            User user = UserManager.getInstance().getVotingPluginUser(args[1]);
            user.setPoints(Integer.parseInt(args[2]));
            sender.sendMessage(StringUtils.getInstance().colorize("&cSet " + args[1] + " points to " + args[2]));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "ResyncMilestones" }, "VotingPlugin.Commands.AdminVote.SetResyncMilestones|" + adminPerm, "Resync Milestones") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            sendMessage(sender, "&cStarting...");
            for (String uuid : UserManager.getInstance().getAllUUIDs()) {
                User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
                user.setMilestoneCount(user.getAllTimeTotal());
            }
            sendMessage(sender, "&cFinished");
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "AddPoints", "(player)", "(number)" }, "VotingPlugin.Commands.AdminVote.AddPoints|" + adminPerm, "Add to players voting points") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            User user = UserManager.getInstance().getVotingPluginUser(args[1]);
            user.addPoints(Integer.parseInt(args[2]));
            sender.sendMessage(StringUtils.getInstance().colorize("&cGave " + args[1] + " " + args[2] + " points" + ", " + args[1] + " now has " + user.getPoints() + " points"));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "RemovePoints", "(player)", "(number)" }, "VotingPlugin.Commands.AdminVote.RemovePoints|" + adminPerm, "Remove voting points") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            User user = UserManager.getInstance().getVotingPluginUser(args[1]);
            user.removePoints(Integer.parseInt(args[2]));
            sender.sendMessage(StringUtils.getInstance().colorize("&cRemoved " + args[2] + " points from " + args[1] + ", " + args[1] + " now has " + user.getPoints() + " points"));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "Help&?" }, "VotingPlugin.Commands.AdminVote.Help|" + adminPerm, "See this page") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            int page = 1;
            if (sender instanceof Player) {
                User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                user.sendJson(Commands.getInstance().adminHelp(sender, page - 1));
            } else {
                sender.sendMessage(ArrayUtils.getInstance().convert(ArrayUtils.getInstance().comptoString(Commands.getInstance().adminHelp(sender, page - 1))));
            }
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "ServiceSites" }, "VotingPlugin.Commands.AdminVote.ServiceSites|" + adminPerm, "See a list of all service sites the server got") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            sendMessage(sender, "&cEvery service site the server has gotten:");
            for (String serviceSites : ServerData.getInstance().getServiceSites()) {
                boolean hasSite = plugin.hasVoteSite(serviceSites);
                if (hasSite) {
                    String siteName = plugin.getVoteSiteName(serviceSites);
                    sendMessage(sender, serviceSites + " : Current site = " + siteName);
                } else {
                    sendMessage(sender, serviceSites + " : No site with this service site, did you do something wrong?");
                }
            }
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "Help&?", "(number)" }, "VotingPlugin.Commands.AdminVote.Help|" + adminPerm, "See this page") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            int page = Integer.parseInt(args[1]);
            if (sender instanceof Player) {
                User user = UserManager.getInstance().getVotingPluginUser((Player) sender);
                user.sendJson(Commands.getInstance().adminHelp(sender, page - 1));
            } else {
                sender.sendMessage(ArrayUtils.getInstance().convert(ArrayUtils.getInstance().comptoString(Commands.getInstance().adminHelp(sender, page - 1))));
            }
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "Report" }, "VotingPlugin.Commands.AdminVote.Report|" + adminPerm, "Create a zip file to send for debuging") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            Report.getInstance().create();
            sender.sendMessage("Created Zip File!");
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "Perms" }, "VotingPlugin.Commands.AdminVote.Perms|" + adminPerm, "List permissions") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            sender.sendMessage(Commands.getInstance().listPerms(sender));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "Perms", "(OnlinePlayer)" }, "VotingPlugin.Commands.AdminVote.Perms.Other|" + adminPerm, "List permissions from the plugin the player has") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            Commands.getInstance().listPerms(sender, args[1], 1);
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "Perms", "(OnlinePlayer)", "(Number)" }, "VotingPlugin.Commands.AdminVote.Perms.Other|" + adminPerm, "List permissions from the plugin the player has") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            Commands.getInstance().listPerms(sender, args[1], Integer.parseInt(args[2]));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "Reload" }, "VotingPlugin.Commands.AdminVote.Reload|" + adminPerm, "Reload plugin") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            sender.sendMessage(ChatColor.RED + "Reloading " + plugin.getName() + "...");
            plugin.reload();
            sender.sendMessage(ChatColor.RED + plugin.getName() + " v" + plugin.getDescription().getVersion() + " reloaded!");
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "Version" }, "VotingPlugin.Commands.AdminVote.Version|" + adminPerm, "List version info") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (sender instanceof Player) {
                Player player = (Player) sender;
                Bukkit.getScheduler().runTask(plugin, new Runnable() {

                    @Override
                    public void run() {
                        player.performCommand("bukkit:version " + plugin.getName());
                    }
                });
            } else {
                Bukkit.getScheduler().runTask(plugin, new Runnable() {

                    @Override
                    public void run() {
                        Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "bukkit:version " + plugin.getName());
                    }
                });
            }
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "Sites" }, "VotingPlugin.Commands.AdminVote.Sites|" + adminPerm, "List VoteSites", false) {

        @Override
        public void execute(CommandSender sender, String[] args) {
            AdminGUI.getInstance().openAdminGUIVoteSites((Player) sender);
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "GUI" }, "VotingPlugin.Commands.AdminVote.GUI|" + adminPerm, "Admin GUI", false) {

        @Override
        public void execute(CommandSender sender, String[] args) {
            com.Ben12345rocks.AdvancedCore.Commands.GUI.AdminGUI.getInstance().openGUI((Player) sender);
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "Sites", "(sitename)" }, "VotingPlugin.Commands.AdminVote.Sites.Site|" + adminPerm, "View Site Info") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (sender instanceof Player) {
                AdminGUI.getInstance().openAdminGUIVoteSiteSite((Player) sender, plugin.getVoteSite(args[1]));
            } else {
                sender.sendMessage("Must be a player to do this");
            }
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "UUID", "(player)" }, "VotingPlugin.Commands.AdminVote.UUID|" + adminPerm, "View UUID of player") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            sender.sendMessage(ChatColor.GREEN + "UUID of player " + ChatColor.DARK_GREEN + args[1] + ChatColor.GREEN + " is: " + PlayerUtils.getInstance().getUUID(args[1]));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "PlayerName", "(uuid)" }, "VotingPlugin.Commands.AdminVote.PlayerName|" + adminPerm, "View PlayerName of player") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            try {
                sender.sendMessage(ChatColor.GREEN + "PlayerName of player " + ChatColor.DARK_GREEN + args[1] + ChatColor.GREEN + " is: " + PlayerUtils.getInstance().getPlayerName(UserManager.getInstance().getVotingPluginUser(new UUID(args[1])), args[1]));
            } catch (IllegalArgumentException e) {
                sendMessage(sender, "&cInvalid uuid");
            }
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "ClearTotal" }, "VotingPlugin.Commands.AdminVote.ClearTotal.All|" + adminPerm, "Reset totals for all players") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (sender instanceof Player) {
                sender.sendMessage(StringUtils.getInstance().colorize("&cThis command can not be done from ingame"));
                return;
            }
            for (String uuid : UserManager.getInstance().getAllUUIDs()) {
                User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
                user.clearTotals();
            }
            sender.sendMessage(StringUtils.getInstance().colorize("&cCleared totals for everyone"));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "ClearOfflineRewards" }, "VotingPlugin.Commands.AdminVote.ClearOfflineRewards|" + adminPerm, "Reset offline votes/rewards") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (sender instanceof Player) {
                sender.sendMessage(StringUtils.getInstance().colorize("&cThis command can not be done from ingame"));
                return;
            }
            for (String uuid : UserManager.getInstance().getAllUUIDs()) {
                User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
                user.clearOfflineRewards();
            }
            sender.sendMessage(StringUtils.getInstance().colorize("&cCleared totals for everyone"));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "ConvertFromData", "(userstorage)" }, "VotingPlugin.Commands.AdminVote.ConvertFromData", "Convert from selected user storage to current user storage") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            if (sender instanceof Player) {
                sender.sendMessage(StringUtils.getInstance().colorize("&cThis can not be done ingame"));
                return;
            }
            try {
                sender.sendMessage("Starting to convert");
                UserStorage prevStorage = UserStorage.valueOf(args[1].toUpperCase());
                plugin.convertDataStorage(prevStorage, AdvancedCoreHook.getInstance().getStorageType());
                sender.sendMessage("Finished converting!");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "SetTotal", "Month", "(player)", "(number)" }, "VotingPlugin.Commands.AdminVote.SetTotal.Month|" + adminPerm, "Set month totals for player") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            UserManager.getInstance().getVotingPluginUser(args[2]).setMonthTotal(Integer.parseInt(args[3]));
            sender.sendMessage(StringUtils.getInstance().colorize("&cSet month total for '" + args[2] + "' to " + args[3]));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "SetTotal", "AllTime", "(player)", "(number)" }, "VotingPlugin.Commands.AdminVote.SetTotal.AllTime|" + adminPerm, "Set alltime totals for player") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            UserManager.getInstance().getVotingPluginUser(args[2]).setAllTimeTotal(Integer.parseInt(args[3]));
            sender.sendMessage(StringUtils.getInstance().colorize("&cSet alltime total for '" + args[2] + "' to " + args[3]));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "SetTotal", "Week", "(player)", "(number)" }, "VotingPlugin.Commands.AdminVote.SetTotal.Week|" + adminPerm, "Set week totals for player") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            UserManager.getInstance().getVotingPluginUser(args[2]).setWeeklyTotal(Integer.parseInt(args[3]));
            sender.sendMessage(StringUtils.getInstance().colorize("&cSet week total for '" + args[2] + "' to " + args[3]));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "SetTotal", "Day", "(player)", "(number)" }, "VotingPlugin.Commands.AdminVote.SetTotal.Day|" + adminPerm, "Set day totals for player") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            UserManager.getInstance().getVotingPluginUser(args[2]).setDailyTotal(Integer.parseInt(args[3]));
            sender.sendMessage(StringUtils.getInstance().colorize("&cSet day total for '" + args[2] + "' to " + args[3]));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "ClearTotal", "(player)" }, "VotingPlugin.Commands.AdminVote.ClearTotal|" + adminPerm, "Clear Totals for player") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            User user = UserManager.getInstance().getVotingPluginUser(args[1]);
            user.clearTotals();
            sender.sendMessage(StringUtils.getInstance().colorize("&cCleared totals for '" + args[1] + "'"));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "Vote", "(player)", "(Sitename)" }, "VotingPlugin.Commands.AdminVote.Vote|" + adminPerm, "Trigger manual vote") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            VotiferEvent.playerVote(args[1], args[2], false);
            PlayerVoteEvent voteEvent = new PlayerVoteEvent(plugin.getVoteSite(args[2]), args[1]);
            plugin.getServer().getPluginManager().callEvent(voteEvent);
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "VoteSite", "(sitename)", "Create" }, "VotingPlugin.Commands.AdminVote.VoteSite.Edit|" + adminPerm, "Create VoteSite") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            sender.sendMessage(StringUtils.getInstance().colorize("&cCreating VoteSite..." + args[1]));
            ConfigVoteSites.getInstance().generateVoteSite(args[1]);
            sender.sendMessage(StringUtils.getInstance().colorize("&cCreated VoteSite: &c&l" + args[1]));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "Config", "SetDebug", "(boolean)" }, "VotingPlugin.Commands.AdminVote.Config.Edit|" + adminPerm, "Set Debug on or off, effective until reload/restart") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            AdvancedCoreHook.getInstance().setDebug(true);
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "VoteSite", "(sitename)", "SetServiceSite", "(string)" }, "VotingPlugin.Commands.AdminVote.VoteSite.Edit|" + adminPerm, "Set VoteSite SerivceSite") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            String voteSite = plugin.getVoteSiteName(args[1]);
            String serviceSite = args[3];
            ConfigVoteSites.getInstance().setServiceSite(voteSite, serviceSite);
            sender.sendMessage(StringUtils.getInstance().colorize("&cSet ServiceSite to &c&l" + serviceSite + "&c on &c&l" + voteSite));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "VoteSite", "(sitename)", "SetVoteURL", "(string)" }, "VotingPlugin.Commands.AdminVote.VoteSite.Edit|" + adminPerm, "Set VoteSite VoteURL") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            String voteSite = plugin.getVoteSiteName(args[1]);
            String url = args[3];
            ConfigVoteSites.getInstance().setVoteURL(voteSite, url);
            sender.sendMessage(StringUtils.getInstance().colorize("&cSet VoteURL to &c&l" + url + "&c on &c&l" + voteSite));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "VoteSite", "(sitename)", "SetPriority", "(number)" }, "VotingPlugin.Commands.AdminVote.VoteSite.Edit|" + adminPerm, "Set VoteSite Priority") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            String voteSite = plugin.getVoteSiteName(args[1]);
            int value = Integer.parseInt(args[3]);
            ConfigVoteSites.getInstance().setPriority(voteSite, value);
            sender.sendMessage(StringUtils.getInstance().colorize("&cSet priortiy to &c&l" + value + "&c on &c&l" + voteSite));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "VoteSite", "(sitename)", "SetVoteDelay", "(number)" }, "VotingPlugin.Commands.AdminVote.VoteSite.Edit|" + adminPerm, "Set VoteSite VoteDelay") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            String voteSite = plugin.getVoteSiteName(args[1]);
            int delay = Integer.parseInt(args[3]);
            ConfigVoteSites.getInstance().setVoteDelay(voteSite, delay);
            sender.sendMessage(StringUtils.getInstance().colorize("&cSet VoteDelay to &c&l" + delay + "&c on &c&l" + voteSite));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "UpdateCheck" }, "VotingPlugin.Commands.AdminVote.UpdateCheck|" + adminPerm, "Check for update") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {

                @Override
                public void run() {
                    sender.sendMessage(StringUtils.getInstance().colorize("&cChecking for update..."));
                    plugin.updater = new Updater(plugin, 15358, false);
                    final Updater.UpdateResult result = plugin.updater.getResult();
                    switch(result) {
                        case FAIL_SPIGOT:
                            {
                                sender.sendMessage(StringUtils.getInstance().colorize("&cFailed to check for update for &c&l" + plugin.getName() + "&c!"));
                                break;
                            }
                        case NO_UPDATE:
                            {
                                sender.sendMessage(StringUtils.getInstance().colorize("&c&l" + plugin.getName() + " &cis up to date! Version: &c&l" + plugin.updater.getVersion()));
                                break;
                            }
                        case UPDATE_AVAILABLE:
                            {
                                sender.sendMessage(StringUtils.getInstance().colorize("&c&l" + plugin.getName() + " &chas an update available! Your Version: &c&l" + plugin.getDescription().getVersion() + " &cNew Version: &c&l" + plugin.updater.getVersion()));
                                break;
                            }
                        default:
                            {
                                break;
                            }
                    }
                }
            });
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "VoteSite", "(sitename)", "SetEnabled", "(boolean)" }, "VotingPlugin.Commands.AdminVote.VoteSite.Edit|" + adminPerm, "Set VoteSite Enabled") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            String voteSite = plugin.getVoteSiteName(args[1]);
            boolean value = Boolean.parseBoolean(args[3]);
            ConfigVoteSites.getInstance().setEnabled(voteSite, value);
            sender.sendMessage(StringUtils.getInstance().colorize("&cSet votesite " + voteSite + " enabled to " + value));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "VoteSite", "(sitename)", "Check" }, "VotingPlugin.Commands.AdminVote.VoteSite.Check|" + adminPerm, "Check to see if VoteSite is valid") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            String siteName = args[1];
            if (!ConfigVoteSites.getInstance().isServiceSiteGood(siteName)) {
                sender.sendMessage(StringUtils.getInstance().colorize("&cServiceSite is invalid, votes may not work properly"));
            } else {
                String service = ConfigVoteSites.getInstance().getServiceSite(siteName);
                if (ServerData.getInstance().getServiceSites().contains(service)) {
                    sender.sendMessage(StringUtils.getInstance().colorize("&aServiceSite is properly setup"));
                } else {
                    sender.sendMessage(StringUtils.getInstance().colorize("&cService may not be valid, haven't recieved a vote from " + service + ", see /av servicesites"));
                }
            }
            if (!ConfigVoteSites.getInstance().isVoteURLGood(siteName)) {
                sender.sendMessage(StringUtils.getInstance().colorize("&cVoteURL is invalid"));
            } else {
                sender.sendMessage(StringUtils.getInstance().colorize("&aVoteURL is properly setup"));
            }
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "BackgroundUpdate" }, "VotingPlugin.Commands.AdminVote.BackgroundUpdate|" + adminPerm, "Force a background update") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            plugin.setUpdate(true);
            plugin.update();
            sender.sendMessage(StringUtils.getInstance().colorize("&cUpdating..."));
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "SetVotePartyCount", "(number)" }, "VotingPlugin.Commands.AdminVote.SetVotePartyCount|" + adminPerm, "Set voteparty count") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            plugin.getVoteParty().setTotalVotes(Integer.parseInt(args[1]));
            sendMessage(sender, "&cSet vote party count to " + args[1]);
        }
    });
    plugin.adminVoteCommand.add(new CommandHandler(new String[] { "ClearOfflineVotes" }, "VotingPlugin.Commands.AdminVote.ClearOfflineVotes|" + adminPerm, "Clear all offline votes") {

        @Override
        public void execute(CommandSender sender, String[] args) {
            for (String uuid : UserManager.getInstance().getAllUUIDs()) {
                User user = UserManager.getInstance().getVotingPluginUser(new UUID(uuid));
                user.setOfflineVotes(new ArrayList<String>());
            }
            sender.sendMessage(StringUtils.getInstance().colorize("&cCleared"));
        }
    });
    ArrayList<CommandHandler> avCommands = com.Ben12345rocks.AdvancedCore.Commands.CommandLoader.getInstance().getBasicAdminCommands("VotingPlugin");
    for (CommandHandler cmd : avCommands) {
        cmd.setPerm(cmd.getPerm() + "|" + adminPerm);
    }
    plugin.adminVoteCommand.addAll(avCommands);
}
Also used : User(com.Ben12345rocks.VotingPlugin.Objects.User) ArrayList(java.util.ArrayList) CommandHandler(com.Ben12345rocks.AdvancedCore.Objects.CommandHandler) UserStorage(com.Ben12345rocks.AdvancedCore.Objects.UserStorage) VoteSite(com.Ben12345rocks.VotingPlugin.Objects.VoteSite) Entry(java.util.Map.Entry) Updater(com.Ben12345rocks.AdvancedCore.Util.Updater.Updater) Voter(com.mythicacraft.voteroulette.Voter) OfflinePlayer(org.bukkit.OfflinePlayer) List(java.util.List) ArrayList(java.util.ArrayList) UUID(com.Ben12345rocks.AdvancedCore.Objects.UUID) Cell(com.google.common.collect.Table.Cell) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) Table(com.google.common.collect.Table) PlayerVoteEvent(com.Ben12345rocks.VotingPlugin.Events.PlayerVoteEvent) CommandSender(org.bukkit.command.CommandSender) ListMultimap(com.google.common.collect.ListMultimap) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 2 with Cell

use of com.google.common.collect.Table.Cell in project guava by google.

the class TableCollectionTest method suite.

// suite
@GwtIncompatible
public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ArrayRowTests.class);
    suite.addTestSuite(HashRowTests.class);
    suite.addTestSuite(TreeRowTests.class);
    suite.addTestSuite(TransposeRowTests.class);
    suite.addTestSuite(TransformValueRowTests.class);
    suite.addTestSuite(UnmodifiableHashRowTests.class);
    suite.addTestSuite(UnmodifiableTreeRowTests.class);
    suite.addTestSuite(ArrayColumnTests.class);
    suite.addTestSuite(HashColumnTests.class);
    suite.addTestSuite(TreeColumnTests.class);
    suite.addTestSuite(TransposeColumnTests.class);
    suite.addTestSuite(TransformValueColumnTests.class);
    suite.addTestSuite(UnmodifiableHashColumnTests.class);
    suite.addTestSuite(UnmodifiableTreeColumnTests.class);
    suite.addTestSuite(ArrayRowMapTests.class);
    suite.addTestSuite(HashRowMapTests.class);
    suite.addTestSuite(TreeRowMapTests.class);
    suite.addTestSuite(TreeRowMapHeadMapTests.class);
    suite.addTestSuite(TreeRowMapTailMapTests.class);
    suite.addTestSuite(TreeRowMapSubMapTests.class);
    suite.addTestSuite(TransformValueRowMapTests.class);
    suite.addTestSuite(UnmodifiableHashRowMapTests.class);
    suite.addTestSuite(UnmodifiableTreeRowMapTests.class);
    suite.addTestSuite(ArrayColumnMapTests.class);
    suite.addTestSuite(HashColumnMapTests.class);
    suite.addTestSuite(TreeColumnMapTests.class);
    suite.addTestSuite(TransformValueColumnMapTests.class);
    suite.addTestSuite(UnmodifiableHashColumnMapTests.class);
    suite.addTestSuite(UnmodifiableTreeColumnMapTests.class);
    // Not testing rowKeySet() or columnKeySet() of Table.transformValues()
    // since the transformation doesn't affect the row and column key sets.
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = ArrayTable.create(ImmutableList.copyOf(elements), ImmutableList.of(1, 2));
            populateForRowKeySet(table, elements);
            return table.rowKeySet();
        }
    }).named("ArrayTable.rowKeySet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = HashBasedTable.create();
            populateForRowKeySet(table, elements);
            return table.rowKeySet();
        }
    }).named("HashBasedTable.rowKeySet").withFeatures(COLLECTION_FEATURES_REMOVE).withFeatures(CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
    suite.addTest(SortedSetTestSuiteBuilder.using(new TestStringSortedSetGenerator() {

        @Override
        protected SortedSet<String> create(String[] elements) {
            TreeBasedTable<String, Integer, Character> table = TreeBasedTable.create();
            populateForRowKeySet(table, elements);
            return table.rowKeySet();
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("TreeBasedTable.rowKeySet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).withFeatures(CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = HashBasedTable.create();
            populateForRowKeySet(table, elements);
            return Tables.unmodifiableTable(table).rowKeySet();
        }
    }).named("unmodifiableTable[HashBasedTable].rowKeySet").withFeatures(COLLECTION_FEATURES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            RowSortedTable<String, Integer, Character> table = TreeBasedTable.create();
            populateForRowKeySet(table, elements);
            return Tables.unmodifiableRowSortedTable(table).rowKeySet();
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("unmodifiableRowSortedTable[TreeBasedTable].rowKeySet").withFeatures(COLLECTION_FEATURES_ORDER).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<Integer, String, Character> table = ArrayTable.create(ImmutableList.of(1, 2), ImmutableList.copyOf(elements));
            populateForColumnKeySet(table, elements);
            return table.columnKeySet();
        }
    }).named("ArrayTable.columnKeySet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<Integer, String, Character> table = HashBasedTable.create();
            populateForColumnKeySet(table, elements);
            return table.columnKeySet();
        }
    }).named("HashBasedTable.columnKeySet").withFeatures(COLLECTION_FEATURES_REMOVE).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<Integer, String, Character> table = TreeBasedTable.create();
            populateForColumnKeySet(table, elements);
            return table.columnKeySet();
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("TreeBasedTable.columnKeySet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<Integer, String, Character> table = HashBasedTable.create();
            populateForColumnKeySet(table, elements);
            return Tables.unmodifiableTable(table).columnKeySet();
        }
    }).named("unmodifiableTable[HashBasedTable].columnKeySet").withFeatures(COLLECTION_FEATURES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            RowSortedTable<Integer, String, Character> table = TreeBasedTable.create();
            populateForColumnKeySet(table, elements);
            return Tables.unmodifiableRowSortedTable(table).columnKeySet();
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("unmodifiableRowSortedTable[TreeBasedTable].columnKeySet").withFeatures(COLLECTION_FEATURES_ORDER).createTestSuite());
    suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {

        @Override
        protected Collection<String> create(String[] elements) {
            List<Integer> rowKeys = Lists.newArrayList();
            for (int i = 0; i < elements.length; i++) {
                rowKeys.add(i);
            }
            Table<Integer, Character, String> table = ArrayTable.create(rowKeys, ImmutableList.of('a'));
            populateForValues(table, elements);
            return table.values();
        }
    }).named("ArrayTable.values").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.KNOWN_ORDER).createTestSuite());
    suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {

        @Override
        protected Collection<String> create(String[] elements) {
            Table<Integer, Character, String> table = HashBasedTable.create();
            table.put(1, 'a', "foo");
            table.clear();
            populateForValues(table, elements);
            return table.values();
        }
    }).named("HashBasedTable.values").withFeatures(COLLECTION_FEATURES_REMOVE).withFeatures(CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
    suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {

        @Override
        protected Collection<String> create(String[] elements) {
            Table<Integer, Character, String> table = TreeBasedTable.create();
            table.put(1, 'a', "foo");
            table.clear();
            populateForValues(table, elements);
            return table.values();
        }
    }).named("TreeBasedTable.values").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).withFeatures(CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
    final Function<String, String> removeFirstCharacter = new Function<String, String>() {

        @Override
        public String apply(String input) {
            return input.substring(1);
        }
    };
    suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {

        @Override
        protected Collection<String> create(String[] elements) {
            Table<Integer, Character, String> table = HashBasedTable.create();
            for (int i = 0; i < elements.length; i++) {
                table.put(i, 'a', "x" + checkNotNull(elements[i]));
            }
            return Tables.transformValues(table, removeFirstCharacter).values();
        }
    }).named("TransformValues.values").withFeatures(COLLECTION_FEATURES_REMOVE).withFeatures(CollectionFeature.SUPPORTS_ITERATOR_REMOVE).createTestSuite());
    suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {

        @Override
        protected Collection<String> create(String[] elements) {
            Table<Integer, Character, String> table = HashBasedTable.create();
            table.put(1, 'a', "foo");
            table.clear();
            populateForValues(table, elements);
            return Tables.unmodifiableTable(table).values();
        }
    }).named("unmodifiableTable[HashBasedTable].values").withFeatures(COLLECTION_FEATURES).createTestSuite());
    suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {

        @Override
        protected Collection<String> create(String[] elements) {
            RowSortedTable<Integer, Character, String> table = TreeBasedTable.create();
            table.put(1, 'a', "foo");
            table.clear();
            populateForValues(table, elements);
            return Tables.unmodifiableRowSortedTable(table).values();
        }
    }).named("unmodifiableTable[TreeBasedTable].values").withFeatures(COLLECTION_FEATURES_ORDER).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        public SampleElements<Cell<String, Integer, Character>> samples() {
            return new SampleElements<>(Tables.immutableCell("bar", 1, 'a'), Tables.immutableCell("bar", 2, 'b'), Tables.immutableCell("bar", 3, (Character) null), Tables.immutableCell("bar", 4, 'b'), Tables.immutableCell("bar", 5, 'b'));
        }

        @Override
        public Set<Cell<String, Integer, Character>> create(Object... elements) {
            List<Integer> columnKeys = Lists.newArrayList();
            for (Object element : elements) {
                @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
                columnKeys.add(cell.getColumnKey());
            }
            Table<String, Integer, Character> table = ArrayTable.create(ImmutableList.of("bar"), columnKeys);
            for (Object element : elements) {
                @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
                table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
            }
            return table.cellSet();
        }

        @Override
        Table<String, Integer, Character> createTable() {
            throw new UnsupportedOperationException();
        }
    }).named("ArrayTable.cellSet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        Table<String, Integer, Character> createTable() {
            return HashBasedTable.create();
        }
    }).named("HashBasedTable.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        Table<String, Integer, Character> createTable() {
            return TreeBasedTable.create();
        }
    }).named("TreeBasedTable.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        Table<String, Integer, Character> createTable() {
            Table<Integer, String, Character> original = TreeBasedTable.create();
            return Tables.transpose(original);
        }
    }).named("TransposedTable.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        Table<String, Integer, Character> createTable() {
            return HashBasedTable.create();
        }

        @Override
        public Set<Cell<String, Integer, Character>> create(Object... elements) {
            Table<String, Integer, Character> table = createTable();
            for (Object element : elements) {
                @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
                table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
            }
            return Tables.transformValues(table, Functions.<Character>identity()).cellSet();
        }
    }).named("TransformValues.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES, CollectionFeature.REMOVE_OPERATIONS).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        Table<String, Integer, Character> createTable() {
            return Tables.unmodifiableTable(HashBasedTable.<String, Integer, Character>create());
        }

        @Override
        public Set<Cell<String, Integer, Character>> create(Object... elements) {
            Table<String, Integer, Character> table = HashBasedTable.create();
            for (Object element : elements) {
                @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
                table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
            }
            return Tables.unmodifiableTable(table).cellSet();
        }
    }).named("unmodifiableTable[HashBasedTable].cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        RowSortedTable<String, Integer, Character> createTable() {
            return Tables.unmodifiableRowSortedTable(TreeBasedTable.<String, Integer, Character>create());
        }

        @Override
        public Set<Cell<String, Integer, Character>> create(Object... elements) {
            RowSortedTable<String, Integer, Character> table = TreeBasedTable.create();
            for (Object element : elements) {
                @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
                table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
            }
            return Tables.unmodifiableRowSortedTable(table).cellSet();
        }
    }).named("unmodifiableRowSortedTable[TreeBasedTable].cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Iterable<String> rowKeys = ImmutableSet.copyOf(elements);
            Iterable<Integer> columnKeys = ImmutableList.of(1, 2, 3);
            Table<String, Integer, Character> table = ArrayTable.create(rowKeys, columnKeys);
            populateForRowKeySet(table, elements);
            return table.column(1).keySet();
        }
    }).named("ArrayTable.column.keySet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = HashBasedTable.create();
            populateForRowKeySet(table, elements);
            return table.column(1).keySet();
        }
    }).named("HashBasedTable.column.keySet").withFeatures(COLLECTION_FEATURES_REMOVE).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = TreeBasedTable.create();
            populateForRowKeySet(table, elements);
            return table.column(1).keySet();
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("TreeBasedTable.column.keySet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = HashBasedTable.create();
            populateForRowKeySet(table, elements);
            return Tables.transformValues(table, Functions.toStringFunction()).column(1).keySet();
        }
    }).named("TransformValues.column.keySet").withFeatures(COLLECTION_FEATURES_REMOVE).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = HashBasedTable.create();
            populateForRowKeySet(table, elements);
            return Tables.unmodifiableTable(table).column(1).keySet();
        }
    }).named("unmodifiableTable[HashBasedTable].column.keySet").withFeatures(COLLECTION_FEATURES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            RowSortedTable<String, Integer, Character> table = TreeBasedTable.create();
            populateForRowKeySet(table, elements);
            return Tables.unmodifiableRowSortedTable(table).column(1).keySet();
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("unmodifiableRowSortedTable[TreeBasedTable].column.keySet").withFeatures(COLLECTION_FEATURES_ORDER).createTestSuite());
    return suite;
}
Also used : SortedSet(java.util.SortedSet) Set(java.util.Set) TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) Function(com.google.common.base.Function) TestSuite(junit.framework.TestSuite) List(java.util.List) Cell(com.google.common.collect.Table.Cell) TestStringCollectionGenerator(com.google.common.collect.testing.TestStringCollectionGenerator) TestStringSortedSetGenerator(com.google.common.collect.testing.TestStringSortedSetGenerator) SampleElements(com.google.common.collect.testing.SampleElements) Collection(java.util.Collection) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 3 with Cell

use of com.google.common.collect.Table.Cell in project guava by hceylan.

the class TableCollectionTest method suite.

@GwtIncompatible("suite")
public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ArrayRowTests.class);
    suite.addTestSuite(HashRowTests.class);
    suite.addTestSuite(TreeRowTests.class);
    suite.addTestSuite(TransposeRowTests.class);
    suite.addTestSuite(TransformValueRowTests.class);
    suite.addTestSuite(UnmodifiableHashRowTests.class);
    suite.addTestSuite(UnmodifiableTreeRowTests.class);
    suite.addTestSuite(ArrayColumnTests.class);
    suite.addTestSuite(HashColumnTests.class);
    suite.addTestSuite(TreeColumnTests.class);
    suite.addTestSuite(TransposeColumnTests.class);
    suite.addTestSuite(TransformValueColumnTests.class);
    suite.addTestSuite(UnmodifiableHashColumnTests.class);
    suite.addTestSuite(UnmodifiableTreeColumnTests.class);
    suite.addTestSuite(ArrayRowMapTests.class);
    suite.addTestSuite(HashRowMapTests.class);
    suite.addTestSuite(TreeRowMapTests.class);
    suite.addTestSuite(TreeRowMapHeadMapTests.class);
    suite.addTestSuite(TreeRowMapTailMapTests.class);
    suite.addTestSuite(TreeRowMapSubMapTests.class);
    suite.addTestSuite(TransformValueRowMapTests.class);
    suite.addTestSuite(UnmodifiableHashRowMapTests.class);
    suite.addTestSuite(UnmodifiableTreeRowMapTests.class);
    suite.addTestSuite(ArrayColumnMapTests.class);
    suite.addTestSuite(HashColumnMapTests.class);
    suite.addTestSuite(TreeColumnMapTests.class);
    suite.addTestSuite(TransformValueColumnMapTests.class);
    suite.addTestSuite(UnmodifiableHashColumnMapTests.class);
    suite.addTestSuite(UnmodifiableTreeColumnMapTests.class);
    // Not testing rowKeySet() or columnKeySet() of Table.transformValues()
    // since the transformation doesn't affect the row and column key sets.
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = ArrayTable.create(ImmutableList.copyOf(elements), ImmutableList.of(1, 2));
            populateForRowKeySet(table, elements);
            return table.rowKeySet();
        }
    }).named("ArrayTable.rowKeySet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = HashBasedTable.create();
            populateForRowKeySet(table, elements);
            return table.rowKeySet();
        }
    }).named("HashBasedTable.rowKeySet").withFeatures(COLLECTION_FEATURES_REMOVE).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = TreeBasedTable.create();
            populateForRowKeySet(table, elements);
            return table.rowKeySet();
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("TreeBasedTable.rowKeySet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            TreeBasedTable<String, Integer, Character> table = TreeBasedTable.create();
            populateForRowKeySet(table, elements);
            table.put("z", 1, 'a');
            return table.rowKeySet().headSet("x");
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("TreeBasedTable.rowKeySet.headSet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            TreeBasedTable<String, Integer, Character> table = TreeBasedTable.create();
            populateForRowKeySet(table, elements);
            table.put("\0", 1, 'a');
            return table.rowKeySet().tailSet("a");
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("TreeBasedTable.rowKeySet.tailSet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            TreeBasedTable<String, Integer, Character> table = TreeBasedTable.create();
            populateForRowKeySet(table, elements);
            table.put("\0", 1, 'a');
            table.put("z", 1, 'a');
            return table.rowKeySet().subSet("a", "x");
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("TreeBasedTable.rowKeySet.subSet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = HashBasedTable.create();
            populateForRowKeySet(table, elements);
            return Tables.unmodifiableTable(table).rowKeySet();
        }
    }).named("unmodifiableTable[HashBasedTable].rowKeySet").withFeatures(COLLECTION_FEATURES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            RowSortedTable<String, Integer, Character> table = TreeBasedTable.create();
            populateForRowKeySet(table, elements);
            return Tables.unmodifiableRowSortedTable(table).rowKeySet();
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("unmodifiableRowSortedTable[TreeBasedTable].rowKeySet").withFeatures(COLLECTION_FEATURES_ORDER).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<Integer, String, Character> table = ArrayTable.create(ImmutableList.of(1, 2), ImmutableList.copyOf(elements));
            populateForColumnKeySet(table, elements);
            return table.columnKeySet();
        }
    }).named("ArrayTable.columnKeySet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<Integer, String, Character> table = HashBasedTable.create();
            populateForColumnKeySet(table, elements);
            return table.columnKeySet();
        }
    }).named("HashBasedTable.columnKeySet").withFeatures(COLLECTION_FEATURES_REMOVE).suppressing(getIteratorUnknownOrderRemoveSupportedMethod()).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<Integer, String, Character> table = TreeBasedTable.create();
            populateForColumnKeySet(table, elements);
            return table.columnKeySet();
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("TreeBasedTable.columnKeySet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).suppressing(getIteratorKnownOrderRemoveSupportedMethod()).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<Integer, String, Character> table = HashBasedTable.create();
            populateForColumnKeySet(table, elements);
            return Tables.unmodifiableTable(table).columnKeySet();
        }
    }).named("unmodifiableTable[HashBasedTable].columnKeySet").withFeatures(COLLECTION_FEATURES).suppressing(getIteratorUnknownOrderRemoveSupportedMethod()).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            RowSortedTable<Integer, String, Character> table = TreeBasedTable.create();
            populateForColumnKeySet(table, elements);
            return Tables.unmodifiableRowSortedTable(table).columnKeySet();
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("unmodifiableRowSortedTable[TreeBasedTable].columnKeySet").withFeatures(COLLECTION_FEATURES_ORDER).suppressing(getIteratorKnownOrderRemoveSupportedMethod()).createTestSuite());
    suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {

        @Override
        protected Collection<String> create(String[] elements) {
            List<Integer> rowKeys = Lists.newArrayList();
            for (int i = 0; i < elements.length; i++) {
                rowKeys.add(i);
            }
            Table<Integer, Character, String> table = ArrayTable.create(rowKeys, ImmutableList.of('a'));
            populateForValues(table, elements);
            return table.values();
        }
    }).named("ArrayTable.values").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.ALLOWS_NULL_VALUES, CollectionFeature.KNOWN_ORDER).createTestSuite());
    suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {

        @Override
        protected Collection<String> create(String[] elements) {
            Table<Integer, Character, String> table = HashBasedTable.create();
            table.put(1, 'a', "foo");
            table.clear();
            populateForValues(table, elements);
            return table.values();
        }
    }).named("HashBasedTable.values").withFeatures(COLLECTION_FEATURES_REMOVE).createTestSuite());
    suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {

        @Override
        protected Collection<String> create(String[] elements) {
            Table<Integer, Character, String> table = TreeBasedTable.create();
            table.put(1, 'a', "foo");
            table.clear();
            populateForValues(table, elements);
            return table.values();
        }
    }).named("TreeBasedTable.values").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).createTestSuite());
    final Function<String, String> removeFirstCharacter = new Function<String, String>() {

        @Override
        public String apply(String input) {
            return input.substring(1);
        }
    };
    suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {

        @Override
        protected Collection<String> create(String[] elements) {
            Table<Integer, Character, String> table = HashBasedTable.create();
            for (int i = 0; i < elements.length; i++) {
                table.put(i, 'a', "x" + checkNotNull(elements[i]));
            }
            return Tables.transformValues(table, removeFirstCharacter).values();
        }
    }).named("TransformValues.values").withFeatures(COLLECTION_FEATURES_REMOVE).createTestSuite());
    suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {

        @Override
        protected Collection<String> create(String[] elements) {
            Table<Integer, Character, String> table = HashBasedTable.create();
            table.put(1, 'a', "foo");
            table.clear();
            populateForValues(table, elements);
            return Tables.unmodifiableTable(table).values();
        }
    }).named("unmodifiableTable[HashBasedTable].values").withFeatures(COLLECTION_FEATURES).createTestSuite());
    suite.addTest(CollectionTestSuiteBuilder.using(new TestStringCollectionGenerator() {

        @Override
        protected Collection<String> create(String[] elements) {
            RowSortedTable<Integer, Character, String> table = TreeBasedTable.create();
            table.put(1, 'a', "foo");
            table.clear();
            populateForValues(table, elements);
            return Tables.unmodifiableRowSortedTable(table).values();
        }
    }).named("unmodifiableTable[TreeBasedTable].values").withFeatures(COLLECTION_FEATURES_ORDER).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        public SampleElements<Cell<String, Integer, Character>> samples() {
            return new SampleElements<Cell<String, Integer, Character>>(Tables.immutableCell("bar", 1, 'a'), Tables.immutableCell("bar", 2, 'b'), Tables.immutableCell("bar", 3, (Character) null), Tables.immutableCell("bar", 4, 'b'), Tables.immutableCell("bar", 5, 'b'));
        }

        @Override
        public Set<Cell<String, Integer, Character>> create(Object... elements) {
            List<Integer> columnKeys = Lists.newArrayList();
            for (Object element : elements) {
                @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
                columnKeys.add(cell.getColumnKey());
            }
            Table<String, Integer, Character> table = ArrayTable.create(ImmutableList.of("bar"), columnKeys);
            for (Object element : elements) {
                @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
                table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
            }
            return table.cellSet();
        }

        @Override
        Table<String, Integer, Character> createTable() {
            throw new UnsupportedOperationException();
        }
    }).named("ArrayTable.cellSet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.REJECTS_DUPLICATES_AT_CREATION, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        Table<String, Integer, Character> createTable() {
            return HashBasedTable.create();
        }
    }).named("HashBasedTable.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        Table<String, Integer, Character> createTable() {
            return TreeBasedTable.create();
        }
    }).named("TreeBasedTable.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        Table<String, Integer, Character> createTable() {
            Table<Integer, String, Character> original = TreeBasedTable.create();
            return Tables.transpose(original);
        }
    }).named("TransposedTable.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        Table<String, Integer, Character> createTable() {
            return HashBasedTable.create();
        }

        @Override
        public Set<Cell<String, Integer, Character>> create(Object... elements) {
            Table<String, Integer, Character> table = createTable();
            for (Object element : elements) {
                @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
                table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
            }
            return Tables.transformValues(table, Functions.<Character>identity()).cellSet();
        }
    }).named("TransformValues.cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES, CollectionFeature.REMOVE_OPERATIONS).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        Table<String, Integer, Character> createTable() {
            return Tables.unmodifiableTable(HashBasedTable.<String, Integer, Character>create());
        }

        @Override
        public Set<Cell<String, Integer, Character>> create(Object... elements) {
            Table<String, Integer, Character> table = HashBasedTable.create();
            for (Object element : elements) {
                @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
                table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
            }
            return Tables.unmodifiableTable(table).cellSet();
        }
    }).named("unmodifiableTable[HashBasedTable].cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestCellSetGenerator() {

        @Override
        RowSortedTable<String, Integer, Character> createTable() {
            return Tables.unmodifiableRowSortedTable(TreeBasedTable.<String, Integer, Character>create());
        }

        @Override
        public Set<Cell<String, Integer, Character>> create(Object... elements) {
            RowSortedTable<String, Integer, Character> table = TreeBasedTable.create();
            for (Object element : elements) {
                @SuppressWarnings("unchecked") Cell<String, Integer, Character> cell = (Cell<String, Integer, Character>) element;
                table.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
            }
            return Tables.unmodifiableRowSortedTable(table).cellSet();
        }
    }).named("unmodifiableRowSortedTable[TreeBasedTable].cellSet").withFeatures(CollectionSize.ANY, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Iterable<String> rowKeys = ImmutableSet.copyOf(elements);
            Iterable<Integer> columnKeys = ImmutableList.of(1, 2, 3);
            Table<String, Integer, Character> table = ArrayTable.create(rowKeys, columnKeys);
            populateForRowKeySet(table, elements);
            return table.column(1).keySet();
        }
    }).named("ArrayTable.column.keySet").withFeatures(CollectionSize.ONE, CollectionSize.SEVERAL, CollectionFeature.KNOWN_ORDER, CollectionFeature.ALLOWS_NULL_QUERIES).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = HashBasedTable.create();
            populateForRowKeySet(table, elements);
            return table.column(1).keySet();
        }
    }).named("HashBasedTable.column.keySet").withFeatures(COLLECTION_FEATURES_REMOVE).suppressing(getIteratorUnknownOrderRemoveSupportedMethod()).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = TreeBasedTable.create();
            populateForRowKeySet(table, elements);
            return table.column(1).keySet();
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("TreeBasedTable.column.keySet").withFeatures(COLLECTION_FEATURES_REMOVE_ORDER).suppressing(getIteratorKnownOrderRemoveSupportedMethod()).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = HashBasedTable.create();
            populateForRowKeySet(table, elements);
            return Tables.transformValues(table, Functions.toStringFunction()).column(1).keySet();
        }
    }).named("TransformValues.column.keySet").withFeatures(COLLECTION_FEATURES_REMOVE).suppressing(getIteratorUnknownOrderRemoveSupportedMethod()).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            Table<String, Integer, Character> table = HashBasedTable.create();
            populateForRowKeySet(table, elements);
            return Tables.unmodifiableTable(table).column(1).keySet();
        }
    }).named("unmodifiableTable[HashBasedTable].column.keySet").withFeatures(COLLECTION_FEATURES).suppressing(getIteratorUnknownOrderRemoveSupportedMethod()).createTestSuite());
    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {

        @Override
        protected Set<String> create(String[] elements) {
            RowSortedTable<String, Integer, Character> table = TreeBasedTable.create();
            populateForRowKeySet(table, elements);
            return Tables.unmodifiableRowSortedTable(table).column(1).keySet();
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder);
            return insertionOrder;
        }
    }).named("unmodifiableRowSortedTable[TreeBasedTable].column.keySet").withFeatures(COLLECTION_FEATURES_ORDER).suppressing(getIteratorKnownOrderRemoveSupportedMethod()).createTestSuite());
    return suite;
}
Also used : Set(java.util.Set) TestStringSetGenerator(com.google.common.collect.testing.TestStringSetGenerator) Function(com.google.common.base.Function) TestSuite(junit.framework.TestSuite) List(java.util.List) Cell(com.google.common.collect.Table.Cell) TestStringCollectionGenerator(com.google.common.collect.testing.TestStringCollectionGenerator) SampleElements(com.google.common.collect.testing.SampleElements) Collection(java.util.Collection) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Aggregations

Cell (com.google.common.collect.Table.Cell)3 List (java.util.List)3 GwtIncompatible (com.google.common.annotations.GwtIncompatible)2 Function (com.google.common.base.Function)2 SampleElements (com.google.common.collect.testing.SampleElements)2 TestStringCollectionGenerator (com.google.common.collect.testing.TestStringCollectionGenerator)2 TestStringSetGenerator (com.google.common.collect.testing.TestStringSetGenerator)2 Collection (java.util.Collection)2 Set (java.util.Set)2 TestSuite (junit.framework.TestSuite)2 CommandHandler (com.Ben12345rocks.AdvancedCore.Objects.CommandHandler)1 UUID (com.Ben12345rocks.AdvancedCore.Objects.UUID)1 UserStorage (com.Ben12345rocks.AdvancedCore.Objects.UserStorage)1 Updater (com.Ben12345rocks.AdvancedCore.Util.Updater.Updater)1 PlayerVoteEvent (com.Ben12345rocks.VotingPlugin.Events.PlayerVoteEvent)1 User (com.Ben12345rocks.VotingPlugin.Objects.User)1 VoteSite (com.Ben12345rocks.VotingPlugin.Objects.VoteSite)1 ListMultimap (com.google.common.collect.ListMultimap)1 Table (com.google.common.collect.Table)1 TestStringSortedSetGenerator (com.google.common.collect.testing.TestStringSortedSetGenerator)1