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:io.hops.leaderElection.experiments.ExperimentDriver.java

private void runCommands(String file) throws FileNotFoundException, IOException, InterruptedException {
    if (!new File(file).exists()) {
        LOG.error("File Does not exists");
        return;//www  .ja v a2 s  .com
    }

    BufferedReader br = new BufferedReader(new FileReader(file));
    String line;
    while ((line = br.readLine()) != null) {
        if (line.startsWith("#") || line.trim().isEmpty()) {
            continue;
        }

        StringTokenizer st = new StringTokenizer(line, " ");
        int numProcesses = -1;
        String timeToRep = st.nextToken();
        int timesToRepeat = Integer.parseInt(timeToRep);
        line = line.substring(timeToRep.length(), line.length());
        String outputFileName = null;

        while (st.hasMoreElements()) {
            if (st.nextElement().equals("-max_processes")) {
                numProcesses = Integer.parseInt(st.nextToken());
                outputFileName = numProcesses + ".log";
                break;
            }
        }
        LOG.info("Going to repeat the experiment of " + timesToRepeat + " times");
        for (int i = 0; i < timesToRepeat; i++) { // run command 10 times
            String command = line + " -output_file_path " + outputFileName;
            LOG.info("Driver going to run command " + command);
            runCommand(command);
        }

        LOG.info("Going to calculate points from file " + outputFileName);
        calculateNumbers(numProcesses, outputFileName);
    }
    br.close();
}

From source file:mobi.jenkinsci.net.UrlPath.java

public UrlPath(String requestedPath) {
    this.requestPath = requestedPath;

    if (requestedPath == null || requestedPath.trim().length() <= 0) {
        requestedPath = "/";
    } else if (requestedPath.startsWith("http")) {
        requestedPath = getUriRequestPath(requestedPath);
    } else if (!requestedPath.startsWith("/")) {
        requestedPath = "/" + requestedPath;
    }/*from  w  ww. ja v a 2  s.  co m*/

    this.path = requestedPath;
    final StringTokenizer tokens = new StringTokenizer(path, "/");
    components = new LinkedList<String>();
    String nextToken;
    while (tokens.hasMoreTokens()) {
        nextToken = tokens.nextToken();
        if (nextToken != null) {
            components.add(nextToken);
        }
    }

    if (components.size() > 0) {
        isRootPath = components.size() == 1 && components.get(0).startsWith("_");
        depth = calculateDepth();
        path = removeDepthSuffix();
    } else {
        isRootPath = true;
        depth = SINGLE_NODE_ONLY;
    }
}

From source file:net.ripe.rpki.commons.util.VersionedId.java

public static VersionedId parse(String s) {
    Validate.notNull(s, "string required");
    StringTokenizer tokenizer = new StringTokenizer(s, ":");
    int count = tokenizer.countTokens();
    Validate.isTrue(count == 1 || count == 2, "invalid number of tokens in versioned id");
    long id = Long.parseLong(tokenizer.nextToken());
    long version;
    if (tokenizer.hasMoreTokens()) {
        version = Long.parseLong(tokenizer.nextToken());
    } else {//from  w  ww.  jav a2 s  .c om
        version = 0;
    }
    return new VersionedId(id, version);
}

From source file:com.glaf.report.web.springmvc.MxReportFileController.java

@RequestMapping("/delete")
public ModelAndView delete(HttpServletRequest request, ModelMap modelMap) {

    Map<String, Object> params = RequestUtils.getParameterMap(request);
    String reportFileId = ParamUtils.getString(params, "reportFileId");
    String reportFileIds = request.getParameter("reportFileIds");
    if (StringUtils.isNotEmpty(reportFileIds)) {
        StringTokenizer token = new StringTokenizer(reportFileIds, ",");
        while (token.hasMoreTokens()) {
            String x = token.nextToken();
            if (StringUtils.isNotEmpty(x)) {
                ReportFile reportFile = reportFileService.getReportFile(x);
                if (reportFile != null) {

                    reportFileService.save(reportFile);
                }//from  w ww  . j  a  v a2s.c  o m
            }
        }
    } else if (StringUtils.isNotEmpty(reportFileId)) {
        ReportFile reportFile = reportFileService.getReportFile(reportFileId);
        if (reportFile != null) {

            reportFileService.save(reportFile);
        }
    }

    return this.list(request, modelMap);
}

