Example usage for java.util StringTokenizer countTokens

List of usage examples for java.util StringTokenizer countTokens

Introduction

In this page you can find the example usage for java.util StringTokenizer countTokens.

Prototype

public int countTokens() 

Source Link

Document

Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.

Usage

From source file:de.tor.tribes.ui.views.DSWorkbenchSOSRequestAnalyzer.java

private void copySelectionToClipboardAsBBCode() {
    HashMap<Tribe, SOSRequest> selectedRequests = new HashMap<>();
    List<DefenseInformation> selection = getSelectedRows();
    if (selection.isEmpty()) {
        showInfo("Keine SOS Anfragen eingelesen");
        return;/*from  w  ww.  ja  v a 2 s . co m*/
    }

    for (DefenseInformation info : selection) {
        Tribe defender = info.getTarget().getTribe();
        SOSRequest request = selectedRequests.get(defender);
        if (request == null) {
            request = new SOSRequest(defender);
            selectedRequests.put(defender, request);
        }
        TargetInformation targetInfo = request.addTarget(info.getTarget());
        targetInfo.merge(info.getTargetInformation());
    }

    try {
        boolean extended = (JOptionPaneHelper.showQuestionConfirmBox(this,
                "Erweiterte BB-Codes verwenden (nur fr Forum und Notizen geeignet)?", "Erweiterter BB-Code",
                "Nein", "Ja") == JOptionPane.YES_OPTION);

        StringBuilder buffer = new StringBuilder();
        if (extended) {
            buffer.append("[u][size=12]SOS Anfragen[/size][/u]\n\n");
        } else {
            buffer.append("[u]SOS Anfragen[/u]\n\n");
        }

        List<SOSRequest> requests = new LinkedList<>();
        CollectionUtils.addAll(requests, selectedRequests.values());
        buffer.append(new SosListFormatter().formatElements(requests, extended));

        if (extended) {
            buffer.append("\n[size=8]Erstellt am ");
            buffer.append(
                    new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "[/size]\n");
        } else {
            buffer.append("\nErstellt am ");
            buffer.append(
                    new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss").format(Calendar.getInstance().getTime()));
            buffer.append(" mit DS Workbench ");
            buffer.append(Constants.VERSION).append(Constants.VERSION_ADDITION + "\n");
        }

        String b = buffer.toString();
        StringTokenizer t = new StringTokenizer(b, "[");
        int cnt = t.countTokens();
        if (cnt > 1000) {
            if (JOptionPaneHelper.showQuestionConfirmBox(this,
                    "Die momentan vorhandenen Anfragen bentigen mehr als 1000 BB-Codes\n"
                            + "und knnen daher im Spiel (Forum/IGM/Notizen) nicht auf einmal dargestellt werden.\nTrotzdem exportieren?",
                    "Zu viele BB-Codes", "Nein", "Ja") == JOptionPane.NO_OPTION) {
                return;
            }
        }

        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(b), null);
        showSuccess("Daten in Zwischenablage kopiert");
    } catch (Exception e) {
        logger.error("Failed to copy data to clipboard", e);
        showError("Fehler beim Kopieren in die Zwischenablage");
    }

}

From source file:com.ibm.bi.dml.runtime.controlprogram.parfor.ProgramConverter.java

/**
 * /*  ww  w  .  j a  v  a2  s. com*/
 * @param in
 * @return
 */
public static String[] parseStringArray(String in) {
    StringTokenizer st = new StringTokenizer(in, ELEMENT_DELIM);
    int len = st.countTokens();
    String[] a = new String[len];
    for (int i = 0; i < len; i++) {
        String tmp = st.nextToken();
        if (tmp.equals("null"))
            a[i] = null;
        else
            a[i] = tmp;
    }
    return a;
}

From source file:com.salesmanager.central.shipping.ShippingCustomRatesAction.java

