Example usage for java.lang CharSequence toString

List of usage examples for java.lang CharSequence toString

Introduction

In this page you can find the example usage for java.lang CharSequence toString.

Prototype

public String toString();

Source Link

Document

Returns a string containing the characters in this sequence in the same order as this sequence.

Usage

From source file:fr.landel.utils.commons.StringUtils.java

/**
 * Try to suffix the sequence//w w  w.  ja  v a  2  s .c om
 * 
 * @param sequence
 *            the sequence to suffix
 * @param suffix
 *            the suffix
 * @return the suffixed sequence
 * @throws NullPointerException
 *             if {@code sequence} or {@code suffix} are {@code null}
 */
public static String suffixIfNotEndsWith(final CharSequence sequence, final CharSequence suffix) {
    Objects.requireNonNull(sequence, ERROR_SEQUENCE);
    Objects.requireNonNull(suffix, ERROR_SUFFIX);

    int lSequence = sequence.length();
    int lSuffix = suffix.length();
    if (lSuffix == 0
            || (lSequence >= lSuffix && sequence.subSequence(lSequence - lSuffix, lSequence).equals(suffix))) {
        return sequence.toString();
    }
    return sequence.toString().concat(suffix.toString());
}

From source file:br.msf.commons.util.CharSequenceUtils.java

@SuppressWarnings("unchecked")
public static Set<String> listParams(final CharSequence sequence, final String startDelimiter,
        final String endDelimiter) {
    if (isBlankOrNull(sequence)) {
        return Collections.EMPTY_SET;
    }//from   w w w.  j  a va  2s. co  m
    String str = sequence.toString();
    int idx0 = str.indexOf(startDelimiter);
    if (idx0 < 0) {
        return Collections.EMPTY_SET;
    }

    Set<String> set = new HashSet<String>();
    while (idx0 >= 0) {
        int idx1 = str.indexOf(endDelimiter, idx0);
        if (idx1 <= idx0) {
            return set;
        }
        set.add(str.substring(idx0 + startDelimiter.length(), idx1));
        idx0 = str.indexOf(startDelimiter, idx1);
    }
    return set;
}

From source file:com.cyberway.issue.extractor.RegexpHTMLLinkExtractor.java

protected void processMeta(CharSequence cs) {
    Matcher attr = TextUtils.getMatcher(EACH_ATTRIBUTE_EXTRACTOR, cs);

    String name = null;//from  w w w .jav a2  s .c  om
    String httpEquiv = null;
    String content = null;

    while (attr.find()) {
        int valueGroup = (attr.start(12) > -1) ? 12 : (attr.start(13) > -1) ? 13 : 14;
        CharSequence value = cs.subSequence(attr.start(valueGroup), attr.end(valueGroup));
        if (attr.group(1).equalsIgnoreCase("name")) {
            name = value.toString();
        } else if (attr.group(1).equalsIgnoreCase("http-equiv")) {
            httpEquiv = value.toString();
        } else if (attr.group(1).equalsIgnoreCase("content")) {
            content = value.toString();
        }
        // TODO: handle other stuff
    }
    TextUtils.recycleMatcher(attr);

    // Look for the 'robots' meta-tag
    if ("robots".equalsIgnoreCase(name) && content != null) {
        if (getHonorRobots()) {
            String contentLower = content.toLowerCase();
            if ((contentLower.indexOf("nofollow") >= 0 || contentLower.indexOf("none") >= 0)) {
                // if 'nofollow' or 'none' is specified and we
                // are honoring robots, end html extraction
                logger.fine("HTML extraction skipped due to robots meta-tag for: " + source);
                cancelFurtherExtraction();
                return;
            }
        }
    } else if ("refresh".equalsIgnoreCase(httpEquiv) && content != null) {
        String refreshUri = content.substring(content.indexOf("=") + 1);
        try {
            Link refreshLink = new Link(source, UURIFactory.getInstance(base, refreshUri),
                    Link.elementContext("meta", httpEquiv), Link.REFER_HOP);
            next.addLast(refreshLink);
        } catch (URIException e) {
            extractErrorListener.noteExtractError(e, source, refreshUri);
        }
    }
}

From source file:br.msf.commons.util.CharSequenceUtils.java

public static List<String> split(final CharSequence sequence, final CharSequence regex,
        final boolean ignoreBlank) {
    if (isEmptyOrNull(regex)) {
        return split(sequence, (Pattern) null, ignoreBlank);
    } else {//from  w w w .  java  2s  . com
        return split(sequence, Pattern.compile(regex.toString()), ignoreBlank);
    }
}

From source file:edu.cornell.med.icb.pca.RotationReaderWriter.java

/**
 * Given the specified parameters, return the file where rotation information is stored.
 *
 * @param datasetEndpointName the dataset to find a table for
 * @param pathwayId          the pathwayId to find a table for
 * @return the file where rotation information is stored.
 *///from w w w  .  j  a va  2  s  .  c om