From source file:com.glaf.oa.traveladdress.web.springmvc.TraveladdressController.java

@ResponseBody
@RequestMapping("/delete")
public void delete(HttpServletRequest request, ModelMap modelMap) {
    Long addressid = RequestUtils.getLong(request, "addressid");
    String addressids = request.getParameter("addressids");
    if (StringUtils.isNotEmpty(addressids)) {
        StringTokenizer token = new StringTokenizer(addressids, ",");
        while (token.hasMoreTokens()) {
            String x = token.nextToken();
            if (StringUtils.isNotEmpty(x)) {
                Traveladdress traveladdress = traveladdressService.getTraveladdress(Long.valueOf(x));
                /**//from w w  w  . j a v  a2 s  .  c o m
                 * 
                 */
                if (traveladdress != null) {
                    // traveladdress.setDeleteFlag(1);
                    traveladdressService.deleteById(Long.valueOf(x));
                }
            }
        }
    } else if (addressid != null) {
        Traveladdress traveladdress = traveladdressService.getTraveladdress(Long.valueOf(addressid));
        /**
         * 
         */
        if (traveladdress != null) {
            // traveladdress.setDeleteFlag(1);
            traveladdressService.deleteById(addressid);
        }
    }
}

From source file:de.mg.stock.server.update.StockUpdateFromYahooHistorical.java

@Override
public List<DayPrice> get(String symbol) {

    LocalDateTime fetchTime = dateTimeProvider.now();

    String response = httpUtil.get("https://ichart.yahoo.com/table.csv?s=" + symbol);
    if (isEmpty(response)) {
        logger.warning("nothing received for " + symbol);
        return Collections.emptyList();
    }/*from  w  w w .  j  a  v a  2s .  c  o  m*/

    String[] lines = response.split(System.getProperty("line.separator"));
    if (lines.length < 2) {
        logger.warning("no lines received for " + symbol);
        return Collections.emptyList();
    }
    if (!"Date,Open,High,Low,Close,Volume,Adj Close".equals(lines[0])) {
        logger.warning("wrong header for " + symbol + ": " + lines[0]);
        return Collections.emptyList();
    }

    List<DayPrice> result = new ArrayList<>();

    for (int i = 1; i < lines.length; i++) {
        StringTokenizer tok = new StringTokenizer(lines[i], ",");
        LocalDate date = toLocalDate(tok.nextToken(), "yyyy-MM-dd");
        DayPrice dayPrice = new DayPrice(date);

        // skip
        tok.nextToken();

        dayPrice.setMax(toLong(tok.nextToken()));
        dayPrice.setMin(toLong(tok.nextToken()));

        dayPrice.setFetchedAt(fetchTime);

        if (dayPrice.getMax() != null && dayPrice.getMin() != null && dayPrice.getMax() != 0
                && dayPrice.getMin() != 0)
            result.add(dayPrice);
    }

    return result;
}

From source file:gov.nasa.ensemble.common.ERGBUtils.java

/**
 * COPIED FROM org.eclipse.jface.resource.StringConverter
 * /*w  ww.ja  v a 2 s  .  c om*/
 * Converts the given value into an SWT RGB color value.
 * This method fails if the value does not represent an RGB
 * color value.
 * <p>
 * A valid RGB color value representation is a string of the form
 * <code><it>red</it>,<it>green</it></code>,<it>blue</it></code> where
 * <code><it>red</it></code>, <it>green</it></code>, and 
 * <code><it>blue</it></code> are valid ints.
 * </p>
 *
 * @param value the value to be converted
 * @return the value as an RGB color value
 * @exception DataFormatException if the given value does not represent
 *   an RGB color value
 */