private String modifyCostLine(int action, MerchantConfiguration costs, BigDecimal price, int weight)
        throws Exception {

    if (costs == null)
        throw new Exception(" MerchantConfiguration costs is null");

    Map costsmap = buildPriceRegionWithPrice(new HashMap(), costs.getConfigurationValue2());

    Set keys = costsmap.keySet();
    Iterator it = keys.iterator();
    StringBuffer costline = new StringBuffer();
    // int i = 1;
    for (int i = 1; i <= ShippingConstants.MAX_PRICE_RANGE_COUNT; i++) {
        // while(it.hasNext()) {
        // int key = (Integer)it.next();
        ShippingPriceRegion spr = (ShippingPriceRegion) costsmap.get(i);
        if (i == zonepriceid) {// price need to be deleted from that id
            // @todo if only one country to be delete, also remove the
            // price-weight

            if (spr != null && spr.getPriceLine() != null) {

                String ln = spr.getPriceLine();
                StringTokenizer st = new StringTokenizer(ln, "|");
                while (st.hasMoreTokens()) {
                    String tk = (String) st.nextToken();
                    StringTokenizer prtk = new StringTokenizer(tk, ";");
                    int countsemic = prtk.countTokens();
                    int j = 1;
                    while (prtk.hasMoreTokens()) {
                        String wpr = (String) prtk.nextToken();
                        int indxof = wpr.indexOf(":");
                        boolean found = false;

                        if (indxof != -1) {// got something

                            if (action == 1) {// delete price
                                String pr = wpr.substring(0, indxof);
                                if (!pr.equals(String.valueOf(weight))) {// if
                                    // dealing
                                    // with
                                    // delete
                                    costline.append(wpr);// 5:3
                                } else {// the one we want to delete or
                                        // modify
                                    if (j == countsemic && countsemic == 1) {
                                        costline.append("*");
                                    }/*w w w  . java  2 s  .  c  om*/
                                    found = true;
                                }
                            } else {// modify price

                                String pr = wpr.substring(0, indxof);
                                if (!pr.equals(String.valueOf(weight))) {// if
                                    // dealing
                                    // with
                                    // delete
                                    costline.append(wpr);// 5:3
                                } else {// the one we want to delete or
                                        // modify
                                    costline.append(wpr.substring(0, indxof)).append(":").append(price);
                                }
                            }
                        } else {
                            costline.append(wpr);
                        }
                        if (j < countsemic && !found) {

                            costline.append(";");
                        }
                        j++;
                    }
                }
            } else {
                costline.append("*");
            }

        } else {

            if (spr != null && spr.getPriceLine() != null) {
                costline.append(spr.getPriceLine());
            } else {
                costline.append("*");
            }
        }

        if (i < costsmap.size()) {
            costline.append("|");
        }

    }

    return costline.toString();

}

From source file:corelyzer.ui.CorelyzerApp.java

private static void doStartupChecks() {
    String javaVersion = System.getProperty("java.version");
    StringTokenizer st = new StringTokenizer(javaVersion, ".");
    if (st.countTokens() >= 2) {
        final int majorVersion = Integer.parseInt(st.nextToken());
        final int minorVersion = Integer.parseInt(st.nextToken());

        if (!MAC_OS_X && majorVersion <= 1 && minorVersion <= 6) {
            JOptionPane.showMessageDialog(null, "Detected Java version " + javaVersion + ":\n"
                    + "Java 1.7 or later is recommended for use with this version of Corelyzer.");
        }/*from w w  w  . j a va 2 s  . c  om*/
    }
}

From source file:com.cyberway.issue.crawler.Heritrix.java

/**
 * Test string is valid login/password string.
 *
 * A valid login/password string has the login and password compounded
 * w/ a ':' delimiter.//from w w  w  . j av  a 2s.c  om
 *
 * @param str String to test.
 * @return True if valid password/login string.
 */
protected static boolean isValidLoginPasswordString(String str) {
    boolean isValid = false;
    StringTokenizer tokenizer = new StringTokenizer(str, ":");
    if (tokenizer.countTokens() == 2) {
        String login = ((String) tokenizer.nextElement()).trim();
        String password = ((String) tokenizer.nextElement()).trim();
        if (login.length() > 0 && password.length() > 0) {
            isValid = true;
        }
    }
    return isValid;
}

From source file:com.salesmanager.central.shipping.ShippingCustomRatesAction.java