private String getRotationFile(CharSequence datasetEndpointName, MutableString pathwayId) {
    pathwayId = pathwayId.replace(' ', '_');
    pathwayId = pathwayId.replace('/', '_');
    datasetEndpointName = datasetEndpointName.toString().replace('/', '_');
    final String cachedTableFilename = String.format(S_CACHED_FILENAME, datasetEndpointName, splitId,
            pathwayId);
    LOG.trace("rotation filename:  " + cachedTableFilename);
    return cachedTableFilename;
}

From source file:com.mastercard.masterpasswallet.fragments.addcard.VerifyCardFragment.java

private void setupWidgetFormats() {

    // format the expiry date to mm/yy
    mEdtExpiry.addTextChangedListener(new TextWatcher() {
        @Override//  w w w .j av  a2  s.  com
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            String text = s.toString();

            int selection = mEdtExpiry.getSelectionStart();

            String pattern = "[0-9][0-9]\\/[0-9][0-9]";
            Pattern p = Pattern.compile(pattern);
            Matcher m = p.matcher(text);
            if (!m.find()) {
                // if they have typed the second character
                if (text.length() == 2 && before == 0) {
                    mEdtExpiry.setText(text + "/");
                    selection++;
                } else {
                    // remove anything that isn't a number
                    String cleanText = text.replaceAll("[^0-9.]", "");

                    // if the / will be added we need to increase the cursor position by 1
                    if (!text.contains("/")) {
                        selection++;
                    }

                    if (text.length() > 2) {
                        // format the starting numbers
                        text = cleanText.substring(0, 2) + "/" + cleanText.substring(2);

                    }

                    // make sure we only set the text if there are changes (otherwise we infinite loop)
                    if (!text.equals(s.toString())) {
                        // set the text
                        mEdtExpiry.setText(text);
                    }
                }
            }

            // don't allow the date to be greater than 5 characters (including the /)
            if (text.length() > 5) {
                mEdtExpiry.setText(text.substring(0, 5));
            }

            // make sure the cursor isn't moved out of bounds
            if (selection > mEdtExpiry.getText().length()) {
                selection = mEdtExpiry.getText().length();
            }

            // move the cursor back to where it was
            mEdtExpiry.setSelection(selection);
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
}

From source file:org.tradex.jdbc.JDBCHelper.java

/**
 * Batch executes the update define in the passed sql 
 * @param sql The sql//from   w w w . j a v  a 2s.  c  o  m
 * @param bindSets An array of bind value arrays
 * @return an array containing the numbers of rows affected by each update in the batch
 */
public int[] batchExecute(CharSequence sql, Object[]... bindSets) {
    NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(ds);
    SqlParameterSource[] sps = new SqlParameterSource[bindSets.length];
    for (int i = 0; i < bindSets.length; i++) {
        sps[i] = getBinds(sql.toString().trim().toUpperCase(), bindSets[i]);
    }
    return template.batchUpdate(sql.toString(), sps);
}

From source file:com.wso2.mobile.mdm.api.PhoneState.java

private JSONObject getDataUseReport(CharSequence name, TrafficRecord latest_rec, TrafficRecord previous_rec,
        ArrayList<String> rows) {
    JSONObject jsonObj = new JSONObject();
    if (latest_rec.rx > -1 || latest_rec.tx > -1) {
        StringBuilder buf = new StringBuilder(name);
        try {//from  ww  w .  j  a va  2  s . co m
            jsonObj.put("package", name);
            jsonObj.put("name", appList.getAppNameFromPackage(name.toString()));
            jsonObj.put("upload", formatSizeMB(latest_rec.tx));
            jsonObj.put("download", formatSizeMB(latest_rec.rx));
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        buf.append("=");
        buf.append(String.valueOf(latest_rec.rx));
        buf.append(" received");

        if (previous_rec != null) {
            buf.append(" (delta=");
            buf.append(String.valueOf(latest_rec.rx - previous_rec.rx));
            buf.append(")");
        }

        buf.append(", ");
        buf.append(String.valueOf(latest_rec.tx));
        buf.append(" sent");

        if (previous_rec != null) {
            buf.append(" (delta=");
            buf.append(String.valueOf(latest_rec.tx - previous_rec.tx));
            buf.append(")");
        }

        rows.add(buf.toString());
    }
    return jsonObj;
}

From source file:edu.cornell.med.icb.pca.RotationReaderWriter.java

private String getMapFile(CharSequence datasetEndpointName, MutableString pathwayId, final String mapType) {
    pathwayId = pathwayId.replace(' ', '_');
    pathwayId = pathwayId.replace('/', '_');
    datasetEndpointName = datasetEndpointName.toString().replace('/', '_');
    final String cachedTableFilename = String.format(S_MAP_FILENAME, datasetEndpointName, splitId, pathwayId,
            mapType);/*  www. j  ava 2s.  c o  m*/
    LOG.trace("map filename:  " + cachedTableFilename);
    return cachedTableFilename;
}