Example usage for java.util StringTokenizer nextToken

List of usage examples for java.util StringTokenizer nextToken

Introduction

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

Prototype

public String nextToken() 

Source Link

Document

Returns the next token from this string tokenizer.

Usage

From source file:com.helpers.ServiceLocationsHelper.java

public static void addLocationToOpportunity(String opportunityID, String locationID)
        throws ConnectionException {
    System.out.println("addLocationToOpportunity\t" + opportunityID + "\t" + locationID);

    String tempArr[] = locationID.split(Pattern.quote("***"));
    String addLocations = tempArr[0];
    String deleteLocations = tempArr.length > 1 ? tempArr[1] : null;

    StringTokenizer st = new StringTokenizer(addLocations, ",");

    List<Pricesenz__ServLocOppJn__c> locations = getLocationsForOpportunity(opportunityID);

    ArrayList<Pricesenz__ServLocOppJn__c> addList = new ArrayList<>();
    ArrayList<Pricesenz__ServLocOppJn__c> deleteList = new ArrayList<>();

    Pricesenz__ServLocOppJn__c tempJnObj;

    while (st.hasMoreTokens()) {
        boolean flag = true;
        String tempID = st.nextToken();
        for (Pricesenz__ServLocOppJn__c l : locations) {
            if (l.getId().equals(tempID)) {
                //                    System.out.println(tempID);
                flag = false;/* w  w  w .  j  av  a 2 s .  c  om*/
                break;
            }
        }
        if (flag) {
            tempJnObj = new Pricesenz__ServLocOppJn__c();
            tempJnObj.setPricesenz__Service_Location__c(tempID);
            tempJnObj.setPricesenz__Opportunity__c(opportunityID);
            addList.add(tempJnObj);
        }
    }
}

From source file:com.kcs.core.utilities.Utility.java

public static String[] split(String value, String delim) {
    if (value == null) {
        return new String[0];
    }//  w ww.j av  a 2s . co  m
    if (value.trim().equals("")) {
        return new String[0];
    }
    String[] ret = null;
    if (value.indexOf(delim) == -1) {
        ret = new String[1];
        ret[0] = value;
    } else {
        StringTokenizer stoken = new StringTokenizer(value, delim);
        ret = new String[stoken.countTokens()];
        int i = 0;
        while (stoken.hasMoreTokens()) {
            ret[i] = stoken.nextToken();
            i++;
        }
    }
    return ret;
}

From source file:com.openkm.dao.ConfigDAO.java

/**
 * Find by pk with a default value/*ww w .ja v  a2 s  . c om*/
 */
public static String getSelectedOption(String key, String value) throws DatabaseException {
    StringTokenizer st = new StringTokenizer(value, "|");
    ConfigStoredSelect stSelect = new ConfigStoredSelect();
    boolean selected = false;

    while (st.hasMoreTokens()) {
        String tk = st.nextToken().trim();
        ConfigStoredOption stOption = new ConfigStoredOption();

        if (tk.startsWith(ConfigStoredOption.SELECTED)) {
            stOption.setName(tk.substring(1));
            stOption.setValue(tk.substring(1));
            stOption.setSelected(true);
            selected = true;
        } else {
            stOption.setName(tk);
            stOption.setValue(tk);
            stOption.setSelected(false);
        }

        stSelect.getOptions().add(stOption);
    }

    // Set first option as default
    if (!selected && stSelect.getOptions().size() > 0) {
        stSelect.getOptions().get(0).setSelected(true);
    }

    String dbValue = getProperty(key, new Gson().toJson(stSelect), Config.SELECT);
    ConfigStoredSelect dbSelect = new Gson().fromJson(dbValue, ConfigStoredSelect.class);

    for (ConfigStoredOption option : dbSelect.getOptions()) {
        if (option.isSelected()) {
            return option.getValue();
        }
    }

    return "";
}

From source file:com.floreantpos.config.TerminalConfig.java