private MerchantConfiguration deleteShippingEstimate(MerchantConfiguration conf, int index) throws Exception {

    StringTokenizer cvtk = null;

    String confValue = "";

    confValue = conf.getConfigurationValue1();

    cvtk = new StringTokenizer(confValue, "|");

    StringBuffer linebuffer = new StringBuffer();
    int i = 1;/*from ww w  .  j a  v a  2  s .co  m*/
    int count = cvtk.countTokens();
    while (cvtk.hasMoreTokens()) {

        String line = (String) cvtk.nextToken();
        if (!line.equals("*")) {
            String newLine = line.substring(0, 2);
            if (newLine.equals(new StringBuffer().append(index).append(":").toString())) {
                linebuffer.append("*");// replace the line
            } else {
                linebuffer.append(line);
            }
        } else {
            linebuffer.append(line);
        }
        if (i < count) {
            linebuffer.append("|");
        }
        i++;
    }

    conf.setConfigurationValue1(linebuffer.toString());

    java.util.Date dt = new java.util.Date();
    conf.setLastModified(dt);

    return conf;

}

From source file:android.transitions.everywhere.Transition.java

private static int[] parseMatchOrder(String matchOrderString) {
    StringTokenizer st = new StringTokenizer(matchOrderString, ",");
    int matches[] = new int[st.countTokens()];
    int index = 0;
    while (st.hasMoreTokens()) {
        String token = st.nextToken().trim();
        if (MATCH_ID_STR.equalsIgnoreCase(token)) {
            matches[index] = Transition.MATCH_ID;
        } else if (MATCH_INSTANCE_STR.equalsIgnoreCase(token)) {
            matches[index] = Transition.MATCH_INSTANCE;
        } else if (MATCH_NAME_STR.equalsIgnoreCase(token)) {
            matches[index] = Transition.MATCH_NAME;
        } else if (MATCH_VIEW_NAME_STR.equalsIgnoreCase(token)) {
            matches[index] = Transition.MATCH_NAME;
        } else if (MATCH_ITEM_ID_STR.equalsIgnoreCase(token)) {
            matches[index] = Transition.MATCH_ITEM_ID;
        } else if (token.isEmpty()) {
            int[] smallerMatches = new int[matches.length - 1];
            System.arraycopy(matches, 0, smallerMatches, 0, index);
            matches = smallerMatches;//from w w  w .ja  va2s.  c  o m
            index--;
        } else {
            throw new InflateException("Unknown match type in matchOrder: '" + token + "'");
        }
        index++;
    }
    return matches;
}

From source file:lineage2.gameserver.handler.admincommands.impl.AdminEditChar.java

/**
 * Method useAdminCommand./*from www  .  jav a  2  s  . c om*/
 * @param comm Enum<?>
 * @param wordList String[]
 * @param fullString String
 * @param activeChar Player
 * @return boolean * @see lineage2.gameserver.handler.admincommands.IAdminCommandHandler#useAdminCommand(Enum<?>, String[], String, Player)
 */
