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:egovframework.rte.fdl.string.EgovStringUtil.java

/**
 * <p>/*from  w  w  w .  j  a  va  2s  .c o  m*/
 * Checks if the String contains only unicode
 * letters or digits.
 * </p>
 * <p>
 * <code>null</code> will return <code>false</code>
 * . An empty String ("") will return
 * <code>false</code>.
 * </p>
 * 
 * <pre>
 * StringUtil.isAlphaNumeric(null)             = false
 * StringUtil.isAlphaNumeric(&quot;&quot;)     = false
 * StringUtil.isAlphaNumeric(&quot;  &quot;)   = false
 * StringUtil.isAlphaNumeric(&quot;abc&quot;)  = true
 * StringUtil.isAlphaNumeric(&quot;ab c&quot;) = false
 * StringUtil.isAlphaNumeric(&quot;ab2c&quot;) = true
 * StringUtil.isAlphaNumeric(&quot;ab-c&quot;) = false
 * </pre>
 * @param str
 *        the String to check, may be null
 * @return <code>true</code> if only contains
 *         letters or digits, and is non-null
 *         public static boolean
 *         isAlphaNumeric(String str) { if (str ==
 *         null) { return false; } int sz =
 *         str.length(); if (sz == 0) return false;
 *         for (int i = 0; i < sz; i++) { if
 *         (!Character
 *         .isLetterOrDigit(str.charAt(i))) {
 *         return false; } } return true; } /**
 *         <p>
 *         Checks if the String contains only
 *         unicode letters.
 *         </p>
 *         <p>
 *         <code>null</code> will return
 *         <code>false</code>. An empty String ("")
 *         will return <code>false</code>.
 *         </p>
 * 
 *         <pre>
 * StringUtil.isAlpha(null)            = false
 * StringUtil.isAlpha(&quot;&quot;)     = false
 * StringUtil.isAlpha(&quot;  &quot;)   = false
 * StringUtil.isAlpha(&quot;abc&quot;)  = true
 * StringUtil.isAlpha(&quot;ab2c&quot;) = false
 * StringUtil.isAlpha(&quot;ab-c&quot;) = false
 * </pre>
 * @param str
 *        the String to check, may be null
 * @return <code>true</code> if only contains
 *         letters, and is non-null public static
 *         boolean isAlpha(String str) { if (str ==
 *         null) { return false; } int sz =
 *         str.length(); if (sz == 0) return false;
 *         for (int i = 0; i < sz; i++) { if
 *         (!Character.isLetter(str.charAt(i))) {
 *         return false; } } return true; } /**
 *         <p>
 *         Checks if the String contains only
 *         unicode digits. A decimal point is not a
 *         unicode digit and returns false.
 *         </p>
 *         <p>
 *         <code>null</code> will return
 *         <code>false</code>. An empty String ("")
 *         will return <code>false</code>.
 *         </p>
 * 
 *         <pre>
 * StringUtil.isNumeric(null)            = false
 * StringUtil.isNumeric(&quot;&quot;)     = false
 * StringUtil.isNumeric(&quot;  &quot;)   = false
 * StringUtil.isNumeric(&quot;123&quot;)  = true
 * StringUtil.isNumeric(&quot;12 3&quot;) = false
 * StringUtil.isNumeric(&quot;ab2c&quot;) = false
 * StringUtil.isNumeric(&quot;12-3&quot;) = false
 * StringUtil.isNumeric(&quot;12.3&quot;) = false
 * </pre>
 * @param str
 *        the String to check, may be null
 * @return <code>true</code> if only contains
 *         digits, and is non-null
 */
public static boolean isNumeric(String str) {
    if (str == null) {
        return false;
    }
    int sz = str.length();
    if (sz == 0)
        return false;
    for (int i = 0; i < sz; i++) {
        if (!Character.isDigit(str.charAt(i))) {
            return false;
        }
    }
    return true;
}

From source file:de.tudarmstadt.ukp.clarin.webanno.crowdflower.NamedEntityTaskManager.java

/**
 * Helper function that retrieves the first token number in a task1 html span
 * @param spans//from w  ww.  j  ava2s  .  c o m
 * @return first number in span offset string
 */
private int getFirstSpanOffset(String spans) {
    String firstNum = "0";
    boolean foundDigit = false;

    // span beginn will look like: "<span id='token=num'>", so will just search the first number
    // in the string

    /*
     * regex for this would be:
     * Pattern p = Pattern.compile("(^|\\s)([0-9]+)($|\\s)");
     * Matcher m = p.matcher(s);
     * if (m.find()) { String num = m.group(2); }
     */

    // but hey, extractSpan gets called a lot, this is faster:

    for (int i = 0; i < spans.length(); i++) {
        if (Character.isDigit(spans.charAt(i))) {
            foundDigit = true;
            firstNum = firstNum + Character.toString(spans.charAt(i));
        } else if (foundDigit && !Character.isDigit(spans.charAt(i))) {
            break;
        }
    }

    int offset = Integer.valueOf(firstNum);
    return offset;
}

From source file:Game.Engine.java

