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:de.mg.stock.server.update.StockUpdateFromGoogleHistorical.java

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

    String shortSymbol = symbol.substring(0, symbol.lastIndexOf('.'));

    LocalDateTime fetchTime = dateTimeProvider.now();

    String response = httpUtil.get(
            "http://www.google.com/finance/historical?output=csv&startdate=Jan+1%2C+2000&q=" + shortSymbol);
    if (isEmpty(response)) {
        logger.warning("nothing received for " + shortSymbol);
        return Collections.emptyList();
    }/*from w  ww  . j  a  v  a  2 s  .c o  m*/

    String[] lines = response.split(System.getProperty("line.separator"));
    if (lines.length < 2) {
        logger.warning("no lines received for " + shortSymbol);
        return Collections.emptyList();
    }
    if (!lines[0].contains("Date,Open,High,Low,Close,Volume")) {
        logger.warning("wrong header for " + shortSymbol + ": " + 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(), "dd-MMMM-yy", Locale.ENGLISH);
        DayPrice dayPrice = new DayPrice(date);
        dayPrice.setFetchedAt(fetchTime);

        // skip
        tok.nextToken();

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

        Long close = toLong(tok.nextToken());
        if (dayPrice.getMax() == null)
            dayPrice.setMax(close);
        if (dayPrice.getMin() == null)
            dayPrice.setMin(close);

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

    return result;
}

From source file:com.moviejukebox.plugin.MovieListingPluginCustomCsv.java

/**
 * Take a comma-separated list of field names and split them into separate fields
 *
 * @param aFields Text to split// www. ja  v  a2s  . c om
 * @return Number of fields found
 */
private int initFields(String aFields) {
    // Clear the current list (if there is one)
    mFields = new ArrayList<>();

    for (StringTokenizer t = new StringTokenizer(aFields, ","); t.hasMoreTokens();) {
        String st = StringUtils.trimToNull(t.nextToken());
        if (st != null) {
            mFields.add(st);
        }
    }
    return mFields.size();
}

From source file:org.globus.security.authorization.xml.AbstractBeanDefinitionParser.java

protected String getIdOrName(Element elem) {
    String id = elem.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);

    if (null == id || "".equals(id)) {
        String names = elem.getAttribute("name");
        if (null != names) {
            StringTokenizer st = new StringTokenizer(names, BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS);
            if (st.countTokens() > 0) {
                id = st.nextToken();//from w w  w .ja  v a2s. co m
            }
        }
    }
    return id;
}

From source file:com.smartmarmot.orabbix.Configurator.java

private static Query[] getQueries(String parameter, Properties _propsq) throws Exception {
    try {/* w  w  w .ja  v  a 2  s. c om*/
        StringTokenizer stq = new StringTokenizer(_propsq.getProperty(parameter), Constants.DELIMITER);
        String[] QueryLists = new String[stq.countTokens()];
        int count = 0;
        while (stq.hasMoreTokens()) {
            String token = stq.nextToken().toString().trim();
            QueryLists[count] = token;
            count++;
        }

        Collection<Query> Queries = new ArrayList<Query>();
        for (int i = 0; i < QueryLists.length; i++) {
            try {
                Query q = getQueryProperties(_propsq, QueryLists[i]);
                Queries.add(q);
            } catch (Exception e1) {
                SmartLogger.logThis(Level.ERROR,
                        "Error on Configurator on reading query " + QueryLists[i] + e1);
                SmartLogger.logThis(Level.INFO, "Query " + QueryLists[i] + " skipped due to error " + e1);

            }
        }
        Query[] queries = (Query[]) Queries.toArray(new Query[0]);
        return queries;
    } catch (Exception ex) {

        SmartLogger.logThis(Level.ERROR,
                "Error on Configurator on reading properties file " + _propsq.toString() + " getQueries("
                        + parameter + "," + _propsq.toString() + ") " + ex.getMessage());
        return null;
    }

}

From source file:gov.nih.nci.cacisweb.util.LoggableStatement.java

public String toString() {
    StringTokenizer st = new StringTokenizer(sqlTemplate, "?");
    int count = 1;
    // System.out.println("Size of parameterValues in LoggableStatement === "
    // + parameterValues.size());
    // System.out.println("Size of tokens in LoggableStatement === " +
    // st.countTokens());
    StringBuffer statement = new StringBuffer();
    while (st.hasMoreTokens()) {
        statement.append(st.nextToken());
        if (count < parameterValues.size()) {
            if (parameterValues.get(count) != null && parameterValues.get(count).toString().length() > 0) {
                statement.append(parameterValues.get(count).toString());
            } else {
                statement.append("? " + "(missing variable # " + count + " ) ");
            }//from w  w  w  .j  a  v  a  2s  . c om
        }
        count++;
    }
    return statement.toString();
}

From source file:net.sf.ehcache.distribution.JNDIManualRMICacheManagerPeerProviderFactory.java