@Override
public boolean useAdminCommand(Enum<?> comm, String[] wordList, String fullString, Player activeChar) {
    Commands command = (Commands) comm;
    if (activeChar.getPlayerAccess().CanRename) {
        if (fullString.startsWith("admin_settitle")) {
            try {
                String val = fullString.substring(15);
                GameObject target = activeChar.getTarget();
                Player player = null;
                if (target == null) {
                    return false;
                }
                if (target.isPlayer()) {
                    player = (Player) target;
                    player.setTitle(val);
                    player.sendMessage("Your title has been changed by a GM");
                    player.sendChanges();
                } else if (target.isNpc()) {
                    ((NpcInstance) target).setTitle(val);
                    target.decayMe();
                    target.spawnMe();
                }
                return true;
            } catch (StringIndexOutOfBoundsException e) {
                activeChar.sendMessage("You need to specify the new title.");
                return false;
            }
        } else if (fullString.startsWith("admin_setclass")) {
            try {
                String val = fullString.substring(15);
                int id = Integer.parseInt(val.trim());
                GameObject target = activeChar.getTarget();
                if ((target == null) || !target.isPlayer()) {
                    target = activeChar;
                }
                if (id > (ClassId.VALUES.length - 1)) {
                    activeChar.sendMessage(
                            "There are no classes over " + String.valueOf(ClassId.VALUES.length - 1) + "  id.");
                    return false;
                }
                Player player = target.getPlayer();
                player.setClassId(id, true, false);
                player.sendMessage("Your class has been changed by a GM");
                player.broadcastCharInfo();
                return true;
            } catch (StringIndexOutOfBoundsException e) {
                activeChar.sendMessage("You need to specify the new class id.");
                return false;
            }
        } else if (fullString.startsWith("admin_setname")) {
            try {
                String val = fullString.substring(14);
                GameObject target = activeChar.getTarget();
                Player player;
                if ((target != null) && target.isPlayer()) {
                    player = (Player) target;
                } else {
                    return false;
                }
                if (mysql.simple_get_int("count(*)", "characters", "`char_name` like '" + val + "'") > 0) {
                    activeChar.sendMessage("Name already exist.");
                    return false;
                }
                Log.add("Character " + player.getName() + " renamed to " + val + " by GM "
                        + activeChar.getName(), "renames");
                player.reName(val);
                player.sendMessage("Your name has been changed by a GM");
                return true;
            } catch (StringIndexOutOfBoundsException e) {
                activeChar.sendMessage("You need to specify the new name.");
                return false;
            }
        }
    }
    if (!activeChar.getPlayerAccess().CanEditChar && !activeChar.getPlayerAccess().CanViewChar) {
        return false;
    }
    if (fullString.equals("admin_current_player")) {
        showCharacterList(activeChar, null);
    } else if (fullString.startsWith("admin_character_list")) {
        try {
            String val = fullString.substring(21);
            Player target = GameObjectsStorage.getPlayer(val);
            showCharacterList(activeChar, target);
        } catch (StringIndexOutOfBoundsException e) {
        }
    } else if (fullString.startsWith("admin_show_characters")) {
        try {
            String val = fullString.substring(22);
            int page = Integer.parseInt(val);
            listCharacters(activeChar, page);
        } catch (StringIndexOutOfBoundsException e) {
        }
    } else if (fullString.startsWith("admin_find_character")) {
        try {
            String val = fullString.substring(21);
            findCharacter(activeChar, val);
        } catch (StringIndexOutOfBoundsException e) {
            activeChar.sendMessage("You didnt enter a character name to find.");
            listCharacters(activeChar, 0);
        }
    } else if (!activeChar.getPlayerAccess().CanEditChar) {
        return false;
    } else if (fullString.equals("admin_edit_character")) {
        editCharacter(activeChar);
    } else if (fullString.equals("admin_character_actions")) {
        showCharacterActions(activeChar);
    } else if (fullString.equals("admin_nokarma")) {
        setTargetKarma(activeChar, 0);
    } else if (fullString.startsWith("admin_setkarma")) {
        try {
            String val = fullString.substring(15);
            int karma = Integer.parseInt(val);
            setTargetKarma(activeChar, karma);
        } catch (StringIndexOutOfBoundsException e) {
            activeChar.sendMessage("Please specify new karma value.");
        }
    } else if (fullString.startsWith("admin_save_modifications")) {
        try {
            String val = fullString.substring(24);
            adminModifyCharacter(activeChar, val);
        } catch (StringIndexOutOfBoundsException e) {
            activeChar.sendMessage("Error while modifying character.");
            listCharacters(activeChar, 0);
        }
    } else if (fullString.equals("admin_rec")) {
        GameObject target = activeChar.getTarget();
        Player player = null;
        if ((target != null) && target.isPlayer()) {
            player = (Player) target;
        } else {
            return false;
        }
        player.setRecomHave(player.getRecomHave() + 1);
        player.sendMessage("You have been recommended by a GM");
        player.broadcastCharInfo();
    } else if (fullString.startsWith("admin_rec")) {
        try {
            String val = fullString.substring(10);
            int recVal = Integer.parseInt(val);
            GameObject target = activeChar.getTarget();
            Player player = null;
            if ((target != null) && target.isPlayer()) {
                player = (Player) target;
            } else {
                return false;
            }
            player.setRecomHave(player.getRecomHave() + recVal);
            player.sendMessage("You have been recommended by a GM");
            player.broadcastCharInfo();
        } catch (NumberFormatException e) {
            activeChar.sendMessage("Command format is //rec <number>");
        }
    } else if (fullString.startsWith("admin_sethero")) {
        GameObject target = activeChar.getTarget();
        Player player;
        if ((wordList.length > 1) && (wordList[1] != null)) {
            player = GameObjectsStorage.getPlayer(wordList[1]);
            if (player == null) {
                activeChar.sendMessage("Character " + wordList[1] + " not found in game.");
                return false;
            }
        } else if ((target != null) && target.isPlayer()) {
            player = (Player) target;
        } else {
            activeChar.sendMessage("You must specify the name or target character.");
            return false;
        }
        if (player.isHero()) {
            player.setHero(false);
            player.updatePledgeClass();
            player.removeSkill(SkillTable.getInstance().getInfo(395, 1));
            player.removeSkill(SkillTable.getInstance().getInfo(396, 1));
            player.removeSkill(SkillTable.getInstance().getInfo(1374, 1));
            player.removeSkill(SkillTable.getInstance().getInfo(1375, 1));
            player.removeSkill(SkillTable.getInstance().getInfo(1376, 1));
        } else {
            player.setHero(true);
            player.updatePledgeClass();
            player.addSkill(SkillTable.getInstance().getInfo(395, 1));
            player.addSkill(SkillTable.getInstance().getInfo(396, 1));
            player.addSkill(SkillTable.getInstance().getInfo(1374, 1));
            player.addSkill(SkillTable.getInstance().getInfo(1375, 1));
            player.addSkill(SkillTable.getInstance().getInfo(1376, 1));
        }
        player.sendSkillList();
        player.sendMessage("Admin has changed your hero status.");
        player.broadcastUserInfo();
    } else if (fullString.startsWith("admin_setnoble")) {
        GameObject target = activeChar.getTarget();
        Player player;
        if ((wordList.length > 1) && (wordList[1] != null)) {
            player = GameObjectsStorage.getPlayer(wordList[1]);
            if (player == null) {
                activeChar.sendMessage("Character " + wordList[1] + " not found in game.");
                return false;
            }
        } else if ((target != null) && target.isPlayer()) {
            player = (Player) target;
        } else {
            activeChar.sendMessage("You must specify the name or target character.");
            return false;
        }
        if (player.isNoble()) {
            Olympiad.removeNoble(player);
            player.setNoble(false);
            player.sendMessage("Admin changed your noble status, now you are not nobless.");
        } else {
            Olympiad.addNoble(player);
            player.setNoble(true);
            player.sendMessage("Admin changed your noble status, now you are Nobless.");
        }
        player.updatePledgeClass();
        player.updateNobleSkills();
        player.sendSkillList();
        player.broadcastUserInfo();
    } else if (fullString.startsWith("admin_setsex")) {
        GameObject target = activeChar.getTarget();
        Player player = null;
        if ((target != null) && target.isPlayer()) {
            player = (Player) target;
        } else {
            return false;
        }
        player.changeSex();
        player.sendMessage("Your gender has been changed by a GM");
        player.broadcastUserInfo();
    } else if (fullString.startsWith("admin_setcolor")) {
        try {
            String val = fullString.substring(15);
            GameObject target = activeChar.getTarget();
            Player player = null;
            if ((target != null) && target.isPlayer()) {
                player = (Player) target;
            } else {
                return false;
            }
            player.setNameColor(Integer.decode("0x" + val));
            player.sendMessage("Your name color has been changed by a GM");
            player.broadcastUserInfo();
        } catch (StringIndexOutOfBoundsException e) {
            activeChar.sendMessage("You need to specify the new color.");
        }
    } else if (fullString.startsWith("admin_add_exp_sp_to_character")) {
        addExpSp(activeChar);
    } else if (fullString.startsWith("admin_add_exp_sp")) {
        try {
            final String val = fullString.substring(16).trim();
            String[] vals = val.split(" ");
            long exp = NumberUtils.toLong(vals[0], 0L);
            int sp = vals.length > 1 ? NumberUtils.toInt(vals[1], 0) : 0;
            adminAddExpSp(activeChar, exp, sp);
        } catch (Exception e) {
            activeChar.sendMessage("Usage: //add_exp_sp <exp> <sp>");
        }
    } else if (fullString.startsWith("admin_trans")) {
        StringTokenizer st = new StringTokenizer(fullString);
        if (st.countTokens() > 1) {
            st.nextToken();
            int transformId = 0;
            try {
                transformId = Integer.parseInt(st.nextToken());
            } catch (Exception e) {
                activeChar.sendMessage("Specify a valid integer value.");
                return false;
            }
            if ((transformId != 0) && (activeChar.getTransformation() != 0)) {
                activeChar.sendPacket(Msg.YOU_ALREADY_POLYMORPHED_AND_CANNOT_POLYMORPH_AGAIN);
                return false;
            }
            activeChar.setTransformation(transformId);
            activeChar.sendMessage("Transforming...");
        } else {
            activeChar.sendMessage("Usage: //trans <ID>");
        }
    } else if (fullString.startsWith("admin_setsubclass")) {
        final GameObject target = activeChar.getTarget();
        if ((target == null) || !target.isPlayer()) {
            activeChar.sendPacket(Msg.SELECT_TARGET);
            return false;
        }
        final Player player = (Player) target;
        StringTokenizer st = new StringTokenizer(fullString);
        if (st.countTokens() > 1) {
            st.nextToken();
            int classId = Short.parseShort(st.nextToken());
            if (!player.addSubClass(classId, true, 0, 0, false, 0)) {
                activeChar.sendMessage(new CustomMessage(
                        "lineage2.gameserver.model.instances.L2VillageMasterInstance.SubclassCouldNotBeAdded",
                        activeChar));
                return false;
            }
            player.sendPacket(Msg.CONGRATULATIONS_YOU_HAVE_TRANSFERRED_TO_A_NEW_CLASS);
        } else {
            setSubclass(activeChar, player);
        }
    } else if (fullString.startsWith("admin_setfame")) {
        try {
            String val = fullString.substring(14);
            int fame = Integer.parseInt(val);
            setTargetFame(activeChar, fame);
        } catch (StringIndexOutOfBoundsException e) {
            activeChar.sendMessage("Please specify new fame value.");
        }
    } else if (fullString.startsWith("admin_setbday")) {
        String msgUsage = "Usage: //setbday YYYY-MM-DD";
        String date = fullString.substring(14);
        if ((date.length() != 10) || !Util.isMatchingRegexp(date, "[0-9]{4}-[0-9]{2}-[0-9]{2}")) {
            activeChar.sendMessage(msgUsage);
            return false;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            dateFormat.parse(date);
        } catch (ParseException e) {
            activeChar.sendMessage(msgUsage);
        }
        if ((activeChar.getTarget() == null) || !activeChar.getTarget().isPlayer()) {
            activeChar.sendMessage("Please select a character.");
            return false;
        }
        if (!mysql.set("update characters set createtime = UNIX_TIMESTAMP('" + date + "') where obj_Id = "
                + activeChar.getTarget().getObjectId())) {
            activeChar.sendMessage(msgUsage);
            return false;
        }
        activeChar.sendMessage("New Birthday for " + activeChar.getTarget().getName() + ": " + date);
        activeChar.getTarget().getPlayer().sendMessage("Admin changed your birthday to: " + date);
    } else if (fullString.startsWith("admin_give_item")) {
        if (wordList.length < 3) {
            activeChar.sendMessage("Usage: //give_item id count <target>");
            return false;
        }
        int id = Integer.parseInt(wordList[1]);
        int count = Integer.parseInt(wordList[2]);
        if ((id < 1) || (count < 1) || (activeChar.getTarget() == null) || !activeChar.getTarget().isPlayer()) {
            activeChar.sendMessage("Usage: //give_item id count <target>");
            return false;
        }
        ItemFunctions.addItem(activeChar.getTarget().getPlayer(), id, count, true);
    } else if (fullString.startsWith("admin_add_bang")) {
        if (!Config.ALT_PCBANG_POINTS_ENABLED) {
            activeChar.sendMessage("Error! Pc Bang Points service disabled!");
            return true;
        }
        if (wordList.length < 1) {
            activeChar.sendMessage("Usage: //add_bang count <target>");
            return false;
        }
        int count = Integer.parseInt(wordList[1]);
        if ((count < 1) || (activeChar.getTarget() == null) || !activeChar.getTarget().isPlayer()) {
            activeChar.sendMessage("Usage: //add_bang count <target>");
            return false;
        }
        Player target = activeChar.getTarget().getPlayer();
        target.addPcBangPoints(count, false);
        activeChar.sendMessage("You have added " + count + " Pc Bang Points to " + target.getName());
    } else if (fullString.startsWith("admin_set_bang")) {
        if (!Config.ALT_PCBANG_POINTS_ENABLED) {
            activeChar.sendMessage("Error! Pc Bang Points service disabled!");
            return true;
        }
        if (wordList.length < 1) {
            activeChar.sendMessage("Usage: //set_bang count <target>");
            return false;
        }
        int count = Integer.parseInt(wordList[1]);
        if ((count < 1) || (activeChar.getTarget() == null) || !activeChar.getTarget().isPlayer()) {
            activeChar.sendMessage("Usage: //set_bang count <target>");
            return false;
        }
        Player target = activeChar.getTarget().getPlayer();
        target.setPcBangPoints(count);
        target.sendMessage("Your Pc Bang Points count is now " + count);
        target.sendPacket(new ExPCCafePointInfo(target, count, 1, 2, 12));
        activeChar.sendMessage("You have set " + target.getName() + "'s Pc Bang Points to " + count);
    } else if (fullString.startsWith("admin_reset_mentor_penalty")) {
        if (activeChar.getTarget().getPlayer() == null) {
            activeChar.sendMessage("You have no target selected.");
            return false;
        }
        if (Mentoring.getTimePenalty(activeChar.getTargetId()) > 0) {
            Mentoring.setTimePenalty(activeChar.getTargetId(), 0, -1);
            activeChar.getTarget().getPlayer().sendMessage("Your mentor penalty has been lifted by a GM.");
            activeChar.sendMessage(
                    activeChar.getTarget().getPlayer().getName() + "'s mentor penalty has been lifted.");
        } else {
            activeChar.sendMessage("The selected character has no penalty.");
            return false;
        }
    }
    return true;
}

