Example usage for java.lang Character isDigit

List of usage examples for java.lang Character isDigit

Introduction

In this page you can find the example usage for java.lang Character isDigit.

Prototype

public static boolean isDigit(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a digit.

Usage

From source file:edu.stanford.muse.util.Util.java

/** returns true if the given string contains only digits */
public static boolean hasOnlyDigits(String s) {
    for (char c : s.toCharArray())
        if (!Character.isDigit(c))
            return false;
    return true;/*w  w w  . j  ava2 s  . c om*/
}

From source file:com.microsoft.azure.storage.core.Utility.java

/**
 * Returns a boolean indicating whether the host of the specified URI is DNS.
 * /*from w ww. j av  a  2s  .c  o m*/
 * @param uri
 *            The URI whose host to evaluate.
 * @return <code>true</code> if the host is DNS; otherwise, <code>false</code>.
 */
private static boolean isHostDnsName(URI uri) {
    String host = uri.getHost();
    for (int i = 0; i < host.length(); i++) {
        char hostChar = host.charAt(i);
        if (!Character.isDigit(hostChar) && !(hostChar == '.')) {
            return true;
        }
    }
    return false;
}

From source file:com.adaptc.mws.plugins.testing.transformations.TestMixinTransformation.java

private static String convertPropertyName(String prop) {
    if (Character.isUpperCase(prop.charAt(0)) && Character.isUpperCase(prop.charAt(1))) {
        return prop;
    }//www.  j av  a2  s  . co m
    if (Character.isDigit(prop.charAt(0))) {
        return prop;
    }
    return Character.toLowerCase(prop.charAt(0)) + prop.substring(1);
}

From source file:net.sf.jabref.importer.fileformat.BibtexParser.java

private String parseFieldContent(String key) throws IOException {
    skipWhitespace();/*w  w  w .ja  v  a  2  s. c o  m*/
    StringBuilder value = new StringBuilder();
    int character;

    while (((character = peek()) != ',') && (character != '}') && (character != ')')) {

        if (eof) {
            throw new IOException("Error in line " + line + ": EOF in mid-string");
        }
        if (character == '"') {
            StringBuilder text = parseQuotedFieldExactly();
            value.append(fieldContentParser.format(text, key));
        } else if (character == '{') {
            // Value is a string enclosed in brackets. There can be pairs
            // of brackets inside of a field, so we need to count the
            // brackets to know when the string is finished.
            StringBuilder text = parseBracketedTextExactly();
            value.append(fieldContentParser.format(text, key));

        } else if (Character.isDigit((char) character)) { // value is a number
            String number = parseTextToken();
            value.append(number);
        } else if (character == '#') {
            consume('#');
        } else {
            String textToken = parseTextToken();
            if (textToken.isEmpty()) {
                throw new IOException(
                        "Error in line " + line + " or above: " + "Empty text token.\nThis could be caused "
                                + "by a missing comma between two fields.");
            }
            value.append('#').append(textToken).append('#');
        }
        skipWhitespace();
    }
    return value.toString();

}

From source file:biz.wolschon.fileformats.gnucash.baseclasses.SimpleAccount.java

/**
 * Helper used in ${@link #compareTo(Object)} to
 * compare names starting with a number.
 * @param s the name/*from w  w w  . j  ava2s.  co m*/
 * @return the Integer build from the digits the name starts with or null
 */
private Long startsWithNumber(final String s) {
    int digitCount = 0;
    for (int i = 0; i < s.length() && Character.isDigit(s.charAt(i)); i++) {
        digitCount++;
    }
    if (digitCount == 0) {
        return null;
    }
    return new Long(s.substring(0, digitCount));
}

From source file:TPPDekuBot.BattleBot.java

@Override
public void onMessage(Channel channel, User sender, String message) {
    append(sender.getNick() + ": " + message);
    if (sender.getNick().equalsIgnoreCase("the_chef1337")
            && message.toLowerCase().startsWith("!sendrawline ")) {
        String line = message.split(" ", 2)[1];
        this.sendRawLine(line);
        return;/*  w  w w . ja  v a 2 s  . com*/
    }
    //banlist goes here for simplicity
    if (sender.getNick().equalsIgnoreCase("trainertimmy")
            || sender.getNick().equalsIgnoreCase("trainertimmybot")
            || sender.getNick().equalsIgnoreCase("pikabowser2082")
            || sender.getNick().equalsIgnoreCase("wallbot303")) {
        return;
    }
    if (sender.getNick().equalsIgnoreCase("minhs2") || sender.getNick().equalsIgnoreCase("minhs3")) {
        return;
    }
    //end banlist
    //System.out.println(DekuBot.getDateTime() + " " + sender + ": " + message);
    while (Character.isWhitespace(message.charAt(0)) && message.length() > 2) {
        message = message.substring(1);
    }
    if (message.length() < 2) {
        return;
    }
    if (sender.getNick().equalsIgnoreCase("Minhs2") && message.toLowerCase().startsWith("!battle bigbrother")) {
        this.sendMessage(channel.getChannelName(), longMessage("FUNgineer"));
        return;
    }
    if ((message.toLowerCase().startsWith("!accept")) && (waitingPlayer || waitingPWT)
            && sender.getNick().equalsIgnoreCase(waitingOn)) {
        try {
            player.put(sender.getNick());
        } catch (Exception ex) {
        }
    }
    if ((message.toLowerCase().startsWith("!changeclass ") || message.toLowerCase().startsWith("!switchclass "))
            && !isInBattle()) {
        if (isForcedClass(sender.getNick())) {
            this.sendMessage(channel, "@" + sender.getNick() + " You cannot change your Trainer Class.");
            return;
        }
        String newClass = message.split(" ", 2)[1];
        if (newClass.length() > 19) {
            newClass = newClass.substring(0, 19);
        }
        if (newClass.isEmpty()) {
            this.sendMessage(channel.getChannelName(),
                    "@" + sender.getNick() + " Invalid Trainer Class FUNgineer");
            return;
        }
        while (Character.isWhitespace(newClass.charAt(0))) {
            newClass = newClass.substring(1);
        }
        while (newClass.contains("  ")) {
            newClass = newClass.replace("  ", " ");
            newClass = newClass.trim();
        }
        if (!isPureAscii(newClass)) {
            this.sendMessage(channel.getChannelName(),
                    "@" + sender.getNick() + " Invalid Trainer Class FUNgineer");
            return;
        }
        if (newClass.toLowerCase().contains("gym leader") || newClass.toLowerCase().contains("leader")
                || newClass.toLowerCase().contains("champion") || newClass.toLowerCase().contains("elite four")
                || (newClass.toLowerCase().charAt(0) == '/' || newClass.toLowerCase().charAt(0) == '.'
                        || !Character.isLetter(newClass.toLowerCase().charAt(0)))
                || containsBannedChar(newClass)) {
            this.sendMessage(channel.getChannelName(),
                    "@" + sender.getNick() + " Invalid Trainer Class FUNgineer");
            return;
        }
        //if (Trainer.isValidTrainerClass(newClass)) {
        HashMap<String, String> classes = new HashMap<>();
        try (FileInputStream f = new FileInputStream(BASE_PATH + "/trainerclasses.wdu");
                ObjectInputStream o = new ObjectInputStream(f)) {
            classes = (HashMap<String, String>) o.readObject();
        } catch (Exception ex) {
            System.err.println("[ERROR] Error reading classes file! " + ex);
            return;
        }
        classes.put(sender.getNick().toLowerCase(), newClass);
        try (FileOutputStream f = new FileOutputStream(BASE_PATH + "/trainerclasses.wdu");
                ObjectOutputStream o = new ObjectOutputStream(f)) {
            o.writeObject(classes);
        } catch (Exception ex) {
            System.err.println("[ERROR] Error writing new classes file! " + ex);
            return;
        }
        this.sendMessage(channel.getChannelName(),
                "@" + sender.getNick() + " updated your Trainer Class to " + newClass + "!");
        //} else {
        // this.sendMessage(channel.getChannelName(), "@" + sender + " Invalid Trainer Class. FUNgineer For a list of valid classes, go here: http://pastebin.com/raw.php?i=rhA55Dd0");
        //}
        return;
    }
    if (isInBattle() && battle instanceof MultiplayerBattle) {
        MultiplayerBattle mpB = (MultiplayerBattle) battle;
        if (message.toLowerCase().startsWith("!run") || (message.toLowerCase().startsWith("!switch")
                && message.length() >= 8 && Character.isDigit(message.charAt(7)))
                || Move.isValidMove(message)) {
            if (sender.getNick().equalsIgnoreCase(mpB.getPlayer1())) {
                try {
                    mpB.p1msg.put(message);
                } catch (Exception ex) {
                }
            }
            if (sender.getNick().equalsIgnoreCase(mpB.getPlayer2())) {
                try {
                    mpB.p2msg.put(message);
                } catch (Exception ex) {
                }
            }
        }
        if (message.toLowerCase().startsWith("!list")) {
            if (sender.getNick().equalsIgnoreCase(mpB.getPlayer1())) {
                try {
                    String pokemon = mpB.player1.getPokemonList();
                    this.sendMessage(channel.getChannelName(),
                            "/w " + sender.getNick() + " Your pokemon are: " + pokemon);
                } catch (Exception ex) {
                    this.sendMessage(channel.getChannelName(),
                            "/w " + sender.getNick() + " You have no other Pokemon in your party!");
                }
            } else if (sender.getNick().equalsIgnoreCase(mpB.getPlayer2())) {
                try {
                    String pokemon = mpB.player2.getPokemonList();
                    this.sendMessage(channel.getChannelName(),
                            "/w " + sender.getNick() + " Your pokemon are: " + pokemon);
                } catch (Exception ex) {
                    this.sendMessage(channel.getChannelName(),
                            "/w " + sender.getNick() + " You have no other Pokemon in your party!");
                }
            }
            return;
        }
        if (message.toLowerCase().startsWith("!check") && message.length() >= 7
                && Character.isDigit(message.charAt(6))) {
            int check = Integer.parseInt(message.charAt(6) + "");
            if (sender.getNick().equalsIgnoreCase(mpB.getPlayer1())) {
                Pokemon p = mpB.player1.getPokemon(check);
                this.sendMessage(channel.getChannelName(),
                        "/w " + sender.getNick() + " Status of " + p.getName() + " (" + p.getType1()
                                + ((p.getType2() != Type.NONE) ? "/" + p.getType2() : "") + "): "
                                + p.getStat(Stats.HP) + " out of " + p.getMaxHP() + "hp left. Has these moves: "
                                + p.getMove1().getName() + ", " + p.getMove2().getName() + ", "
                                + p.getMove3().getName() + ", " + p.getMove4().getName());
            } else if (sender.getNick().equalsIgnoreCase(mpB.getPlayer2())) {
                Pokemon p = mpB.player2.getPokemon(check);
                this.sendMessage(channel.getChannelName(),
                        "/w " + sender.getNick() + " Status of " + p.getName() + " (" + p.getType1()
                                + ((p.getType2() != Type.NONE) ? "/" + p.getType2() : "") + "): "
                                + p.getStat(Stats.HP) + " out of " + p.getMaxHP() + "hp left. Has these moves: "
                                + p.getMove1().getName() + ", " + p.getMove2().getName() + ", "
                                + p.getMove3().getName() + ", " + p.getMove4().getName());
            }
        }
        if (message.toLowerCase().startsWith("!help") && (isInBattle() && battle instanceof MultiplayerBattle)
                && (sender.getNick().equalsIgnoreCase(mpB.getPlayer1())
                        || sender.getNick().equalsIgnoreCase(mpB.getPlayer2()))) {
            this.sendMessage(channel.getChannelName(), "/w " + sender.getNick()
                    + " Type !list to see a list of your Pokemon. Type !checkx where x is the number of the Pokemon from !list to see it's moves. Type !switchx where x is number of the Pokemon from !list to switch to a Pokemon.");
        }
    }
    if (isInBattle() && battle instanceof PWTBattle) {
        PWTBattle mpB = (PWTBattle) battle;
        if (message.toLowerCase().startsWith("!run") || (message.toLowerCase().startsWith("!switch")
                && message.length() >= 8 && Character.isDigit(message.charAt(7)))
                || Move.isValidMove(message)) {
            if (sender.getNick().equalsIgnoreCase(mpB.player1.getTrainerName())) {
                try {
                    mpB.p1msg.put(message);
                } catch (Exception ex) {
                }
            }
            if (sender.getNick().equalsIgnoreCase(mpB.player2.getTrainerName())) {
                try {
                    mpB.p2msg.put(message);
                } catch (Exception ex) {
                }
            }
        }
        if (message.toLowerCase().startsWith("!list")) {
            if (sender.getNick().equalsIgnoreCase(mpB.player1.getTrainerName())) {
                try {
                    String pokemon = mpB.player1.getPokemonList();
                    this.sendMessage(channel.getChannelName(),
                            "/w " + sender.getNick() + " Your pokemon are: " + pokemon);
                } catch (Exception ex) {
                    this.sendMessage(channel.getChannelName(),
                            "/w " + sender.getNick() + " You have no other Pokemon in your party!");
                }
            } else if (sender.getNick().equalsIgnoreCase(mpB.player2.getTrainerName())) {
                try {
                    String pokemon = mpB.player2.getPokemonList();
                    this.sendMessage(channel.getChannelName(),
                            "/w " + sender.getNick() + " Your pokemon are: " + pokemon);
                } catch (Exception ex) {
                    this.sendMessage(channel.getChannelName(),
                            "/w " + sender.getNick() + " You have no other Pokemon in your party!");
                }
            }
            return;
        }
        if (message.toLowerCase().startsWith("!check") && message.length() >= 7
                && Character.isDigit(message.charAt(6))) {
            int check = Integer.parseInt(message.charAt(6) + "");
            if (sender.getNick().equalsIgnoreCase(mpB.player1.getTrainerName())) {
                Pokemon p = mpB.player1.getPokemon(check);
                this.sendMessage(channel.getChannelName(),
                        "/w " + sender.getNick() + " Status of " + p.getName() + " (" + p.getType1()
                                + ((p.getType2() != Type.NONE) ? "/" + p.getType2() : "") + "): "
                                + p.getStat(Stats.HP) + " out of " + p.getMaxHP() + "hp left. Has these moves: "
                                + p.getMove1().getName() + ", " + p.getMove2().getName() + ", "
                                + p.getMove3().getName() + ", " + p.getMove4().getName());
            } else if (sender.getNick().equalsIgnoreCase(mpB.player2.getTrainerName())) {
                Pokemon p = mpB.player2.getPokemon(check);
                this.sendMessage(channel.getChannelName(),
                        "/w " + sender.getNick() + " Status of " + p.getName() + " (" + p.getType1()
                                + ((p.getType2() != Type.NONE) ? "/" + p.getType2() : "") + "): "
                                + p.getStat(Stats.HP) + " out of " + p.getMaxHP() + "hp left. Has these moves: "
                                + p.getMove1().getName() + ", " + p.getMove2().getName() + ", "
                                + p.getMove3().getName() + ", " + p.getMove4().getName());
            }
        }
        if (message.toLowerCase().startsWith("!help") && (isInBattle() && battle instanceof PWTBattle)
                && (sender.getNick().equalsIgnoreCase(mpB.player1.getTrainerName()))
                || sender.getNick().equalsIgnoreCase(mpB.player2.getTrainerName())) {
            this.sendMessage(channel.getChannelName(), "/w " + sender.getNick()
                    + " Type !list to see a list of your Pokemon. Type !checkx where x is the number of the Pokemon from !list to see it's moves. Type !switchx where x is number of the Pokemon from !list to switch to a Pokemon.");
        }
    }
    if (isInBattle() && battle instanceof SafariBattle) {
        SafariBattle sB = (SafariBattle) battle;
        if (sender.getNick().equalsIgnoreCase(sB.user.getTrainerName())) {
            if (message.toLowerCase().startsWith("!rock") || message.toLowerCase().startsWith("!bait")
                    || message.toLowerCase().startsWith("!ball") || message.toLowerCase().startsWith("!run")) {
                if (this.getOutgoingQueueSize() == 0) {
                    sB.msg.add(message.split(" ", 2)[0].toLowerCase());
                }
            }
        }
    }
    if (!isInBattle() && !waitingPlayer && !waitingPWT) {
        if (message.startsWith("!safari")) {
            Thread t = new Thread(() -> {
                int level = new SecureRandom().nextInt(100 - 20 + 1) + 20;
                int id = new SecureRandom().nextInt(718 - 1 + 1) + 1;
                System.err.println("Attempting Pokemon ID " + id + " level " + level);
                SafariBattle sB = new SafariBattle(this, sender.getNick(), new Pokemon(id, level));
                battle = sB;
                sB.doBattle(this, channel.getChannelName());
                System.err.println("Now out of Safari Battle");
                battle = null;
            });
            t.start();
        }
    }
    if (!isInBattle() && !waitingPlayer && !waitingPWT) {
        if (message.startsWith("!pwt")) {
            this.sendMessage(channel, sender.getNick()
                    + " has started a new Random Pokemon World Tournament! Type !join to join. The PWT will start in 60 seconds.");
            //this.sendMessage(channel,"Debug mode for PWT activated, wait 60 sec");
            pwtQueue.add(sender.getNick().toLowerCase());
            music.play(new File(ROOT_PATH + "\\pwt\\pwt-lobby.mp3"));
            waitingPWT = true;
            Thread t = new Thread(() -> {
                try {
                    ArrayList<Trainer> randoms = new ArrayList<>();
                    Thread tet = new Thread(() -> {
                        outer: while (waitingPWT) {
                            Trainer rand = PWTournament.generateTrainer(PWTType.RANDOM, PWTClass.NORMAL);
                            if (randoms.isEmpty()) {
                                randoms.add(rand);
                                System.err.println("Added " + rand + " " + rand.getPokemon());
                                continue;
                            }
                            for (Trainer el : randoms) {
                                if (el.getTrainerName().equalsIgnoreCase(rand.getTrainerName())) {
                                    continue outer;
                                }
                            }
                            randoms.add(rand);
                            System.err.println("Added " + rand + " " + rand.getPokemon());
                        }
                    });
                    tet.start();
                    Thread.sleep(60000);
                    //                        while (randoms.size() < 7) {
                    //                            outer:
                    //                            while (waitingPWT) {
                    //                                Trainer rand = PWTournament.generateTrainer(PWTType.RANDOM, PWTClass.NORMAL);
                    //                                if (randoms.isEmpty()) {
                    //                                    randoms.add(rand);
                    //                                    System.err.println("Added " + rand + " " + rand.getPokemon());
                    //                                    continue;
                    //                                }
                    //                                for (Trainer el : randoms) {
                    //                                    if (el.getTrainerName().equalsIgnoreCase(rand.getTrainerName())) {
                    //                                        continue outer;
                    //                                    }
                    //                                }
                    //                                randoms.add(rand);
                    //                                System.err.println("Added " + rand + " " + rand.getPokemon());
                    //                            }
                    //                        }
                    waitingPWT = false;
                    inPWT = true;
                    this.sendMessage(channel, "The " + PWTType.RANDOM
                            + " Pokemon World Tournament is starting! Stand by while I generate Pokemon... the first match will begin soon!");
                    ArrayList<Trainer> pwtList = new ArrayList<>();
                    for (String el : pwtQueue) {
                        ArrayList<Pokemon> p = Trainer.generatePokemon(3, 50);
                        Trainer te = new Trainer(el, Trainer.getTrainerClass(el), Region.getRandomRegion(), p,
                                false);
                        pwtList.add(te);
                    }
                    Collections.shuffle(pwtList);
                    PWTournament pwt = new PWTournament(PWTType.RANDOM, PWTClass.NORMAL, pwtList, randoms);
                    pwt.arrangeBracket();
                    pwt.doTourney(this, channel.getChannelName());
                    pwtQueue = new ArrayList<>();
                    waitingPWT = false;
                    inPWT = false;
                } catch (Exception ex) {
                    StringWriter sw = new StringWriter();
                    PrintWriter pw = new PrintWriter(sw);
                    ex.printStackTrace(pw);
                    music.sendMessage(music.getChannel(), music.CHEF.mention()
                            + " ```An error occurred in the PWT!!\n" + sw.toString() + "```");
                    pwtQueue = new ArrayList<>();
                    waitingPWT = false;
                    inPWT = false;
                }
            });
            t.start();
        }
    }
    if (!isInBattle() && waitingPWT) {
        if (message.toLowerCase().startsWith("!join") && pwtQueue.size() < 4) {
            if (!pwtQueue.contains(sender.getNick().toLowerCase())) {
                pwtQueue.add(sender.getNick().toLowerCase());
                this.sendMessage(channel, sender.getNick() + " has been added to the PWT! Type !join to join.");
                return;
            }
        }
    }
    if (message.toLowerCase().startsWith("!help") && !isInBattle()) {
        this.sendMessage(channel.getChannelName(),
                "https://github.com/robomaeyhem/WowBattleBot (scroll down to see the Readme)");
    }
    if (message.toLowerCase().startsWith("!randbat @") || message.toLowerCase().startsWith("!randombattle @")) {
        if (isInBattle() || waitingPlayer || waitingPWT) {
            return;
        }
        //if ((message.toLowerCase().startsWith("!challenge @") || message.toLowerCase().startsWith("!multibattle @")) && !inMultiBattle && !inPokemonBattle && !inSafariBattle) {
        final String messageFinal = message;
        Thread t = new Thread(() -> {
            try {
                String target = messageFinal.split("@", 2)[1].split(" ", 2)[0];
                if (target.isEmpty() || target.contains("/") || target.contains(".")) {
                    this.sendMessage(channel, "FUNgineer");
                    return;
                }
                int pkmAmt = 1;
                try {
                    pkmAmt = Integer.parseInt(messageFinal.split("@", 2)[1].split(" ", 2)[1].split(" ", 2)[0]);
                } catch (Exception ex2) {
                    pkmAmt = 1;
                }
                if (pkmAmt < 1) {
                    pkmAmt = 1;
                }
                if (pkmAmt > 6) {
                    pkmAmt = 6;
                }
                if (target.equalsIgnoreCase(sender.getNick())) {
                    this.sendMessage(channel.getChannelName(), "You cannot challenge yourself FUNgineer");
                    return;
                }
                if (target.equalsIgnoreCase("frunky5") || target.equalsIgnoreCase("23forces")
                        || target.equalsIgnoreCase("groudonger")) {

                } else if (target.equalsIgnoreCase("wow_deku_onehand")
                        || target.equalsIgnoreCase("wow_battlebot_onehand") || User.isBot(target)
                        || target.equalsIgnoreCase("killermapper")) {
                    this.sendMessage(channel.getChannelName(), "FUNgineer");
                    return;
                }
                if (!waitingPlayer) {
                    waitingPlayer = true;
                    waitingOn = target;
                    this.sendMessage(channel.getChannelName(), "Challenging " + target + "...");
                    int level = new SecureRandom().nextInt(100 - 20 + 1) + 20;
                    while (level < 20) {
                        level = new SecureRandom().nextInt(100 - 20 + 1) + 20;
                    }
                    boolean isHere = false;
                    for (User el : this.getUsers(channel.getChannelName())) {
                        if (target.equalsIgnoreCase(el.getNick())) {
                            isHere = true;
                            break;
                        }
                    }
                    if (!isHere) {
                        append(sender.getNick() + " SENDING INVITE");
                        BattleBot.sendAnInvite(target, "_keredau_1423645868201", oAuth);
                    }
                    this.sendWhisper(target, "You have been challenged to a Pokemon Battle by "
                            + sender.getNick()
                            + "! To accept, go to the Battle Dungeon and type !accept. You have one minute.");
                    String player2 = player.poll(60, TimeUnit.SECONDS);
                    if (player2 == null) {
                        this.sendMessage(channel.getChannelName(),
                                target + " did not respond to the challenge BibleThump");
                        waitingPlayer = false;
                        waitingOn = "";
                        return;
                    }
                    waitingPlayer = false;
                    waitingOn = "";
                    this.sendMessage(channel.getChannelName(), "Generating Pokemon, give me a minute...");
                    System.err.println("Going into Multiplayer Battle");
                    MultiplayerBattle mpB = new MultiplayerBattle(this, sender.getNick(), target, level,
                            pkmAmt);
                    battle = mpB;
                    mpB.doBattle(channel.getChannelName());
                    battle = null;
                    System.err.println("Now out of Multiplayer Battle");
                }
            } catch (Exception ex) {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                ex.printStackTrace(pw);
                music.sendMessage(music.getChannel(), music.CHEF.mention() + " ```" + sw.toString() + "\n```");
                waitingPlayer = false;
                battle = null;
            }
        });
        t.start();

    }
    if (message.toLowerCase().startsWith("!test ") && sender.getNick().equalsIgnoreCase("the_chef1337")) {
        String test = message.toLowerCase().split("!test ", 2)[1].split(" ", 2)[0];
        if (!test.equalsIgnoreCase("pwt") && !Character.isDigit(message.charAt(6))) {
            final String senderFinal = "the_chef1337";
            Thread t = new Thread(() -> {
                try {
                    pokemonMessages = new LinkedBlockingQueue<>();
                    personInBattle = senderFinal;
                    System.err.println("Going into Pokemon Battle");
                    PokemonBattle a = new PokemonBattle(this, channel.getChannelName(), false, false,
                            sender.getNick(), true);
                    System.err.println("Now out of Pokemon Battle");
                    pokemonMessages = new LinkedBlockingQueue<>();
                    personInBattle = "";
                    battle = null;
                } catch (Exception ex) {
                    personInBattle = "";
                    pokemonMessages = new LinkedBlockingQueue<>();
                    this.sendMessage(channel.getChannelName(),
                            "Something fucked up OneHand this battle is now over both Pokemon exploded violently KAPOW");
                    System.err.println("[POKEMON] Uh oh " + ex);
                    ex.printStackTrace();
                    StringWriter sw = new StringWriter();
                    PrintWriter pw = new PrintWriter(sw);
                    ex.printStackTrace(pw);
                    music.sendMessage(music.getChannel(),
                            music.CHEF.mention() + " ```" + sw.toString() + "```");
                    battle = null;
                }
            });
            t.start();
        } else if (message.toLowerCase().split("!test ", 2)[1].split(" ", 2)[0].equalsIgnoreCase("pwt")) {
            Trainer t = new Trainer("Cynthia", "Sinnoh Champion", Region.SINNOH, Trainer.generatePokemon(3, 50),
                    true);
            Trainer m = new Trainer("23forces", "Elite Four", Region.getRandomRegion(),
                    Trainer.generatePokemon(3, 50), true);
            //String name, String trnClass, Region region, ArrayList<Pokemon> pokemon, boolean ai
            this.sendMessage(channel, PWTRound.FIRST_ROUND.getText() + "match of the " + PWTType.RANDOM
                    + " tournament! This match is between " + t + " and " + m + "!");
            PWTBattle b = new PWTBattle(this, m, t, PWTType.RANDOM, PWTClass.NORMAL, PWTRound.FIRST_ROUND);
            battle = b;
            Thread th = new Thread(() -> {
                try {
                    this.music.play(PWTBattle.determineMusic(b));
                    b.doBattle(channel.getChannelName());
                    battle = null;
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            });
            th.start();
        } else {
            final int finalId = Integer.parseInt(message.split("!test ", 2)[1].split(" ", 2)[0]);
            Thread t = new Thread(() -> {
                int level = new SecureRandom().nextInt(100 - 20 + 1) + 20;
                int id = finalId;
                System.err.println("Attempting Pokemon ID " + id + " level " + level);
                SafariBattle sB = new SafariBattle(this, sender.getNick(), new Pokemon(id, level));
                battle = sB;
                sB.doBattle(this, channel.getChannelName());
                System.err.println("Now out of Safari Battle");
                battle = null;
            });
            t.start();
        }
    }
    if (message.toLowerCase().startsWith("!battle") && !waitingPlayer && !waitingPWT && !isInBattle()) {
        boolean bigbrother = false, fromChef = false;
        if (message.contains("BigBrother") || sender.getNick().equalsIgnoreCase("dewgong98")
                || sender.getNick().equalsIgnoreCase("mad_king98")
                || sender.getNick().equalsIgnoreCase("Starmiewaifu")) {
            bigbrother = true;
            if (sender.getNick().equalsIgnoreCase("the_chef1337")) {
                fromChef = true;
            }
        }
        final boolean bbrother = bigbrother;
        final boolean fChef = fromChef;
        if (sender.getNick().equalsIgnoreCase("twitchplaysleaderboard")) {
            return;
        } else {
            final String senderFinal = sender.getNick();
            if (!isInBattle() && !waitingPlayer && !waitingPWT) {
                Thread t = new Thread(() -> {
                    try {
                        pokemonMessages = new LinkedBlockingQueue<>();
                        personInBattle = senderFinal;
                        System.err.println("Going into Pokemon Battle");
                        PokemonBattle a = new PokemonBattle(this, channel.getChannelName(), bbrother, fChef,
                                sender.getNick(), false);
                        System.err.println("Now out of Pokemon Battle");
                        pokemonMessages = new LinkedBlockingQueue<>();
                        personInBattle = "";
                        battle = null;
                    } catch (Exception ex) {
                        personInBattle = "";
                        pokemonMessages = new LinkedBlockingQueue<>();
                        this.sendMessage(channel.getChannelName(),
                                "Something fucked up OneHand this battle is now over both Pokemon exploded violently KAPOW");
                        System.err.println("[POKEMON] Uh oh " + ex);
                        ex.printStackTrace();
                        StringWriter sw = new StringWriter();
                        PrintWriter pw = new PrintWriter(sw);
                        ex.printStackTrace(pw);
                        music.sendMessage(music.getChannel(),
                                music.CHEF.mention() + " ```" + sw.toString() + "```");
                        battle = null;
                    }
                });
                t.start();
            }
        }
    }
    if (message.toLowerCase().startsWith("!run")) {
        if (!channel.getChannelName().equals("#_keredau_1423645868201")) {
            return;
        }
        if (isInBattle() && battle instanceof PokemonBattle) {
            if (sender.getNick().equalsIgnoreCase(personInBattle)) {
                //                    if (DekuBot.containsOtherChar(message)) {
                //                        this.sendMessage(channel.getChannelName(), sender + "... TriHard");
                //                        return;
                //                    }
                personInBattle = "";
                pokemonMessages.add("run");
            }
        }
    }

    if (message.toLowerCase().startsWith("!move1") || message.toLowerCase().startsWith("!move2")
            || message.toLowerCase().startsWith("!move3") || message.toLowerCase().startsWith("!move4")) {
        if (sender.getNick().equalsIgnoreCase("wow_deku_onehand")) {
            return;
        }
        if (!channel.getChannelName().equals("#_keredau_1423645868201")) {
            return;
        }
        if (isInBattle() && battle instanceof PokemonBattle) {
            if (sender.getNick().equalsIgnoreCase(personInBattle)) {
                pokemonMessages.add("" + message.charAt(5));
            }
        }
    }
}

From source file:com.aiblockchain.api.StringUtils.java

/**
 * Returns the given string after removing any numeric suffix.
 *
 * @param string the given string//from  w ww  .  ja  v a2s  .  c  o m
 *
 * @return the given string after removing any numeric suffix
 */
public static String stripNumericSuffix(final String string) {
    //Preconditions
    assert string != null : "string must not be null";

    if (string.isEmpty()) {
        return string;
    }
    int index = string.length() - 1;
    while (index >= 0) {
        if (Character.isDigit(string.charAt(index))) {
            index--;
        } else {
            break;
        }
    }
    return string.substring(0, index + 1);
}

From source file:cerrla.Performance.java

/**
 * Reads a raw numerical performance file and stores the values as
 * accessible private values.//w ww  . j  a  v  a2  s .com
 * 
 * @param perfFile
 *            The performance file to read.
 * @return True if the file was read successfully, false otherwise.
 */
public static boolean readRawPerformanceFile(File perfFile, boolean byEpisode) throws Exception {
    if (Config.getInstance().getGeneratorFile() == null) {
        // First, read the last line of the normal file for the time
        RandomAccessFile raf = new RandomAccessFile(perfFile, "r");
        long pos = perfFile.length() - 1;
        StringBuffer line = new StringBuffer();
        char c;
        boolean foundIt = false;
        do {
            raf.seek(pos);
            c = (char) raf.read();
            foundIt |= Character.isDigit(c);
            line.append(c);
            pos--;
        } while (!foundIt || Character.isDigit(c) || c == ':');
        raf.close();
        String time = line.reverse().toString().trim();
        String[] timeSplit = time.split(":");
        runTime_ = (Long.parseLong(timeSplit[2]) + 60 * Long.parseLong(timeSplit[1])
                + 3600 * Long.parseLong(timeSplit[0])) * 1000;
    }

    if (Config.getInstance().getGeneratorFile() == null)
        perfFile = new File(perfFile.getPath() + "raw");
    else
        perfFile = new File(perfFile.getPath() + "greedy");
    performanceMap_ = new TreeMap<Integer, Float[]>();
    FileReader reader = new FileReader(perfFile);
    BufferedReader buf = new BufferedReader(reader);

    // For every value within the performance file
    String input = null;
    Float[] prevPerfs = null;
    while ((input = buf.readLine()) != null) {
        String[] vals = input.split("\t");
        if (vals[PerformanceDetails.EPISODE.ordinal()].equals("Episode"))
            continue;

        Float[] perfs = new Float[PerformanceDetails.values().length];
        int episode = 0;
        for (PerformanceDetails detail : PerformanceDetails.values()) {
            if (vals.length > detail.ordinal()) {
                if (!vals[detail.ordinal()].equals("null"))
                    perfs[detail.ordinal()] = Float.parseFloat(vals[detail.ordinal()]);
                else if (detail.equals(PerformanceDetails.ELITEMEAN)
                        && !vals[PerformanceDetails.ELITEMAX.ordinal()].equals("null"))
                    perfs[detail.ordinal()] = Float.parseFloat(vals[PerformanceDetails.ELITEMAX.ordinal()]);
                else if (detail.equals(PerformanceDetails.ELITEMEAN)
                        || detail.equals(PerformanceDetails.ELITEMAX))
                    perfs[detail.ordinal()] = Float.parseFloat(vals[PerformanceDetails.MEAN.ordinal()]);
                else if (prevPerfs != null)
                    perfs[detail.ordinal()] = prevPerfs[detail.ordinal()];
            }

            if (detail.equals(PerformanceDetails.EPISODE))
                episode = perfs[detail.ordinal()].intValue();
        }

        performanceMap_.put(episode, perfs);
        prevPerfs = perfs;
    }

    buf.close();
    reader.close();

    return true;
}

From source file:com.dgtlrepublic.anitomyj.ParserNumber.java

/**
 * Searches for episode patterns in a list of {@code tokens}.
 *
 * @param tokens the list of tokens/*from  w ww .  j  av  a2 s.c om*/
 * @return true if an episode number was found
 */
public boolean searchForEpisodePatterns(List<Result> tokens) {
    for (Result it : tokens) {
        boolean numericFront = it.token.getContent().length() > 0
                && Character.isDigit(it.token.getContent().charAt(0));

        if (!numericFront) {
            // e.g. "EP.1", "Vol.1"
            if (numberComesAfterPrefix(kElementEpisodePrefix, it.token))
                return true;
            if (numberComesAfterPrefix(kElementVolumePrefix, it.token))
                continue;
        } else {
            // e.g. "8 of 12"
            if (numberComesBeforeTotalNumber(it.token, it.pos))
                return true;
        }

        // Look for other patterns
        if (matchEpisodePatterns(it.token.getContent(), it.token)) {
            return true;
        }
    }

    return false;
}

From source file:org.eclipse.swt.examples.layoutexample.FormLayoutTab.java

/**
 * Sets an attachment to the edge of a widget using the
 * information in the table.//from w  w  w .  jav a  2 s.c  o  m
 */
FormAttachment setAttachment(String attachment) {
    String control, align;
    int position, offset;
    int comma = attachment.indexOf(',');
    char first = attachment.charAt(0);
    if (Character.isLetter(first)) {
        /* Case where there is a control */
        control = attachment.substring(0, comma);
        int i = 0;
        while (i < control.length() && !Character.isDigit(control.charAt(i))) {
            i++;
        }
        String end = control.substring(i);
        int index = Integer.valueOf(end).intValue();
        Control attachControl = children[index];
        int colon = attachment.indexOf(':');
        try {
            offset = Integer.valueOf(attachment.substring(comma + 1, colon)).intValue();
        } catch (NumberFormatException e) {
            offset = 0;
        }
        align = attachment.substring(colon + 1);
        return new FormAttachment(attachControl, offset, alignmentConstant(align));
    } else {
        /* Case where there is a position */
        try {
            position = Integer.valueOf(attachment.substring(0, comma));
        } catch (NumberFormatException e) {
            position = 0;
        }
        try {
            offset = Integer.valueOf(attachment.substring(comma + 1));
        } catch (NumberFormatException e) {
            offset = 0;
        }
        return new FormAttachment(position, offset);
    }
}