@Override
public void invalidated(Observable observable) {
    if (observable instanceof InteractionCase) {
        InteractionCase invalidated = (InteractionCase) observable;
        // Check interaction-flow! interaction closes, it gets notified. 
        JSONObject finishbehaviour = invalidated.getFinishBehaviour();

        ArrayList<Card> selectedCardsFromThisInteractionCase = invalidated.getSelected();
        ArrayList<String> selectedIdentifiersFromThisInteractionCase = invalidated.getIds();
        ArrayList<String> selectedCardNamesFromThisInteractionCase = new ArrayList<>();

        for (int index = 0; index < selectedIdentifiersFromThisInteractionCase.size(); index++) {
            String thisIdentifier = selectedIdentifiersFromThisInteractionCase.get(index);
            // Check if the identifier's first character is a digit.
            // If this is the case, it means the identifier is long-parseable
            // If the identifier is a long, it comes out of the hand of the victim.
            // Identifiers from victims hands get "other" notitifier in front. 
            if (Character.isDigit(thisIdentifier.charAt(0))) {
                selectedIdentifiersFromThisInteractionCase.remove(index);
                selectedIdentifiersFromThisInteractionCase.add(index, "other_" + thisIdentifier);
            }//from   www .j a v  a2  s . com
            Card linkedToThisIdentifier = selectedCardsFromThisInteractionCase.get(index);
            selectedCardNamesFromThisInteractionCase.add(linkedToThisIdentifier.name);

        }

        // Handle behaviour: 

        JSONObject handlebehaviour = invalidated.getFinishBehaviour();

        if (handlebehaviour.getString("showToInitiator").equals(((Boolean) true).toString())) {
            if (invalidated.getInitiator().getFutureInteraction() == null) {
                System.out.println(
                        "---> Tried to show interactionresult to initiator, but his futureInteraction == null");
            } else {
                // Switch victim and initiator positions in indexFor function, since we are swicthing roles in the interaction.
                System.out.println("---> showing interactinoresult to initiator, containing "
                        + selectedCardNamesFromThisInteractionCase.size() + " entries with ids:");
                ArrayList<String> copy_for_injection = new ArrayList<>();
                for (String s : selectedIdentifiersFromThisInteractionCase)
                    copy_for_injection
                            .add(s + "_" + myIndexFor(invalidated.getVictim(), invalidated.getInitiator()));
                selectedIdentifiersFromThisInteractionCase = copy_for_injection;
                for (String s : selectedIdentifiersFromThisInteractionCase)
                    System.out.println(s);
                invalidated.getInitiator().getFutureInteraction()
                        .setStartBehaviour(JSONUtilities.JSON.update_client_confirmation_model(
                                myIndexFor(invalidated.getVictim(), invalidated.getInitiator()),
                                JSONUtilities.JSON.make_player_public_stats(invalidated.getVictim(),
                                        server.getClient(invalidated.getVictim().getSession()).getNickname(),
                                        copy_for_injection, selectedCardNamesFromThisInteractionCase,
                                        (selectedCardNamesFromThisInteractionCase.isEmpty())),
                                invalidated.getInitiator().getFutureInteraction().getStartBehaviour()));
                for (int ix = 0; ix < invalidated.selectedSpecials.size(); ix++) {
                    Card c = invalidated.selectedSpecials.get(ix);
                    String id = copy_for_injection.get(ix) + "_" + ix;
                    invalidated.getInitiator().getFutureInteraction().preloadedCards.add(c);
                    invalidated.getInitiator().getFutureInteraction().fromPreviousInteraction.put(id, c);
                }

            }
        }

        if (handlebehaviour.getString("moveSomething").equals(((Boolean) true).toString())) {
            String from = handlebehaviour.getString("pullFrom");
            String to = handlebehaviour.getString("addTo");
            String foreach = handlebehaviour.getString("iterative_action");

            System.out.println("handling a pull from " + from + " to " + to + " with foreach " + foreach);
            if (from.equals("hand_victim") && to.equals("top_of_deck_victim")) {
                for (int ix = 0; ix < selectedIdentifiersFromThisInteractionCase.size(); ix++) {
                    System.out.println("Identifier is " + selectedIdentifiersFromThisInteractionCase.get(ix));
                    if (selectedIdentifiersFromThisInteractionCase.get(ix).startsWith("other")) {
                        Long victimCardID = Long
                                .parseLong(selectedIdentifiersFromThisInteractionCase.get(ix).split("_")[1]);
                        Card lost = invalidated.getVictim()
                                .loseCard(selectedCardNamesFromThisInteractionCase.get(ix), victimCardID);
                        invalidated.getVictim().deck.addTopOfDeck(lost);
                        server.sendOne(
                                JSONUtilities.JSON.make_client_lose(lost.getName(), victimCardID.toString()),
                                invalidated.getVictim().getSession());
                        make_client_update_deck(invalidated.getVictim());
                        if (!foreach.equals("none")) {
                            System.out.println("uncatched foreach");
                        }
                    }
                }
            } else if (from.equals("none") && (to.equals("hand_victim"))) {
                for (int ix = 0; ix < selectedIdentifiersFromThisInteractionCase.size(); ix++) {
                    if (selectedIdentifiersFromThisInteractionCase.get(ix).startsWith("other")) {
                        Card thecard = selectedCardsFromThisInteractionCase.get(ix);
                        invalidated.getVictim().hand.add(thecard);

                        JSONObject obj = JSONUtilities.JSON.make_client_print(
                                "Adventurer gave you a : " + selectedCardNamesFromThisInteractionCase.get(ix));
                        server.getClient(invalidated.getVictim().getSession()).write(obj);

                        JSONObject act = JSONUtilities.JSON
                                .make_client_gain(selectedCardNamesFromThisInteractionCase.get(ix));
                        server.getClient(invalidated.getVictim().getSession()).write(act);
                        make_client_update_deck(invalidated.getVictim());
                        make_client_update_discardpile(invalidated.getVictim());
                    }
                }
            } else if (from.equals("hand_victim") && (to.equals("discardpile_victim"))) {
                for (int ix = 0; ix < selectedIdentifiersFromThisInteractionCase.size(); ix++) {
                    if (selectedIdentifiersFromThisInteractionCase.get(ix).startsWith("other")) {
                        System.out.println("Discarding from hand: id "
                                + selectedIdentifiersFromThisInteractionCase.get(ix));
                        Long victimCardID = Long
                                .parseLong(selectedIdentifiersFromThisInteractionCase.get(ix).split("_")[1]);
                        Card lost = invalidated.getVictim()
                                .loseCard(selectedCardNamesFromThisInteractionCase.get(ix), victimCardID);
                        invalidated.getVictim().deck.used.add(lost);
                        server.sendOne(
                                JSONUtilities.JSON.make_client_lose(lost.getName(), victimCardID.toString()),
                                invalidated.getVictim().getSession());
                        if (foreach.equals("draw_card")) {
                            // This is the cellar branch of this function
                            give_card_to_player_hand(invalidated.getVictim().getSession());

                        } else if (foreach.equals("none")) {
                            // This is the militia branch of this function
                            System.out.println("militiabranch taken");
                        }
                        make_client_update_deck(invalidated.getVictim());
                        make_client_update_discardpile(invalidated.getVictim());
                    }
                }
            } else if (from.equals("deck_victim") && (to.equals("discardpile_victim"))) {
                if (foreach.equals("until_deck_discarded")) {
                    // Its (probably) a chancellor deckdiscard!
                    if (selectedCardNamesFromThisInteractionCase.isEmpty()) {
                        // Do nothing! The chancellor was not selected, if it even is a chancellor.

                    } else {
                        if (selectedCardNamesFromThisInteractionCase.get(0).equals("chancellor")) {
                            invalidated.getVictim().deck.reshuffle();
                            make_client_update_deck(invalidated.getVictim());
                            make_client_update_discardpile(invalidated.getVictim());
                            server.sendAll(JSONUtilities.JSON
                                    .make_client_print(server.getNickname(invalidated.getVictim().getSession())
                                            + " reshuffeled his/her deck with a chancellor."));
                        } else {
                            System.out.println(
                                    "Non implemented branch of behaviour tree was reached, should not happen");
                        }
                    }
                }
            } else if (from.equals("hand_victim") && (to.equals("trashpile"))) {
                if (foreach.equals("none")) {
                    for (int ix = 0; ix < selectedIdentifiersFromThisInteractionCase.size(); ix++) {
                        if (selectedIdentifiersFromThisInteractionCase.get(ix).startsWith("other")) {
                            System.out.println(
                                    "Chappeling id " + selectedIdentifiersFromThisInteractionCase.get(ix));
                            Long victimCardID = Long.parseLong(
                                    selectedIdentifiersFromThisInteractionCase.get(ix).split("_")[1]);
                            Card lost = invalidated.getVictim()
                                    .loseCard(selectedCardNamesFromThisInteractionCase.get(ix), victimCardID);
                            env.trashpile.add(lost);
                            server.sendOne(JSONUtilities.JSON.make_client_lose(lost.getName(),
                                    victimCardID.toString()), invalidated.getVictim().getSession());
                            server.sendAll(JSONUtilities.JSON
                                    .make_client_print(server.getNickname(invalidated.getVictim().getSession())
                                            + " trashed a " + lost.getName()));
                        }
                    }
                    server.sendAll(JSONUtilities.JSON.make_client_update_environment("trashpile",
                            env.trashpile.size()));
                    server.sendAll(JSONUtilities.JSON
                            .make_client_update_trashpile(env.trashpile.get(env.trashpile.size() - 1)));
                } else if (foreach.equals("gain_treasure_costing_up_to_3_more")) {
                    // Its a mine
                    for (int ix = 0; ix < selectedIdentifiersFromThisInteractionCase.size(); ix++) {
                        if (selectedIdentifiersFromThisInteractionCase.get(ix).startsWith("other")) {
                            System.out.println(
                                    "Trashing id " + selectedIdentifiersFromThisInteractionCase.get(ix));
                            Long victimCardID = Long.parseLong(
                                    selectedIdentifiersFromThisInteractionCase.get(ix).split("_")[1]);
                            Card lost = invalidated.getVictim()
                                    .loseCard(selectedCardNamesFromThisInteractionCase.get(ix), victimCardID);
                            env.trashpile.add(lost);
                            ArrayList<String> identifiers = new ArrayList<>();
                            ArrayList<String> cardnames = new ArrayList<>();
                            for (Card c : env.getAllBuyablesAsCards(lost.getCost() + 3)) {
                                if (c instanceof TreasureCard) {
                                    invalidated.getVictim().getFutureInteraction().preloadedCards.add(c);
                                    invalidated.getVictim().getFutureInteraction().allowedIds
                                            .add("environment");
                                    invalidated.getVictim().getFutureInteraction().enableEnvTreasure();
                                }
                            }
                            invalidated.getVictim().getFutureInteraction()
                                    .setStartBehaviour(JSONUtilities.JSON.make_client_confirmation_model_mine(
                                            invalidated.getVictim(), invalidated.getInitiator(),
                                            invalidated.getVictim().getFutureInteraction()));
                            invalidated.getVictim().getFutureInteraction().setMaxCost(lost.getCost() + 3);
                            invalidated.getVictim().getFutureInteraction().setMinCost(0);
                            invalidated.getVictim().getFutureInteraction().setMinAmount(1);
                            invalidated.getVictim().getFutureInteraction().setMaxAmount(1);

                            //invalidated.getVictim().getFutureInteraction().setStartBehaviour(JSONUtilities.JSON.update_client_confirmation_model(0, JSONUtilities.JSON.make_player_public_stats( invalidated.getVictim(),server.getClient(invalidated.getVictim().getSession()).getNickname(), identifiers, cardnames, false), invalidated.getInitiator().getFutureInteraction().getStartBehaviour()));

                            server.sendOne(JSONUtilities.JSON.make_client_lose(lost.getName(),
                                    victimCardID.toString()), invalidated.getVictim().getSession());
                            server.sendAll(JSONUtilities.JSON
                                    .make_client_print(server.getNickname(invalidated.getVictim().getSession())
                                            + " trashed a " + lost.getName()));

                        }
                    }
                    server.sendAll(JSONUtilities.JSON.make_client_update_environment("trashpile",
                            env.trashpile.size()));
                    server.sendAll(JSONUtilities.JSON
                            .make_client_update_trashpile(env.trashpile.get(env.trashpile.size() - 1)));

                } else if (foreach.equals("gain3moneythisturn")) {
                    Long victimCardID = Long
                            .parseLong(selectedIdentifiersFromThisInteractionCase.get(0).split("_")[1]);
                    Card lost = invalidated.getVictim()
                            .loseCard(selectedCardNamesFromThisInteractionCase.get(0), victimCardID);
                    env.trashpile.add(lost);
                    this.money += 3;
                    server.sendOne(JSONUtilities.JSON.make_client_lose(lost.getName(), victimCardID.toString()),
                            invalidated.getVictim().getSession());
                    server.sendAll(JSONUtilities.JSON.make_client_update_environment("trashpile",
                            env.trashpile.size()));
                    server.sendAll(JSONUtilities.JSON
                            .make_client_update_trashpile(env.trashpile.get(env.trashpile.size() - 1)));
                    server.sendAll(JSONUtilities.JSON.make_client_turninfo(actions, purchases, money));
                    server.sendAll(JSONUtilities.JSON
                            .make_client_print(server.getNickname(invalidated.getVictim().getSession())
                                    + " trashed a " + lost.getName()));

                } else if (foreach.equals("gain_anything_costing_up_to_2_more")) {
                    // Its a remodel
                    for (int ix = 0; ix < selectedIdentifiersFromThisInteractionCase.size(); ix++) {
                        if (selectedIdentifiersFromThisInteractionCase.get(ix).startsWith("other")) {
                            System.out.println(
                                    "Trashing id " + selectedIdentifiersFromThisInteractionCase.get(ix));
                            Long victimCardID = Long.parseLong(
                                    selectedIdentifiersFromThisInteractionCase.get(ix).split("_")[1]);
                            Card lost = invalidated.getVictim()
                                    .loseCard(selectedCardNamesFromThisInteractionCase.get(ix), victimCardID);
                            env.trashpile.add(lost);
                            ArrayList<String> identifiers = new ArrayList<>();
                            ArrayList<String> cardnames = new ArrayList<>();
                            for (Card c : env.getAllBuyablesAsCards(lost.getCost() + 2)) {
                                invalidated.getVictim().getFutureInteraction().preloadedCards.add(c);
                                invalidated.getVictim().getFutureInteraction().allowedIds.add("environment");
                                invalidated.getVictim().getFutureInteraction().enable_environment();
                            }
                            invalidated.getVictim().getFutureInteraction().setStartBehaviour(
                                    JSONUtilities.JSON.make_client_confirmation_model_remodel(
                                            invalidated.getVictim(), invalidated.getInitiator(),
                                            invalidated.getVictim().getFutureInteraction()));
                            invalidated.getVictim().getFutureInteraction().setMaxCost(lost.getCost() + 2);
                            invalidated.getVictim().getFutureInteraction().setMinCost(0);
                            invalidated.getVictim().getFutureInteraction().setMinAmount(1);
                            invalidated.getVictim().getFutureInteraction().setMaxAmount(1);

                            //invalidated.getVictim().getFutureInteraction().setStartBehaviour(JSONUtilities.JSON.update_client_confirmation_model(0, JSONUtilities.JSON.make_player_public_stats( invalidated.getVictim(),server.getClient(invalidated.getVictim().getSession()).getNickname(), identifiers, cardnames, false), invalidated.getInitiator().getFutureInteraction().getStartBehaviour()));

                            server.sendOne(JSONUtilities.JSON.make_client_lose(lost.getName(),
                                    victimCardID.toString()), invalidated.getVictim().getSession());
                            server.sendAll(JSONUtilities.JSON
                                    .make_client_print(server.getNickname(invalidated.getVictim().getSession())
                                            + " trashed a " + lost.getName()));

                        }
                    }
                    server.sendAll(JSONUtilities.JSON.make_client_update_environment("trashpile",
                            env.trashpile.size()));
                    server.sendAll(JSONUtilities.JSON
                            .make_client_update_trashpile(env.trashpile.get(env.trashpile.size() - 1)));

                }
            } else if (from.equals("environment") && to.equals("discardpile_victim")) {
                // Its probably a feast, or some feast-ish card
                if (foreach.equals("trash_my_tablecard")) {
                    for (int ix = 0; ix < selectedIdentifiersFromThisInteractionCase.size(); ix++) {
                        if (selectedIdentifiersFromThisInteractionCase.get(ix).startsWith("env")) {
                            System.out.println(
                                    "Feast used on " + selectedCardNamesFromThisInteractionCase.get(ix));
                            Card bought = env.environment_buy(selectedCardNamesFromThisInteractionCase.get(ix));
                            invalidated.getVictim().deck.used.add(bought);

                            // Trash the feast from the table. 
                            Card feasttrash = env.tablecards.get(env.tablecards.size() - 1);
                            env.tablecards.remove(env.tablecards.size() - 1);
                            env.trashpile.add(feasttrash);
                            //todododododod                // Update clients for tablecards and trashpile!!! todo

                            make_client_update_discardpile(invalidated.getVictim());
                            make_clients_update_environment(bought.getName());
                            make_clients_update_environment("trashpile");

                            server.sendAll(JSONUtilities.JSON
                                    .make_client_print(server.getNickname(invalidated.getVictim().getSession())
                                            + " gained a " + bought.getName() + " with feast."));

                        }
                    }
                } else if (foreach.equals("none")) {
                    for (int ix = 0; ix < selectedIdentifiersFromThisInteractionCase.size(); ix++) {
                        if (selectedIdentifiersFromThisInteractionCase.get(ix).startsWith("env")) {
                            System.out.println("Remodel/workshop used on "
                                    + selectedCardNamesFromThisInteractionCase.get(ix));
                            Card bought = env.environment_buy(selectedCardNamesFromThisInteractionCase.get(ix));
                            invalidated.getVictim().deck.used.add(bought);

                            make_client_update_discardpile(invalidated.getVictim());
                            make_clients_update_environment(bought.getName());

                            server.sendAll(JSONUtilities.JSON
                                    .make_client_print(server.getNickname(invalidated.getVictim().getSession())
                                            + " gained a " + bought.getName() + "."));

                        }
                    }
                }
            } else if (from.equals("environment") && (to.equals("hand_victim"))) {
                if (foreach.equals("none")) {
                    for (int ix = 0; ix < selectedIdentifiersFromThisInteractionCase.size(); ix++) {
                        if (selectedIdentifiersFromThisInteractionCase.get(ix).startsWith("env")) {
                            Card gained = env.environment_buy(selectedCardNamesFromThisInteractionCase.get(ix));
                            invalidated.getVictim().hand.add(gained);
                            server.sendOne(JSONUtilities.JSON.make_client_gain(gained.getName()),
                                    invalidated.getVictim().getSession());
                            server.sendAll(JSONUtilities.JSON.make_client_update_environment(gained.getName(),
                                    env.environment_library.get(gained.getName()).size()));
                        }
                    }

                }
            } else if (from.equals("interaction") && (to.equals("hand_victim"))) {
                for (int ix = 0; ix < selectedIdentifiersFromThisInteractionCase.size(); ix++) {
                    Card thecard = selectedCardsFromThisInteractionCase.get(ix);
                    invalidated.getVictim().hand.add(thecard);

                    JSONObject obj = JSONUtilities.JSON.make_client_print(
                            "Library gave you a : " + selectedCardNamesFromThisInteractionCase.get(ix));
                    server.getClient(invalidated.getVictim().getSession()).write(obj);

                    JSONObject act = JSONUtilities.JSON
                            .make_client_gain(selectedCardNamesFromThisInteractionCase.get(ix));
                    server.getClient(invalidated.getVictim().getSession()).write(act);
                    make_client_update_deck(invalidated.getVictim());
                    make_client_update_discardpile(invalidated.getVictim());
                }
            } else if (from.equals("interaction") && (to.equals("throneroomqueue"))) {
                Card thecard = selectedCardsFromThisInteractionCase.get(0);
                env.throneRoomQueue.offer(thecard);
                env.throneRoomQueue.offer(thecard);
                invalidated.getVictim().loseCard(thecard.getName(),
                        Long.parseLong(selectedIdentifiersFromThisInteractionCase.get(0).split("_")[1]));
                env.tablecards.add(thecard);
                server.sendOne(
                        JSONUtilities.JSON.make_client_lose(thecard.getName(),
                                ((selectedIdentifiersFromThisInteractionCase.get(0).split("_")[1]))),
                        invalidated.getVictim().getSession());
                server.sendAll(JSONUtilities.JSON
                        .make_client_print(server.getNickname(invalidated.getVictim().getSession()) + " lost a "
                                + thecard.getName()));
                server.sendAll(JSONUtilities.JSON.make_client_refresh_tableview());

            } else if (from.equals("interaction") && (to.equals("top_deck_victim"))) {
                if (foreach.equals("if_selected_then_discardpile_victim")) {
                    HashMap<String, Card> mapping = new HashMap<>();
                    System.out.println("spying on " + invalidated.preloadedCards.size() + " cards");
                    System.out.println("however, there are " + invalidated.selectedSpecials.size()
                            + " selected specials.");
                    System.out.println("also " + invalidated.selectedIds.size() + " selected ids, and "
                            + invalidated.allowedIds.size() + " allowed ids");

                    // Allowed : other_2, other_3
                    // selectedIds : other_0_0, other_1_1 -> door naar volgende interactie
                    // preloadedCards : other_0, other_1 -> deze moeten eigenlijk de specials zijn
                    // selectedSpecials : other_0, other_1 -> preloadedcards moeten discarded worden op basis van

                    for (int ix = 0; ix < invalidated.preloadedCards.size(); ix++) {
                        if (ix >= invalidated.allowedIds.size())
                            continue;
                        if (ix >= players.keySet().size())
                            continue;
                        int indexforvictim = ix;
                        Player p = indexForMe(invalidated.getInitiator(), ix);
                        System.out
                                .println("got player " + server.getNickname(p.getSession()) + " from indexFor("
                                        + server.getNickname(invalidated.getInitiator().getSession()) + " , "
                                        + ix + ");");
                        String searchID = "other_" + indexforvictim;
                        boolean isSelected = false;
                        Card card = invalidated.preloadedCards.get(ix);
                        String theid = searchID;
                        for (int ixix = 0; ixix < invalidated.selectedIds.size(); ixix++) {
                            Card c = invalidated.selectedSpecials.get(ixix);
                            String id = invalidated.selectedIds.get(ixix);

                            if (id.startsWith(searchID)) {
                                // Card is selected
                                isSelected = true;
                                card = c;
                                invalidated.selectedSpecials.remove(ixix);
                                invalidated.selectedIds.remove(ixix);
                                break;
                            }
                        }

                        if (isSelected) {
                            p.deck.used.add(card);
                            System.out.println("ADDED " + card.getName() + " TO DISCARDPILE OF "
                                    + server.getNickname(p.getSession()));
                        } else {
                            p.deck.addTopOfDeck(card);
                            System.out.println("ADDED " + card.getName() + " TO TOP OF DECK OF "
                                    + server.getNickname(p.getSession()));
                        }

                        make_client_update_deck(p);
                        make_client_update_discardpile(p);

                    }
                }
            } else if (from.equals("interaction") && to.equals("discardpile_victim")) {
                if (foreach.equals("none")) {
                    // WITCH
                    System.out.println("Witching on " + invalidated.preloadedCards.size() + " cards");
                    System.out.println("however, there are " + invalidated.selectedSpecials.size()
                            + " selected specials.");
                    System.out.println("also " + invalidated.selectedIds.size() + " selected ids, and "
                            + invalidated.allowedIds.size() + " allowed ids");
                    ArrayList<String> newSelectedIds = new ArrayList<>();
                    for (int ix = 0; ix < invalidated.selectedIds.size(); ix++) {
                        Card c = invalidated.selectedSpecials.get(ix);
                        String id = invalidated.selectedIds.get(ix);
                        invalidated.getVictim().deck.used.add(c);
                        make_client_update_discardpile(invalidated.getVictim());
                    }
                    make_clients_update_cursepile();

                } else if (foreach.equals("if_not_selected")) {
                    HashMap<String, Card> mapping = new HashMap<>();
                    System.out.println("thieving on " + invalidated.preloadedCards.size() + " cards");
                    System.out.println("however, there are " + invalidated.selectedSpecials.size()
                            + " selected specials.");
                    System.out.println("also " + invalidated.selectedIds.size() + " selected ids, and "
                            + invalidated.allowedIds.size() + " allowed ids");
                    ArrayList<String> newSelectedIds = new ArrayList<>();

                    for (String s : invalidated.selectedIds)
                        System.out.println("selected id : " + s);
                    for (Card c : invalidated.selectedSpecials)
                        System.out.println("selected card : " + c.getName());
                    for (Card c : invalidated.preloadedCards)
                        System.out.println("preloadedcard name : " + c.getName());
                    for (String s : invalidated.allowedIds)
                        System.out.println("allowed id : " + s);
                    for (String s : invalidated.fromPreviousInteraction.keySet())
                        System.out.println("fromprevious : " + s + " - "
                                + invalidated.fromPreviousInteraction.get(s).getName());
                    HashMap<String, Card> to_next_interaction = new HashMap<>();
                    for (String previd : invalidated.fromPreviousInteraction.keySet()) {
                        Card linked = invalidated.fromPreviousInteraction.get(previd);
                        int indexlinked = Integer.parseInt(previd.split("_")[1]);
                        Player victimlinked = indexForMe(invalidated.getInitiator(), indexlinked);
                        boolean isSelected = false;
                        for (int ix = 0; ix < invalidated.selectedSpecials.size(); ix++) {
                            Card selected = invalidated.selectedSpecials.get(ix);
                            String selectid = invalidated.selectedIds.get(ix);
                            int selectedindexlinked = Integer.parseInt(selectid.split("_")[1]);
                            Player victimselectedlinked = indexForMe(invalidated.getInitiator(),
                                    selectedindexlinked);
                            if (indexlinked == selectedindexlinked) {
                                if (linked.getName().equals(selected.getName())) {
                                    // linked is selected from id victimlinked
                                    isSelected = true;
                                    invalidated.selectedSpecials.remove(ix);
                                    invalidated.selectedIds.remove(ix);
                                    break;
                                }
                            }

                        }
                        if (isSelected) {

                            to_next_interaction.put(previd, linked);
                        } else {
                            victimlinked.deck.used.add(linked);
                            make_client_update_discardpile(victimlinked);
                        }
                    }
                    invalidated.selectedIds.clear();
                    invalidated.selectedSpecials.clear();
                    for (String s : to_next_interaction.keySet()) {
                        invalidated.selectedIds.add(s);
                        invalidated.selectedSpecials.add(to_next_interaction.get(s));
                    }
                }
            } else if (from.equals("interaction") && (to.equals("trashpile"))) {
                if (foreach.equals("if_selected_then_gain")) {
                    System.out.println("thieving on " + invalidated.preloadedCards.size() + " cards");
                    System.out.println("however, there are " + invalidated.selectedSpecials.size()
                            + " selected specials.");
                    System.out.println("also " + invalidated.selectedIds.size() + " selected ids, and "
                            + invalidated.allowedIds.size() + " allowed ids");

                    for (String previd : invalidated.fromPreviousInteraction.keySet()) {
                        Card linked = invalidated.fromPreviousInteraction.get(previd);
                        int indexlinked = Integer.parseInt(previd.split("_")[1]);
                        Player victimlinked = indexForMe(invalidated.getInitiator(), indexlinked);

                        for (int ix = 0; ix < invalidated.selectedSpecials.size(); ix++) {
                            Card selected = invalidated.selectedSpecials.get(ix);
                            String selectid = invalidated.selectedIds.get(ix);
                            int selectedindexlinked = Integer.parseInt(selectid.split("_")[0]);
                            Player victimselectedlinked = indexForMe(invalidated.getInitiator(),
                                    selectedindexlinked);
                            if (indexlinked == selectedindexlinked) {
                                if (linked.getName().equals(selected.getName())) {
                                    // linked is selected from id victimlinked
                                }
                            }
                        }
                    }

                    ArrayList<String> selectedIdReal = new ArrayList<>();
                    for (String s : invalidated.selectedIds) {
                        System.out.println("selectedid : " + s);
                        selectedIdReal.add(s.split("_")[0] + "_" + s.split("_")[1]);
                    }
                    invalidated.selectedIds = selectedIdReal;
                    // IDCA IS UNIQUE
                    ArrayList<String> notselectedcardids = new ArrayList<>();
                    ArrayList<Card> notselectedcards = new ArrayList<>();

                    for (int ix = 0; ix < invalidated.preloadedCards.size(); ix++) {
                        Card ca = invalidated.preloadedCards.get(ix);
                        if (ix >= invalidated.allowedIds.size())
                            continue;
                        String idca = invalidated.allowedIds.get(ix);
                        boolean isselected = false;
                        for (int ixi = 0; ixi < invalidated.selectedIds.size(); ixi++) {
                            String idselected = invalidated.selectedIds.get(ixi);
                            if (idselected.equals(idca)) {
                                isselected = true;
                                break;
                            }
                        }
                        if (!isselected) {
                            notselectedcardids.add(idca);
                            notselectedcards.add(ca);
                        }
                    }
                    for (int ix = 0; ix < notselectedcards.size(); ix++) {
                        Card notselectedcard = notselectedcards.get(ix);
                        String notselectedcardid = notselectedcardids.get(ix);
                        String indexforvictim = notselectedcardid.split("_")[1];
                        Player victim = indexForMe(invalidated.getInitiator(),
                                Integer.parseInt(indexforvictim));
                        env.trashpile.add(notselectedcard);
                        make_clients_update_environment("trashpile");
                        System.out.println("trashed a " + notselectedcard.getName());
                    }

                    for (int ix = 0; ix < invalidated.selectedSpecials.size(); ix++) {
                        Card selectedcard = invalidated.selectedSpecials.get(ix);
                        String selectedcardid = invalidated.selectedIds.get(ix);
                        String indexforvictim = selectedcardid.split("_")[1];
                        Player victim = invalidated.getInitiator();
                        victim.deck.used.add(selectedcard);
                        make_client_update_discardpile(victim);
                        System.out.println("discarded a " + selectedcard.getName() + " to player["
                                + victim.getSession() + "] discardpile");
                    }
                }
            }
            // MoveSomething currently moves everything. 

            // hand_victim
            // top_of_deck_victim

        }

        boolean allDone = true;
        for (Player p : players.values()) {
            if ((p.getCurrentInteraction() != null) && (!p.getCurrentInteraction().isConfirmed()))
                allDone = false;
        }

        if (allDone) {
            // Check if initiator needs another interaction!
            // If not, check if he has other actions. Because if not, enterBuyPhase. 
            System.out.println("Flushing interactioncases to next stage");

            for (Player p : players.values()) {
                p.setInteraction(null);
            }
            // Not now, to test flow. 
            boolean futures = false;
            for (Player p : players.values()) {
                if (p.getFutureInteraction() != null)
                    futures = true;
                if (p.hasIterativeInteractionFactory())
                    futures = true;
            }
            System.out.println("Found a future!");
            // Flush futures to current if there are any, and send them.
            if (futures) {
                for (Player p : players.values()) {
                    if (p.getFutureInteraction() == null) {
                        if (!p.hasIterativeInteractionFactory()) {
                            // this player has no iterative interaction factory
                        } else {
                            p.setInteraction(p.getIterativeInteraction(invalidated, env));
                            p.getCurrentInteraction().addListener(this);
                            server.sendOne(p.getCurrentInteraction().getStartBehaviour(), p.getSession());
                        }
                    } else {
                        p.setInteraction(p.getFutureInteraction());
                        p.setFutureInteraction(null);
                        if (p.getCurrentInteraction() != null) {
                            p.getCurrentInteraction().addListener(this);
                            server.sendOne(p.getCurrentInteraction().getStartBehaviour(), p.getSession());
                        }
                    }
                }
            } else {
                interactionmode = false;

                if (!env.throneRoomQueue.isEmpty()) {
                    handleAction(env.throneRoomQueue.poll(), players.get(playerOrder.get(current_turn)));
                } else if (!invalidated.getInitiator().hasActionCard() || this.actions == 0)
                    enterBuyPhase();
                else {
                    highlight_actions(players.get(playerOrder.get(current_turn)));
                }
            }

        }
        // All interactions closed? Make an initiator interactioncase maybe?
        // Check finishbehaviour!
    }
}