public static Locale getDefaultLocale() {
    String defaultLocaleString = config.getString(DEFAULT_LOCALE, null);
    if (StringUtils.isEmpty(defaultLocaleString)) {
        return null;
    }//from w  ww. j  av  a  2  s  .  c o  m
    String language = "";
    String country = "";
    String variant = "";
    StringTokenizer st = new StringTokenizer(defaultLocaleString, "_");
    if (st.hasMoreTokens())
        language = st.nextToken();
    if (st.hasMoreTokens())
        country = st.nextToken();
    if (st.hasMoreTokens())
        variant = st.nextToken();
    Locale disName = new Locale(language, country, variant);

    return disName;
}

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

public static final long parseDateDDMMYYYY(String str, boolean checkPast) throws IncorrectDateException {
    int year;//from w w w. j av  a 2 s.c  om
    int month;
    int day;

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

    StringTokenizer st = new StringTokenizer(str, ".");

    if (!st.hasMoreTokens()) {
        throw new IncorrectDateException("Day was not specified.");
    }

    String tempEl = st.nextToken();

    try {
        day = Integer.parseInt(tempEl);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Day parameter should be numeric.");
    }

    if ((day < MIN_DAY_VALUE) || (day > MAX_DAY_VALUE)) {
        throw new IncorrectDateException("Incorrect ranges for day (day should be >= " + MIN_DAY_VALUE
                + " and <= " + MAX_DAY_VALUE + ")");
    }

    if (!st.hasMoreTokens()) {
        throw new IncorrectDateException("Month was not specified.");
    }

    tempEl = st.nextToken();

    try {
        month = Integer.parseInt(tempEl);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Month parameter should be numeric.");
    }

    if ((month < MIN_MONTH_VALUE) || (month > MAX_MONTH_VALUE)) {
        throw new IncorrectDateException("Incorrect ranges for month (month should be >= " + MIN_MONTH_VALUE
                + " and <= " + MAX_MONTH_VALUE + ")");
    }

    if (!st.hasMoreTokens()) {
        throw new IncorrectDateException("Year was not specified.");
    }

    tempEl = st.nextToken();

    try {
        year = Integer.parseInt(tempEl);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Year parameter should be numeric.");
    }

    if ((year < MIN_YEAR_VALUE) || (year > MAX_YEAR_VALUE)) {
        throw new IncorrectDateException("Incorrect ranges for year (year should be >= " + MIN_YEAR_VALUE
                + " and <= " + MAX_YEAR_VALUE + ")");
    }

    Calendar cal = Calendar.getInstance();

    if (checkPast) {
        if (year < cal.get(Calendar.YEAR)) {
            throw new IncorrectDateException("Date should not refer to the past.");
        } else if (year == cal.get(Calendar.YEAR)) {
            if (month < (cal.get(Calendar.MONTH) + 1)) {
                throw new IncorrectDateException("Date should not refer to the past.");
            } else if (month == (cal.get(Calendar.MONTH) + 1)) {
                if (day < cal.get(Calendar.DAY_OF_MONTH)) {
                    throw new IncorrectDateException("Date should not refer to the past.");
                }
            }
        }
    }

    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DAY_OF_MONTH, day);

    return cal.getTime().getTime();
}

From source file:jenkins.plugins.testopia.TestopiaBuilder.java

/**
 * <p>Define properties. Following is the list of available properties.</p>
 * //from   w  ww  .  j  a v a 2  s .  c  o m
 * <ul>
 *     <li>xmlrpc.basicEncoding</li>
  *     <li>xmlrpc.basicPassword</li>
  *     <li>xmlrpc.basicUsername</li>
  *     <li>xmlrpc.connectionTimeout</li>
  *     <li>xmlrpc.contentLengthOptional</li>
  *     <li>xmlrpc.enabledForExceptions</li>
  *     <li>xmlrpc.encoding</li>
  *     <li>xmlrpc.gzipCompression</li>
  *     <li>xmlrpc.gzipRequesting</li>
  *     <li>xmlrpc.replyTimeout</li>
  *     <li>xmlrpc.userAgent</li>
 * </ul>
 * 
 * @param properties List of comma separated properties
 * @param listener Jenkins Build listener
 */
