Search in sources :

Example 81 with StringTokenizer

use of java.util.StringTokenizer in project pcgen by PCGen.

the class BonusObj method buildDependMap.

private void buildDependMap(String aString) {
    addImpliedDependenciesFor(aString);
    // First whack out all the () pairs to find variable names
    while (aString.lastIndexOf('(') >= 0) {
        final int x = CoreUtility.innerMostStringStart(aString);
        final int y = CoreUtility.innerMostStringEnd(aString);
        if (y < x) {
            return;
        }
        final String bString = aString.substring(x + 1, y);
        buildDependMap(bString);
        aString = new StringBuilder(aString.length()).append(aString.substring(0, x)).append(aString.substring(y + 1)).toString();
    }
    if (aString.indexOf("(") >= 0 || aString.indexOf(")") >= 0 || aString.indexOf("%") >= 0) {
        return;
    }
    // We now have the substring we want to work on
    final StringTokenizer cTok = new StringTokenizer(aString, ".,");
    while (cTok.hasMoreTokens()) {
        final String controlString = cTok.nextToken();
        // skip flow control tags
        if ("IF".equals(controlString) || "THEN".equals(controlString) || "ELSE".equals(controlString) || "GT".equals(controlString) || "GTEQ".equals(controlString) || "EQ".equals(controlString) || "LTEQ".equals(controlString) || "LT".equals(controlString)) {
            continue;
        }
        // Now remove math strings: + - / *
        // and comparison strings: > = <
        // remember, a StringTokenizer will tokenize
        // on any of the found delimiters
        final StringTokenizer mTok = new StringTokenizer(controlString, "+-/*>=<\"");
        while (mTok.hasMoreTokens()) {
            String newString = mTok.nextToken();
            String testString = newString;
            boolean found = false;
            // now Check for MIN or MAX
            while (!found) {
                if (newString.indexOf("MAX") >= 0) {
                    testString = newString.substring(0, newString.indexOf("MAX"));
                    newString = newString.substring(newString.indexOf("MAX") + 3);
                } else if (newString.indexOf("MIN") >= 0) {
                    testString = newString.substring(0, newString.indexOf("MIN"));
                    newString = newString.substring(newString.indexOf("MIN") + 3);
                } else {
                    found = true;
                }
                // check to see if it's a number
                try {
                    Float.parseFloat(testString);
                } catch (NumberFormatException e) {
                    // It's a Variable!
                    if (!testString.isEmpty()) {
                        if (testString.startsWith("MOVE[")) {
                            testString = new StringBuilder(testString.length()).append("TYPE.").append(testString.substring(5, testString.length() - 1)).toString();
                        }
                        dependMap.put(testString.intern(), "1");
                        addImpliedDependenciesFor(testString);
                    }
                }
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer)

Example 82 with StringTokenizer

use of java.util.StringTokenizer in project pcgen by PCGen.

the class EquipSet method getRootIdPath.

/**
	 * return the root id of the EquipSet
	 * If our id_path is "0.2.8.15", the root would be "0.2"
	 * @return root id path
	 **/
public String getRootIdPath() {
    final StringBuilder buf = new StringBuilder(50);
    final StringTokenizer aTok = new StringTokenizer(id_path, Constants.EQUIP_SET_PATH_SEPARATOR, false);
    final String result;
    if (aTok.countTokens() < 2) {
        result = Constants.EMPTY_STRING;
    } else {
        // get first two tokens and delimiter
        buf.append(aTok.nextToken());
        buf.append('.');
        buf.append(aTok.nextToken());
        result = buf.toString();
    }
    return result;
}
Also used : StringTokenizer(java.util.StringTokenizer)

Example 83 with StringTokenizer

use of java.util.StringTokenizer in project pcgen by PCGen.

the class EquipSet method equipItem.

/**
	 * Apply this EquipSet to a PlayerCharacter object.
	 * @param aPC the PC to equip the item on
	 */
public void equipItem(PlayerCharacter aPC) {
    final StringTokenizer aTok = new StringTokenizer(getIdPath(), Constants.EQUIP_SET_PATH_SEPARATOR);
    // it's inside a container, don't try to equip
    if (aTok.countTokens() > Constants.ID_PATH_LENGTH_FOR_NON_CONTAINED) {
        // Get back to carried/equipped/not carried to determine correct location
        StringBuilder rootPath = new StringBuilder(40);
        for (int i = 0; i < Constants.ID_PATH_LENGTH_FOR_NON_CONTAINED; i++) {
            if (i > 0) {
                rootPath.append(".");
            }
            rootPath.append(aTok.nextToken());
        }
        EquipSet rootSet = aPC.getEquipSetByIdPath(rootPath.toString());
        if (rootSet != null && rootSet.name.startsWith(Constants.EQUIP_LOCATION_CARRIED)) {
            eq_item.addEquipmentToLocation(qty, EquipmentLocation.CARRIED_NEITHER, false, aPC);
        } else if (rootSet != null && rootSet.name.startsWith(Constants.EQUIP_LOCATION_NOTCARRIED)) {
            eq_item.addEquipmentToLocation(qty, EquipmentLocation.NOT_CARRIED, false, aPC);
        } else if (rootSet != null && rootSet.name.startsWith(Constants.EQUIP_LOCATION_EQUIPPED)) {
            eq_item.addEquipmentToLocation(qty, EquipmentLocation.EQUIPPED_NEITHER, false, aPC);
        } else {
            eq_item.addEquipmentToLocation(qty, EquipmentLocation.CONTAINED, false, aPC);
        }
    } else if (name.startsWith(Constants.EQUIP_LOCATION_CARRIED)) {
        eq_item.addEquipmentToLocation(qty, EquipmentLocation.CARRIED_NEITHER, false, aPC);
    } else if (name.startsWith(Constants.EQUIP_LOCATION_NOTCARRIED)) {
        eq_item.addEquipmentToLocation(qty, EquipmentLocation.NOT_CARRIED, false, aPC);
    } else if (eq_item.isWeapon()) {
        if (name.equals(Constants.EQUIP_LOCATION_PRIMARY) || name.equals(Constants.EQUIP_LOCATION_NATURAL_PRIMARY)) {
            eq_item.addWeaponToLocation(qty, EquipmentLocation.EQUIPPED_PRIMARY, aPC);
        } else if (name.startsWith(Constants.EQUIP_LOCATION_SECONDARY) || name.equals(Constants.EQUIP_LOCATION_NATURAL_SECONDARY)) {
            eq_item.addWeaponToLocation(qty, EquipmentLocation.EQUIPPED_SECONDARY, aPC);
        } else if (name.equals(Constants.EQUIP_LOCATION_BOTH)) {
            eq_item.addWeaponToLocation(qty, EquipmentLocation.EQUIPPED_BOTH, aPC);
        } else if (name.equals(Constants.EQUIP_LOCATION_DOUBLE)) {
            eq_item.addWeaponToLocation(qty, EquipmentLocation.EQUIPPED_TWO_HANDS, aPC);
        } else if (name.equals(Constants.EQUIP_LOCATION_UNARMED)) {
            eq_item.addWeaponToLocation(qty, EquipmentLocation.EQUIPPED_NEITHER, aPC);
        } else if (name.equals(Constants.EQUIP_LOCATION_TWOWEAPONS)) {
            Float quantity = (qty.doubleValue() < 2.0) ? 2.0f : qty;
            setQty(quantity);
            eq_item.addWeaponToLocation(quantity, EquipmentLocation.EQUIPPED_TWO_HANDS, aPC);
        } else if (name.equals(Constants.EQUIP_LOCATION_SHIELD)) {
            eq_item.addWeaponToLocation(qty, EquipmentLocation.EQUIPPED_NEITHER, aPC);
        }
    } else {
        eq_item.addEquipmentToLocation(qty, EquipmentLocation.EQUIPPED_NEITHER, true, aPC);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer)

Example 84 with StringTokenizer

use of java.util.StringTokenizer in project pcgen by PCGen.

the class OutputNameFormatting method getPreFormatedOutputName.

/**
	 * rephrase parenthetical name components, if appropriate
	 * @return pre formatted output name
	 */
private static String getPreFormatedOutputName(String displayName) {
    //if there are no () to pull from, just return the name
    if (!displayName.contains("(") || !displayName.contains(")")) {
        return displayName;
    }
    //we just take from the first ( to the first ), typically there should only be one of each
    //the stuff inside the ()
    final String subName = displayName.substring(displayName.indexOf('(') + 1, displayName.lastIndexOf(')'));
    final StringTokenizer tok = new StringTokenizer(subName, "/");
    final StringBuilder newNameBuff = new StringBuilder(subName.length());
    while (tok.hasMoreTokens()) {
        //build this new string from right to left
        newNameBuff.insert(0, tok.nextToken());
        if (tok.hasMoreTokens()) {
            newNameBuff.insert(0, " ");
        }
    }
    return newNameBuff.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer)

Example 85 with StringTokenizer

use of java.util.StringTokenizer in project pcgen by PCGen.

the class ExportHandler method parseIIFs.

/**
	 * Helper method to parse the IIF tokens, includes dealing with a 
	 * |FOR child, |IIF child, ELSE, END IF and plain text
	 * 
	 * @param expr
	 * @param tokens
	 * @return IIFNode representing the parsed tokens
	 */
private IIFNode parseIIFs(String expr, StringTokenizer tokens) {
    final IIFNode node = new IIFNode(expr);
    // Flag to indicate whether we are adding the 
    // true case (e.g.  The IF) or the false case 
    // (e.g.  The ELSE)
    boolean trueCase = true;
    while (tokens.hasMoreTokens()) {
        final String line = tokens.nextToken();
        // It's a |FOR child
        if (line.startsWith("|FOR")) {
            StringTokenizer newFor = new StringTokenizer(line, ",");
            newFor.nextToken();
            // see PCGen docs for |FOR token
            if (newFor.nextToken().startsWith("%")) {
                if (trueCase) {
                    node.addTrueChild(parseFORs(line, tokens));
                } else {
                    node.addFalseChild(parseFORs(line, tokens));
                }
            } else {
                if (trueCase) {
                    node.addTrueChild(line);
                } else {
                    node.addFalseChild(line);
                }
            }
        } else // It's a child IIF, make a recursive call
        if (line.startsWith("|IIF(") && (line.lastIndexOf(',') == -1)) {
            String newExpr = line.substring(5, line.lastIndexOf(')'));
            if (trueCase) {
                node.addTrueChild(parseIIFs(newExpr, tokens));
            } else {
                node.addFalseChild(parseIIFs(newExpr, tokens));
            }
        } else // Set the flag so that the false case is added next
        if (line.startsWith("|ELSE|")) {
            trueCase = false;
        } else // We're done, so exit
        if (line.startsWith("|ENDIF|")) {
            return node;
        } else {
            if (trueCase) {
                node.addTrueChild(line);
            } else {
                node.addFalseChild(line);
            }
        }
    }
    return node;
}
Also used : StringTokenizer(java.util.StringTokenizer)

Aggregations

StringTokenizer (java.util.StringTokenizer)4881 ArrayList (java.util.ArrayList)1083 IOException (java.io.IOException)506 File (java.io.File)392 BufferedReader (java.io.BufferedReader)380 HashMap (java.util.HashMap)375 HashSet (java.util.HashSet)263 FileReader (java.io.FileReader)224 List (java.util.List)200 InputStreamReader (java.io.InputStreamReader)191 Map (java.util.Map)152 FileInputStream (java.io.FileInputStream)135 Iterator (java.util.Iterator)114 Set (java.util.Set)114 URL (java.net.URL)108 NoSuchElementException (java.util.NoSuchElementException)90 Properties (java.util.Properties)84 InputStream (java.io.InputStream)83 BufferedWriter (java.io.BufferedWriter)80 FileNotFoundException (java.io.FileNotFoundException)78