Example usage for java.util StringTokenizer StringTokenizer

List of usage examples for java.util StringTokenizer StringTokenizer

Introduction

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

Prototype

public StringTokenizer(String str, String delim) 

Source Link

Document

Constructs a string tokenizer for the specified string.

Usage

From source file:org.n2.chess.beans.FenParser.java

@Override
public void parse(String fen) {
    StringTokenizer st = new StringTokenizer(fen, " ");
    try {//from   ww  w. ja va2  s.  c  om
        placement = st.nextToken();
        active = st.nextToken();
        castling = st.nextToken();
        enPassant = st.nextToken();
        halfmove = st.nextToken();
        number = st.nextToken();

        st = new StringTokenizer(placement, "/");
        rows = new ArrayList<String>(8);
        for (int i = 0; i < 8; i++) {
            rows.add(st.nextToken());
        }
        if (rows.size() != 8) {
            malformedFen(fen);
        }
    } catch (NoSuchElementException e) {
        malformedFen(fen);
    }
}

From source file:org.obiba.onyx.print.impl.PdfTemplateReport.java

public void setFieldToVariableMap(String keyValuePairs) {
    fieldToVariableMap = new HashMap<String, String>();
    // Get list of strings separated by the delimiter
    StringTokenizer tokenizer = new StringTokenizer(keyValuePairs, ",");
    while (tokenizer.hasMoreElements()) {
        String token = tokenizer.nextToken();
        String[] entry = token.split("=");
        if (entry.length == 2) {
            fieldToVariableMap.put(entry[0].trim(), entry[1].trim());
        } else {//from   w w w.  j a va  2 s .c om
            log.error("Could not identify PDF field name to variable path mapping: " + token);
        }
    }
}

From source file:com.clustercontrol.sql.util.JdbcDriverProperties.java

/**
 * properties(param1=xxx&param2=yyy&param3=zzz...)????Properties??
 * @param props properties???/*from  w  w  w  . j  a  v  a 2s. c  o  m*/
 * @return
 */
private Properties parseProperties(String props) {
    Properties ret = new Properties();

    StringTokenizer separeteToken = new StringTokenizer(props, _propertiesSepareteToken);
    StringTokenizer defineToken = null;

    while (separeteToken.hasMoreTokens()) {
        String property = separeteToken.nextToken();
        log.debug(this.classname + " : parsing property. (" + property + ")");
        defineToken = new StringTokenizer(property, _propertiesDefineToken);
        if (defineToken.countTokens() == 2) {
            String key = defineToken.nextToken();
            String value = defineToken.nextToken();
            ret.setProperty(key, value);
            log.debug(this.classname + " : setting property. (key = " + key + ", value = " + value + ")");
        } else {
            log.info(this.classname + " : skipped, because of invalid jdbc parameter. (" + property + ")");
        }
    }

    return ret;
}

From source file:com.enonic.cms.framework.util.UrlPathEncoder.java

private static StringBuffer doEncodePath(String localPath, String encoding) {
    StringBuffer encodedPath = new StringBuffer(localPath.length() * 2);
    if (localPath.startsWith("/")) {
        encodedPath.append("/");
    }/*from w  w w.  ja  v  a2 s .  co m*/

    StringTokenizer st = new StringTokenizer(localPath, "/");
    int i = 0;
    while (st.hasMoreTokens()) {
        String pathElement = st.nextToken();
        i++;
        if (i > 1) {
            encodedPath.append("/");
        }
        try {
            encodedPath.append(URLEncoder.encode(pathElement, encoding));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(
                    "Failed to encode path '" + localPath + "' with encoding '" + encoding + "'", e);
        }
    }

    if (localPath.endsWith("/")) {
        encodedPath.append("/");
    }
    return encodedPath;
}

From source file:mtis.CreateDisplayJson.java