From source file:org.openspaces.rest.space.ReplicationRESTController.java

private int parseMemoryString(String string) {
    if (string.length() < 2)
        throw new RuntimeException("invalid memory string:" + string);
    if (Character.isDigit(string.charAt(string.length() - 1)))
        throw new RuntimeException("invalid memory string: units required (m or g)");
    int base = Integer.parseInt(string.substring(0, string.length() - 1));
    if (string.substring(string.length() - 1).toLowerCase().equals("g"))
        base *= 1024;/*from w  w w .j a v a2  s.  co  m*/
    //default is mb
    return base;
}

From source file:ee.sk.digidoc.DataFile.java

/**
 * Helper method to validate an id// ww w.  j a v  a 2  s.  com
 * @param str input data
 * @param bStrong flag that specifies if Id atribute value is to
 * be rigorously checked (according to digidoc format) or only
 * as required by XML-DSIG
 * @return exception or null for ok
 */
private DigiDocException validateId(String str, boolean bStrong) {
    DigiDocException ex = null;
    if (str == null)
        ex = new DigiDocException(DigiDocException.ERR_DATA_FILE_ID, "Id is a required attribute", null);
    if (str != null && bStrong && m_sigDoc.getFormat() != null
            && !m_sigDoc.getFormat().equalsIgnoreCase(SignedDoc.FORMAT_BDOC)
            && (str.charAt(0) != 'D' || (!Character.isDigit(str.charAt(1)) && str.charAt(1) != 'O')))
        ex = new DigiDocException(DigiDocException.ERR_DATA_FILE_ID,
                "Id attribute value has to be in form D<number> or DO", null);
    return ex;
}