public static void setProperties(String properties, BuildListener listener) {
    if (StringUtils.isNotBlank(properties)) {
        final StringTokenizer tokenizer = new StringTokenizer(properties, ",");

        if (tokenizer.countTokens() > 0) {
            while (tokenizer.hasMoreTokens()) {
                String systemProperty = tokenizer.nextToken();
                maybeAddSystemProperty(systemProperty, listener);
            }
        }
    }
}

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

public static final long parseDateYYYYMMDD(String str, boolean checkPast) throws IncorrectDateException {
    int year;//from  w w w. j a  v  a2  s.  c  o m
    int month;
    int day;

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

    StringTokenizer st = new StringTokenizer(str, " -");

    if (!st.hasMoreTokens()) {
        throw new IncorrectDateException("Year was not specified.");
    }

    String tempEl = st.nextToken();

    try {
        year = Integer.parseInt(tempEl);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Year parameter should be numeric.");
    }

    if ((year < MIN_YEAR_VALUE) || (year > MAX_YEAR_VALUE)) {
        throw new IncorrectDateException("Incorrect ranges for year (year should be >= " + MIN_YEAR_VALUE
                + " and <= " + MAX_YEAR_VALUE + ")");
    }

    if (!st.hasMoreTokens()) {
        throw new IncorrectDateException("Month was not specified.");
    }

    tempEl = st.nextToken();

    try {
        month = Integer.parseInt(tempEl);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Month parameter should be numeric.");
    }

    if ((month < MIN_MONTH_VALUE) || (month > MAX_MONTH_VALUE)) {
        throw new IncorrectDateException("Incorrect ranges for month (month should be >= " + MIN_MONTH_VALUE
                + " and <= " + MAX_MONTH_VALUE + ")");
    }

    if (!st.hasMoreTokens()) {
        throw new IncorrectDateException("Day was not specified.");
    }

    tempEl = st.nextToken();

    try {
        day = Integer.parseInt(tempEl);
    } catch (NumberFormatException e) {
        throw new IncorrectDateException("Day parameter should be numeric.");
    }

    if ((day < MIN_DAY_VALUE) || (day > MAX_DAY_VALUE)) {
        throw new IncorrectDateException("Incorrect ranges for day (day should be >= " + MIN_DAY_VALUE
                + " and <= " + MAX_DAY_VALUE + ")");
    }

    Calendar cal = Calendar.getInstance();

    if (checkPast) {
        if (year < cal.get(Calendar.YEAR)) {
            throw new IncorrectDateException("Date should not refer to the past.");
        } else if (year == cal.get(Calendar.YEAR)) {
            if (month < (cal.get(Calendar.MONTH) + 1)) {
                throw new IncorrectDateException("Date should not refer to the past.");
            } else if (month == (cal.get(Calendar.MONTH) + 1)) {
                if (day < cal.get(Calendar.DAY_OF_MONTH)) {
                    throw new IncorrectDateException("Date should not refer to the past.");
                }
            }
        }
    }

    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DAY_OF_MONTH, day);

    return cal.getTime().getTime();
}

From source file:edu.stanford.muse.index.NEROld.java

public static void readLocationsWG() {
    try {//from   w  ww . j  a va 2 s .  c  o m
        InputStream is = new GZIPInputStream(
                NER.class.getClassLoader().getResourceAsStream("WG.locations.txt.gz"));
        LineNumberReader lnr = new LineNumberReader(new InputStreamReader(is, "UTF-8"));
        while (true) {
            String line = lnr.readLine();
            if (line == null)
                break;
            StringTokenizer st = new StringTokenizer(line, "\t");
            if (st.countTokens() == 4) {
                String locationName = st.nextToken();
                String canonicalName = locationName.toLowerCase();
                if (locationsToSuppress.contains(canonicalName))
                    continue;
                String lat = st.nextToken();
                String longi = st.nextToken();
                String pop = st.nextToken();
                long popl = Long.parseLong(pop);
                float latf = ((float) Integer.parseInt(lat)) / 100.0f;
                float longif = ((float) Integer.parseInt(longi)) / 100.0f;
                Long existingPop = populations.get(canonicalName);
                if (existingPop == null || popl > existingPop) {
                    populations.put(canonicalName, popl);
                    locations.put(canonicalName,
                            new LocationInfo(locationName, Float.toString(latf), Float.toString(longif)));
                }
            }
        }
    } catch (Exception e) {
        log.warn("Unable to read World Gazetteer file, places info may be inaccurate");
        log.debug(Util.stackTrace(e));
    }
}