From source file:com.salesmanager.central.shipping.ShippingCustomRatesAction.java

private MerchantConfiguration deleteLine(MerchantConfiguration conf, int index, int value) throws Exception {

    StringTokenizer cvtk = null;

    String confValue = "";

    if (value == 1) {// country
        confValue = conf.getConfigurationValue1();

    } else {// price
        confValue = conf.getConfigurationValue2();
    }// w  w  w . j a  va 2  s .c om

    cvtk = new StringTokenizer(confValue, "|");

    StringBuffer linebuffer = new StringBuffer();
    int i = 1;
    int count = cvtk.countTokens();
    while (cvtk.hasMoreTokens()) {

        String line = (String) cvtk.nextToken();
        if (i != index) {
            linebuffer.append(line);
        } else {
            linebuffer.append("*");// replace the line
        }
        if (i < count) {
            linebuffer.append("|");
        }
        i++;
    }

    if (value == 1) {
        conf.setConfigurationValue1(linebuffer.toString());
    } else {
        conf.setConfigurationValue2(linebuffer.toString());
    }
    java.util.Date dt = new java.util.Date();
    conf.setLastModified(dt);

    return conf;

}

From source file:edu.indiana.lib.twinpeaks.search.singlesearch.musepeer.Query.java

/**
 * Generate a SEARCH command// www. j  ava2  s .c  om
 */
private void doSearchCommand() throws SearchException {
    StringTokenizer targetParser;
    String searchCriteria, searchFilter, targets;
    String pageSize, sessionId, sortBy;
    /*
     * Set search criteria
     */
    searchCriteria = getSearchString();
    _log.debug("Search criteria: " + searchCriteria);
    /*
     * Generate the search command
     */
    setParameter("action", "search");
    setParameter("xml", "true");
    setParameter("sessionID", getSessionId());

    setParameter("queryStatement", searchCriteria);

    targets = getRequestParameter("targets");
    targetParser = new StringTokenizer(targets);
    _targetCount = targetParser.countTokens();

    while (targetParser.hasMoreTokens()) {
        String target = targetParser.nextToken();

        setParameter("dbList", target);

        _log.debug("SEARCH: added DB " + target);
    }
    /*
     * Start an asynchronous query (no results are returned) to set things up
     * for a subsequent PROGRESS (status) command
     */
    setParameter("limitsMaxPerSource", getPageSize());
    setParameter("limitsMaxPerPage", "0");
    /*
     * Formatting
     */
    setFormattingFiles();
}