public String getJson(String city, String duration) throws Exception {
    String finalReturn = "";
    JSONArray list = new JSONArray();
    JSONObject finalObj = new JSONObject();
    ArrayList<String> month = new ArrayList<String>();
    month.add("Jan");
    month.add("Feb");
    month.add("Mar");
    month.add("Apr");
    month.add("May");
    month.add("Jun");
    month.add("Jul");
    month.add("Aug");
    month.add("Sep");
    month.add("Oct");
    month.add("Nov");
    month.add("Dec");
    Date d = new Date();
    int dayCount = Integer.parseInt(duration);
    Long dL = d.getTime();//from   w w w .ja v  a  2  s .  c o  m
    FileReader fr = new FileReader(
            "C:\\Users\\Server\\Documents\\twitterData\\" + city + "\\traffic_data_" + city + "_display.txt");
    BufferedReader br = new BufferedReader(fr);
    String line = br.readLine();
    StringBuffer text = new StringBuffer();
    while (line != null) {
        text.append(line);
        line = br.readLine();
    }
    String textData = text.toString();
    textData = textData.replaceAll("\\n", " ");
    String fullTokens[] = textData.split("\\$\\$\\$");
    for (int i = fullTokens.length - 1; i >= 1; i--) {
        StringTokenizer st = new StringTokenizer(fullTokens[i], "||");
        String dateString = st.nextToken();
        Date date = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy").parse(dateString);
        Long dateL = date.getTime();
        //System.out.println(dateL);
        String name = st.nextToken();
        name = name.replaceAll("'", " ");
        if (dL - ((dayCount + 1) * 86400 * 1000) <= dateL && dateL <= dL - ((dayCount) * 86400 * 1000)) {
            //System.out.println("i am in");
            JSONObject js = new JSONObject();
            js.put("userScreenName", name);
            System.out.println(name);
            js.put("userProfilePic", st.nextToken());
            js.put("userId", st.nextToken());
            js.put("statusId", st.nextToken());
            js.put("username", st.nextToken());
            js.put("text", st.nextToken());

            SimpleDateFormat format = new SimpleDateFormat("hh:mm a ");
            //System.out.println(format.format(date));
            //System.out.println(date.getDate()+"-"+month.get(date.getMonth())+" "+format.format(date));              
            //System.out.println(dateL);

            js.put("time", date.getDate() + "-" + month.get(date.getMonth()) + " " + format.format(date));
            list.add(js);
        }
        line = br.readLine();
    }
    finalObj.put("locations", list);
    br.close();
    finalReturn = finalObj.toString();
    System.out.println(finalReturn);
    return finalReturn;
}

From source file:com.xruby.debug.DebugCommandLineOptions.java

/**
 * Constructor/*from   w  w w. j a v  a  2 s  .  c  om*/
 *
 * @param args Arguments
 */
public DebugCommandLineOptions(String[] args) {
    pathList = new ArrayList<String>();

    GnuParser parser = new GnuParser();

    Options options = new Options();
    options.addOption(SOURCE_PATH_S, SOURCE_PATH, true, "path for the source code, seperated by semicolon");
    options.addOption(CLASS_PATH_S, CLASS_PATH, true, "classpath for debugee");

    CommandLine line;
    try {
        line = parser.parse(options, args, true);
    } catch (ParseException e) {
        throw new Error(e.toString());
    }

    if (line.hasOption(SOURCE_PATH_S)) {
        String paths = line.getOptionValue(SOURCE_PATH_S);
        StringTokenizer st = new StringTokenizer(paths, SEPARATOR);

        while (st.hasMoreTokens()) {
            String path = st.nextToken();
            pathList.add(path);
        }
    }

    if (line.hasOption(CLASS_PATH_S)) {
        this.classPath = line.getOptionValue(CLASS_PATH_S);
    }

    String[] tmp = line.getArgs();
    entrance = new StringBuffer();
    for (String str : tmp) {
        entrance.append(str).append(" ");
    }
}

From source file:Main.java