From source file:com.lvwallpapers.utils.WebServiceUtils.java

public static List<Category> getAllCategory() {
    List<Category> listCategory = new ArrayList<Category>();

    List<String> listContain = new ArrayList<>();

    try {/*  ww w .j  ava2  s  . c o  m*/
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpPost = new HttpGet(getWebUrlGalleries());
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        String result = EntityUtils.toString(httpEntity);

        if (result != null && result.length() > 0) {
            JSONObject jobject = new JSONObject(result);
            String jsonPhotos = jobject.getString("galleries");

            JSONObject joPhotos = new JSONObject(jsonPhotos);

            String photos = joPhotos.getString("gallery");

            JSONArray joarray = new JSONArray(photos);

            for (int i = joarray.length() - 1; i >= 0; i--) {
                JSONObject jo = joarray.getJSONObject(i);

                String id = jo.getString("id");
                String title = jo.getString("title");
                String numOfPhotos = jo.getString("count_photos");
                int farm = jo.getInt("primary_photo_farm");
                String secret = jo.getString("primary_photo_secret");
                String server = jo.getString("primary_photo_server");
                String photoId = jo.getString("primary_photo_id");

                JSONObject joTitle = new JSONObject(title);
                String content = joTitle.getString("_content");

                StringTokenizer stringTokenizer = new StringTokenizer(content, "_");
                String categoryName = stringTokenizer.nextToken();
                String cateNo = stringTokenizer.nextToken();

                //

                if (!listContain.contains(categoryName)) {

                    listContain.add(categoryName);
                    Category category = new Category();
                    category.categoryName = categoryName;
                    if (cateNo.equalsIgnoreCase("0")) {
                        category.imageLink = "http://farm" + farm + ".staticflickr.com/" + server + "/"
                                + photoId + "_" + secret + "_b.jpg";

                    }
                    category.numOfPhotos = category.numOfPhotos + Integer.parseInt(numOfPhotos);

                    listCategory.add(category);

                } else {

                    for (int j = 0; j < listCategory.size(); j++) {
                        if (listCategory.get(j).categoryName.equalsIgnoreCase(categoryName)) {
                            if (cateNo.equalsIgnoreCase("0")) {
                                listCategory.get(j).imageLink = "http://farm" + farm + ".staticflickr.com/"
                                        + server + "/" + photoId + "_" + secret + "_b.jpg";
                            }
                            listCategory.get(j).numOfPhotos = listCategory.get(j).numOfPhotos
                                    + Integer.parseInt(numOfPhotos);
                            break;
                        }
                    }
                }

            }

        }
    } catch (Exception e) {
        e.printStackTrace();

    }

    return listCategory;

}

From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferable.java

public static void pasteStringLine(String s, SpreadSheet spreadsheet, int row0, int col0) {
    String valueS;/*from   w w w  . j  a va 2s . c o  m*/
    CommonSpreadSheetModel model = (CommonSpreadSheetModel) spreadsheet.getModel();
    String delim = "\t";
    StringTokenizer st = new StringTokenizer(s, delim, true);
    int col = col0, maxCol = spreadsheet.getColumnCount() - 1;
    FieldContext fieldContext = model.getFieldContext();
    boolean round = fieldContext.isRound();
    fieldContext.setRound(true);
    while (st.hasMoreTokens() && col <= maxCol) {
        valueS = st.nextToken();
        if (delim.equals(valueS))
            valueS = "";
        else if (st.hasMoreTokens())
            st.nextToken();
        try {
            model.setValueAt(valueS, row0, ++col);
        } catch (Exception e) {
        }
    }
    fieldContext.setRound(round);
}