From source file:com.legstar.cob2xsd.XsdDataItem.java

/**
 * Transform the COBOL name to a valid XML Name. Does not do any
 * beautification other than strictly complying with XML specifications.
 * /*from   w w  w . ja  v  a  2s  . c o  m*/
 * @param cobolName the original COBOL data item name
 * @return a valid XML Name
 */
public static String getXmlCompatibleCobolName(final String cobolName) {
    if (cobolName != null && cobolName.length() > 0 && Character.isDigit(cobolName.charAt(0))) {
        return SAFE_NAME_PREFIX + cobolName;
    } else {
        return cobolName;
    }
}

From source file:com.zimbra.cs.imap.ImapRequest.java

ImapPartSpecifier readPartSpecifier(boolean binary, boolean literals) throws ImapParseException, IOException {
    String sectionPart = "", sectionText = "";
    List<String> headers = null;
    boolean done = false;

    while (Character.isDigit((char) peekChar())) {
        sectionPart += (sectionPart.equals("") ? "" : ".") + readNumber(NONZERO);
        if (!(done = (peekChar() != '.'))) {
            skipChar('.');
        }/*  w ww. j ava 2 s .  co  m*/
    }
    if (!done && peekChar() != ']') {
        if (binary) {
            throw new ImapParseException(tag, "section-text not permitted for BINARY");
        }
        sectionText = readATOM();
        if (sectionText.equals("HEADER.FIELDS") || sectionText.equals("HEADER.FIELDS.NOT")) {
            headers = new ArrayList<String>();
            skipSpace();
            skipChar('(');
            while (peekChar() != ')') {
                if (!headers.isEmpty()) {
                    skipSpace();
                }
                headers.add((literals ? readAstring() : readAquoted()).toUpperCase());
            }
            if (headers.isEmpty()) {
                throw new ImapParseException(tag, "header-list may not be empty");
            }
            skipChar(')');
        } else if (sectionText.equals("MIME")) {
            if (sectionPart.isEmpty()) {
                throw new ImapParseException(tag, "\"MIME\" is not a valid section-spec");
            }
        } else if (!sectionText.equals("HEADER") && !sectionText.equals("TEXT")) {
            throw new ImapParseException(tag, "unknown section-text \"" + sectionText + '"');
        }
    }
    ImapPartSpecifier pspec = new ImapPartSpecifier(binary ? "BINARY" : "BODY", sectionPart, sectionText);
    pspec.setHeaders(headers);
    return pspec;
}