public static int findProcessIdWithPS(String command) throws Exception {

    int procId = -1;

    Runtime r = Runtime.getRuntime();

    Process procPs;//from w  w  w  .j  a va  2 s.  co  m

    procPs = r.exec(SHELL_CMD_PS);

    BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
    String line;

    while ((line = reader.readLine()) != null) {
        if (line.contains(' ' + command)) {

            StringTokenizer st = new StringTokenizer(line, " ");
            st.nextToken(); // proc owner

            procId = Integer.parseInt(st.nextToken().trim());

            break;
        }
    }

    return procId;

}

From source file:de.tor.tribes.util.parser.TroopsParser.java

public boolean parse(String pTroopsString) {
    StringTokenizer lineTok = new StringTokenizer(pTroopsString, "\n\r");
    int villageLines = -1;
    boolean retValue = false;
    int foundTroops = 0;
    //boolean haveVillage = false;
    Village v = null;//w w  w .  j ava 2s.  c o  m
    TroopAmountFixed ownTroops = null;
    TroopAmountFixed troopsInVillage = null;
    TroopAmountFixed troopsOutside = null;
    TroopAmountFixed troopsOnTheWay = null;
    TroopsManager.getSingleton().invalidate();
    // used to update group on the fly, if not "all" selected
    String groupName = null;
    // groups could be multiple lines, detection is easiest for first line (starts with "Gruppen:")
    boolean groupLines = false;
    // store visited villages, so we can add em to selected group
    List<Village> villages = new LinkedList<>();
    while (lineTok.hasMoreElements()) {
        //parse single line for village
        String line = lineTok.nextToken();
        //tokenize line by tab and space
        //  StringTokenizer elemTok = new StringTokenizer(line, " \t");
        //parse single line for village
        if (v != null) {
            //parse 4 village lines!
            line = line.trim();
            if (line.trim().startsWith(getVariable("troops.own"))) {
                ownTroops = parseUnits(line.replaceAll(getVariable("troops.own"), "").trim());
            } else if (line.trim().startsWith(getVariable("troops.in.village"))) {
                troopsInVillage = parseUnits(line.replaceAll(getVariable("troops.in.village"), "").trim());
            } else if (line.trim().startsWith(getVariable("troops.outside"))) {
                troopsOutside = parseUnits(line.replaceAll(getVariable("troops.outside"), "").trim());
            } else if (line.trim().startsWith(getVariable("troops.on.the.way"))) {
                troopsOnTheWay = parseUnits(line.replaceAll(getVariable("troops.on.the.way"), "").trim());
            }
            villageLines--;
        } else {
            try {
                Village current = VillageParser.parseSingleLine(line);
                if (current != null) {
                    v = current;
                    villageLines = 4;
                    // we are not searching for further group names
                    groupLines = false;
                    // add village to list of villages in selected group
                    if (groupName != null)
                        villages.add(v);
                } else {
                    // Check if current line is first group line. In case it is, store selected group
                    if (line.trim().startsWith(getVariable("overview.groups")))
                        groupLines = true;
                    // Check if current line contains active group. In case it does, store group name and stop searching
                    if (groupLines && line.matches(".*>.*?<.*")) {
                        groupLines = false;
                        groupName = StringUtils.substringBetween(line, ">", "<"); // = line.replaceAll(".*>|<.*",""); if we stop using Apache Commons            
                    }
                }
            } catch (Exception e) {
                v = null;
                villageLines = 0;
                // Check if current line is first group line. In case it is, store selected group
                if (line.trim().startsWith(getVariable("overview.groups")))
                    groupLines = true;
                // Check if current line contains active group. In case it does, store group name and stop searching
                if (groupLines && line.matches(".*>.*?<.*")) {
                    groupLines = false;
                    groupName = StringUtils.substringBetween(line, ">", "<"); // = line.replaceAll(".*>|<.*",""); if we stop using Apache Commons            
                }
            }
        }
        //add troops information
        if (villageLines == 0) {
            if (v != null && ownTroops != null && troopsInVillage != null && troopsOutside != null
                    && troopsOnTheWay != null) {
                //add troops to manager
                VillageTroopsHolder own = TroopsManager.getSingleton().getTroopsForVillage(v,
                        TroopsManager.TROOP_TYPE.OWN, true);
                VillageTroopsHolder inVillage = TroopsManager.getSingleton().getTroopsForVillage(v,
                        TroopsManager.TROOP_TYPE.IN_VILLAGE, true);
                VillageTroopsHolder outside = TroopsManager.getSingleton().getTroopsForVillage(v,
                        TroopsManager.TROOP_TYPE.OUTWARDS, true);
                VillageTroopsHolder onTheWay = TroopsManager.getSingleton().getTroopsForVillage(v,
                        TroopsManager.TROOP_TYPE.ON_THE_WAY, true);

                own.setTroops(ownTroops);
                inVillage.setTroops(troopsInVillage);
                outside.setTroops(troopsOutside);
                onTheWay.setTroops(troopsOnTheWay);
                ownTroops = null;
                troopsInVillage = null;
                troopsOutside = null;
                troopsOnTheWay = null;
                v = null;
                foundTroops++;
                //found at least one village, so retValue is true    
                retValue = true;
            } else {
                v = null;
                ownTroops = null;
                troopsInVillage = null;
                troopsOutside = null;
                troopsOnTheWay = null;
            }
        }
    }
    if (retValue) {
        try {
            DSWorkbenchMainFrame.getSingleton()
                    .showSuccess("DS Workbench hat Truppeninformationen zu " + foundTroops
                            + ((foundTroops == 1) ? " Dorf " : " Drfern ")
                            + " in die Truppenbersicht eingetragen.");
        } catch (Exception e) {
            NotifierFrame.doNotification("DS Workbench hat Truppeninformationen zu " + foundTroops
                    + ((foundTroops == 1) ? " Dorf " : " Drfern ") + " in die Truppenbersicht eingetragen.",
                    NotifierFrame.NOTIFY_INFO);
        }
    }

    //update selected group, if any
    if (groupName != null && !groupName.equals(getVariable("groups.all"))) {
        HashMap<String, List<Village>> groupTable = new HashMap<>();
        groupTable.put(groupName, villages);
        DSWorkbenchMainFrame.getSingleton().fireGroupParserEvent(groupTable);
    }

    TroopsManager.getSingleton().revalidate(retValue);
    return retValue;
}