private static ERGB asRGB(String value) throws DataFormatException {
    if (value == null) {
        throw new DataFormatException("Null doesn't represent a valid RGB"); //$NON-NLS-1$
    }
    StringTokenizer stok = new StringTokenizer(value, ","); //$NON-NLS-1$

    try {
        String red = stok.nextToken().trim();
        String green = stok.nextToken().trim();
        String blue = stok.nextToken().trim();
        int rval = 0, gval = 0, bval = 0;
        try {
            rval = Integer.parseInt(red);
            gval = Integer.parseInt(green);
            bval = Integer.parseInt(blue);
        } catch (NumberFormatException e) {
            throw new DataFormatException(e.getMessage());
        }
        return new ERGB(rval, gval, bval);
    } catch (NoSuchElementException e) {
        throw new DataFormatException(e.getMessage());
    }
}

From source file:com.dx.ss.plugins.ptree.main.MavenShellCallback.java

public File getDirectory(String targetProject, String targetPackage) {
    // targetProject is interpreted as a directory that must exist
    ///*from w  ww  . j  av  a2s .  c o  m*/
    // targetPackage is interpreted as a sub directory, but in package
    // format (with dots instead of slashes). The sub directory will be
    // created
    // if it does not already exist
    if (!"MAVEN".equals(targetProject)) {
        return super.getDirectory(targetProject, targetPackage);
    }

    // targetProject is the output directory from the MyBatis generator
    // Mojo. It will be created if necessary
    //
    // targetPackage is interpreted as a sub directory, but in package
    // format (with dots instead of slashes).  The sub directory will be created
    // if it does not already exist

    File project = pTreeGeneratorMojo.getOutputDirectory();
    if (!project.exists()) {
        project.mkdirs();
    }

    StringBuilder sb = new StringBuilder();
    if (!StringUtils.isBlank(targetPackage)) {
        StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$
        while (st.hasMoreTokens()) {
            sb.append(st.nextToken());
            sb.append(File.separatorChar);
        }
    }

    File directory = new File(project, sb.toString());
    if (!directory.isDirectory()) {
        boolean rc = directory.mkdirs();
        if (!rc)
            return null;
    }

    return directory;
}

From source file:net.sf.jabref.exporter.layout.WSITools.java

/**
 * @param  vcr       {@link java.util.Vector} of <tt>String</tt>
 * @param  s         Description of the Parameter
 * @param  delimstr  Description of the Parameter
 * @param  limit     Description of the Parameter
 * @return           Description of the Return Value
 */// w  ww  . j  av a  2  s  .  c  o m
public static boolean tokenize(Vector<String> vcr, String s, String delimstr, int limit) {
    LOGGER.warn("Tokenize \"" + s + '"');
    vcr.clear();
    s = s + '\n';

    int endpos;
    int matched = 0;

    StringTokenizer st = new StringTokenizer(s, delimstr);

    while (st.hasMoreTokens()) {
        String tmp = st.nextToken();
        vcr.add(tmp);

        matched++;

        if (matched == limit) {
            endpos = s.lastIndexOf(tmp);
            vcr.add(s.substring(endpos + tmp.length()));

            break;
        }
    }

    return true;
}

From source file:com.glaf.oa.travelpersonnel.web.springmvc.TravelpersonnelController.java

@ResponseBody
@RequestMapping("/delete")
public void delete(HttpServletRequest request, ModelMap modelMap) {
    Long personnelid = RequestUtils.getLong(request, "personnelid");
    String personnelids = request.getParameter("personnelids");
    if (StringUtils.isNotEmpty(personnelids)) {
        StringTokenizer token = new StringTokenizer(personnelids, ",");
        while (token.hasMoreTokens()) {
            String x = token.nextToken();
            if (StringUtils.isNotEmpty(x)) {
                Travelpersonnel travelpersonnel = travelpersonnelService.getTravelpersonnel(Long.valueOf(x));
                /**//from w w  w  .  j a  va  2  s  .c  o  m
                 * 
                 */
                if (travelpersonnel != null) {
                    // travelpersonnel.setDeleteFlag(1);
                    travelpersonnelService.deleteById(Long.valueOf(x));
                }
            }
        }
    } else if (personnelid != null) {
        Travelpersonnel travelpersonnel = travelpersonnelService.getTravelpersonnel(personnelid);
        /**
         * 
         */
        if (travelpersonnel != null) {
            // travelpersonnel.setDeleteFlag(1);
            travelpersonnelService.deleteById(personnelid);
        }
    }
}