From source file:com.android.tools.lint.checks.GradleDetector.java

/** Returns the latest build tools installed for the given major version.
 * We just cache this once; we don't need to be accurate in the sense that if the
 * user opens the SDK manager and installs a more recent version, we capture this in
 * the same IDE session.//from w  w w  .  java2s  .c  o  m
 *
 * @param client the associated client
 * @param major the major version of build tools to look up (e.g. typically 18, 19, ...)
 * @return the corresponding highest known revision
 */
@Nullable
private static PreciseRevision getLatestBuildTools(@NonNull LintClient client, int major) {
    if (major != sMajorBuildTools) {
        sMajorBuildTools = major;

        List<PreciseRevision> revisions = Lists.newArrayList();
        if (major == 21) {
            revisions.add(new PreciseRevision(21, 1, 2));
        } else if (major == 20) {
            revisions.add(new PreciseRevision(20));
        } else if (major == 19) {
            revisions.add(new PreciseRevision(19, 1));
        } else if (major == 18) {
            revisions.add(new PreciseRevision(18, 1, 1));
        }
        // The above versions can go stale.
        // Check if a more recent one is installed. (The above are still useful for
        // people who haven't updated with the SDK manager recently.)
        File sdkHome = client.getSdkHome();
        if (sdkHome != null) {
            File[] dirs = new File(sdkHome, FD_BUILD_TOOLS).listFiles();
            if (dirs != null) {
                for (File dir : dirs) {
                    String name = dir.getName();
                    if (!dir.isDirectory() || !Character.isDigit(name.charAt(0))) {
                        continue;
                    }
                    PreciseRevision v = parseRevisionSilently(name);
                    if (v != null && v.getMajor() == major) {
                        revisions.add(v);
                    }
                }
            }
        }

        if (!revisions.isEmpty()) {
            sLatestBuildTools = Collections.max(revisions);
        }
    }

    return sLatestBuildTools;
}