From source file:sample.ContextFilter.java

private String getTenantId(HttpServletRequest request) {
    String requestUrl = currentUrl(request);

    if ("".equals(requestUrl) || "/".equals(requestUrl)) {
        return null;
    }/* ww  w. j a va2 s .c  o  m*/
    StringTokenizer tokens = new StringTokenizer(requestUrl, "/");
    if (tokens.hasMoreTokens()) {
        String result = tokens.nextToken();
        if (tokens.hasMoreTokens() || requestUrl.endsWith("/")) {
            return result;
        }
    }
    return null;
}

From source file:com.chinamobile.bcbsp.examples.bytearray.pagerank.PRVertexLiteNew.java

@Override
public void fromString(String vertexData) throws Exception {
    String[] buffer = new String[2];
    StringTokenizer str = new StringTokenizer(vertexData, Constants.KV_SPLIT_FLAG);
    if (str.hasMoreElements()) {
        buffer[0] = str.nextToken();//from   w  w  w .j  a v a2  s . c  o  m
    } else {
        throw new Exception();
    }
    if (str.hasMoreElements()) {
        buffer[1] = str.nextToken();
    }
    str = new StringTokenizer(buffer[0], Constants.SPLIT_FLAG);
    if (str.countTokens() != 2) {
        throw new Exception();
    }
    this.vertexID = Integer.valueOf(str.nextToken());
    this.vertexValue = Float.valueOf(str.nextToken());
    if (buffer[1].length() > 0) { // There has edges.
        str = new StringTokenizer(buffer[1], Constants.SPACE_SPLIT_FLAG);
        while (str.hasMoreTokens()) {
            PREdgeLiteNew edge = new PREdgeLiteNew();
            edge.fromString(str.nextToken());
            this.edgesList.add(edge);
        }
    }
}