/**
 * peerDiscovery=manual, //from ww  w . j a v  a 2 s. c o  m
 * jndiUrls=//hostname:port/cacheName //hostname:port/cacheName
 * The jndiUrls are in the format expected by the implementation of your Context.INITIAL_CONTEXT_FACTORY.
 */
protected CacheManagerPeerProvider createManuallyConfiguredCachePeerProvider(Properties properties) {
    String urls = PropertyUtil.extractAndLogProperty(JNDI_URLS, properties);
    if (urls == null || urls.length() == 0) {
        throw new CacheException(JNDI_URLS + " must be specified when peerDiscovery is manual");
    }

    boolean stashContexts = isStashContexts(properties);
    boolean stashRemoteCachePeers = isStashRemoteCachePeers(properties);

    JNDIManualRMICacheManagerPeerProvider jndiPeerProvider = new JNDIManualRMICacheManagerPeerProvider(
            stashContexts, stashRemoteCachePeers);
    urls = urls.trim();
    StringTokenizer stringTokenizer = new StringTokenizer(urls, PayloadUtil.URL_DELIMITER);
    while (stringTokenizer.hasMoreTokens()) {
        String jndiUrl = stringTokenizer.nextToken();
        jndiUrl = jndiUrl.trim();
        jndiPeerProvider.registerPeer(jndiUrl);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Registering peer " + jndiUrl);
        }
    }
    return jndiPeerProvider;
}

From source file:net.rim.ejde.internal.legacy.Util.java

static public List<String> getSources(Project proj) {
    List<String> sources = new ArrayList<String>();
    String udata = proj.getUserData();

    StringTokenizer st = new StringTokenizer(udata, "|");
    String token;//w  w  w . j a v  a2s.  c  o  m

    while (st.hasMoreElements()) {
        token = st.nextToken();
        if (StringUtils.isNotBlank(token)) {
            sources.add(token);
        }
    }

    return sources;
}

From source file:com.adsapient.shared.service.TimeService.java

public static final boolean isInBlockTime(String beginTime, String endTime) throws IncorrectDateException {
    int beginHour;
    int endHour;// www .j a  va  2 s .  c om
    int beginMinute;
    int endMinute;

    Calendar calendar = Calendar.getInstance();
    int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
    int currentMinute = calendar.get(Calendar.MINUTE);

    if (StringUtils.isEmpty(beginTime) | StringUtils.isEmpty(endTime)) {
        throw new IncorrectDateException("Date string is empty.");
    }

    StringTokenizer begin = new StringTokenizer(beginTime, ":");
    StringTokenizer end = new StringTokenizer(endTime, ":");

    if (!begin.hasMoreTokens()) {
        throw new IncorrectDateException("Begin time was not specified.");
    }

    if (!end.hasMoreTokens()) {
        throw new IncorrectDateException("End time was not specified.");
    }

    String tempBH = begin.nextToken();
    String tempEH = end.nextToken();

    try {
        beginHour = Integer.parseInt(tempBH);
        endHour = Integer.parseInt(tempEH);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Year parameter should be numeric.");
    }

    String tempBM = begin.nextToken();
    String tempEM = end.nextToken();

    try {
        beginMinute = Integer.parseInt(tempBM);
        endMinute = Integer.parseInt(tempEM);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Year parameter should be numeric.");
    }

    System.out.println("cur hour" + currentHour + "  curr min" + currentMinute);
    System.out.println("begin time" + beginHour + "  begin min" + beginMinute);

    if ((currentHour > beginHour) | ((currentHour == beginHour) & (currentMinute > beginMinute))) {
        if ((currentHour < endHour) | ((currentHour == endHour) & (currentMinute < endMinute))) {
            return true;
        }
    }

    return false;
}

From source file:com.alvermont.terraj.fracplanet.io.ColourFile.java

private static FloatRGBA parseColour(String line) throws IOException {
    final StringTokenizer tok = new StringTokenizer(line, ",");

    if (tok.countTokens() != 3) {
        throw new IOException("Line should be in the form x,y,z: " + line);
    }//from   w w w .  j a va2  s . co m

    final float[] floats = new float[3];

    for (int b = 0; b < 3; ++b)
        floats[b] = Float.parseFloat(tok.nextToken().trim());

    return new FloatRGBA(floats[0], floats[1], floats[2]);
}

From source file:com.meterware.httpunit.HttpUnitUtils.java

/**
 * Returns the content type and encoding as a pair of strings.
 * If no character set is specified, the second entry will be null.
 * @param header the header to parse/* ww w. ja v a 2  s  .co m*/
 * @return a string array with the content type and the content charset
 **/
public static String[] parseContentTypeHeader(String header) {
    String[] result = new String[] { "text/plain", null };
    StringTokenizer st = new StringTokenizer(header, ";=");
    result[0] = st.nextToken();
    while (st.hasMoreTokens()) {
        String parameter = st.nextToken();
        if (st.hasMoreTokens()) {
            String value = stripQuotes(st.nextToken());
            if (parameter.trim().equalsIgnoreCase("charset")) {
                result[1] = value;
            }
        }
    }
    return result;
}