From source file:cn.kangeqiu.kq.activity.MainActivity.java

/**
 * set head/*from  w  w  w  .j  a  v a 2 s .c o  m*/
 * 
 * @param username
 * @return
 */
User setUserHead(String username) {
    User user = new User();
    user.setUsername(username);
    String headerName = null;
    if (!TextUtils.isEmpty(user.getNick())) {
        headerName = user.getNick();
    } else {
        headerName = user.getUsername();
    }
    if (username.equals(Constant.NEW_FRIENDS_USERNAME)) {
        user.setHeader("");
    } else if (Character.isDigit(headerName.charAt(0))) {
        user.setHeader("#");
    } else {
        user.setHeader(HanziToPinyin.getInstance().get(headerName.substring(0, 1)).get(0).target.substring(0, 1)
                .toUpperCase());
        char header = user.getHeader().toLowerCase().charAt(0);
        if (header < 'a' || header > 'z') {
            user.setHeader("#");
        }
    }
    return user;
}

From source file:edu.stanford.muse.email.EmailFetcherStats.java

@SuppressWarnings("unused")
private static String processLastReceived(String header) {
    header = header.toLowerCase();/*from   w w w.j a  va2  s.co  m*/
    StringTokenizer st = new StringTokenizer(header, " \t()[]");
    String x = st.nextToken();
    if (!x.equals("from")) {
        log.warn("Warning: unrecognized header: " + header);
        return null;
    }

    while (st.hasMoreTokens()) {
        String s = st.nextToken();
        if (Character.isDigit(s.charAt(0))) {
            log.warn("IP address: " + s);
            return s;
        }
    }
    return null;
}