Example usage for java.lang CharSequence subSequence

List of usage examples for java.lang CharSequence subSequence

Introduction

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

Prototype

CharSequence subSequence(int start, int end);

Source Link

Document

Returns a CharSequence that is a subsequence of this sequence.

Usage

From source file:com.cloudera.oryx.kmeans.serving.web.DistanceToNearestServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    CharSequence pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
        return;/*from  ww  w .  ja  v a 2  s .  c o m*/
    }
    String line = pathInfo.subSequence(1, pathInfo.length()).toString();

    Generation generation = getGenerationManager().getCurrentGeneration();
    if (generation == null) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
                "API method unavailable until model has been built and loaded");
        return;
    }

    String[] tokens = DelimitedDataUtils.decode(line);
    RealVector vector = generation.toVector(tokens);
    if (vector == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count");
        return;
    }
    double distance = findClosest(generation, vector).getSquaredDistance();
    response.getWriter().write(Double.toString(distance));
}

From source file:com.none.tom.simplerssreader.view.ReadMoreTextView.java

@SuppressWarnings("SameParameterValue")
public void setText(final CharSequence text, final int maxEms) {
    if (!TextUtils.isEmpty(text) && text.length() > maxEms) {
        final SpannableStringBuilder ssb = new SpannableStringBuilder(text.subSequence(0, maxEms));

        ssb.append('\u2026');

        final int textLength = ssb.length();

        ssb.append('\n');
        ssb.append(getContext().getString(R.string.read_more));

        final int readMoreLength = ssb.length() - textLength;

        ssb.setSpan(new ReadMoreClickableSpan(), textLength, textLength + readMoreLength,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        super.setText(ssb);

        setMaxEms(maxEms + readMoreLength);
        setMovementMethod(LinkMovementMethod.getInstance());

        mText = text;/*  w  ww  .  j  ava 2s. c o  m*/
    } else {
        super.setText(text);
    }
}

From source file:org.sufficientlysecure.keychain.ui.widget.EncryptKeyCompletionView.java

@Override
protected void performFiltering(@NonNull CharSequence text, int start, int end, int keyCode) {
    //        super.performFiltering(text, start, end, keyCode);
    String query = text.subSequence(start, end).toString();
    if (TextUtils.isEmpty(query) || query.length() < 2) {
        mAdapter.swapCursor(null);//from w ww  .j a v a  2s  . c  om
        return;
    }
    Bundle args = new Bundle();
    args.putString(ARG_QUERY, query);
    mLoaderManager.restartLoader(0, args, this);
}

From source file:org.apache.james.jdkim.tagvalue.SignatureRecordImpl.java

public static String dkimQuotedPrintableDecode(CharSequence input) throws IllegalArgumentException {
    StringBuilder sb = new StringBuilder(input.length());
    // TODO should we fail on WSP that is not part of FWS?
    // the specification in 2.6 DKIM-Quoted-Printable is not
    // clear/*from   w  w  w.j av  a2 s.  c o  m*/
    int state = 0;
    int start = 0;
    int d = 0;
    boolean lastWasNL = false;
    for (int i = 0; i < input.length(); i++) {
        if (lastWasNL && input.charAt(i) != ' ' && input.charAt(i) != '\t') {
            throw new IllegalArgumentException("Unexpected LF not part of an FWS");
        }
        lastWasNL = false;
        switch (state) {
        case 0:
            switch (input.charAt(i)) {
            case ' ':
            case '\t':
            case '\r':
            case '\n':
                if ('\n' == input.charAt(i))
                    lastWasNL = true;
                sb.append(input.subSequence(start, i));
                start = i + 1;
                // ignoring whitespace by now.
                break;
            case '=':
                sb.append(input.subSequence(start, i));
                state = 1;
                break;
            }
            break;
        case 1:
        case 2:
            if (input.charAt(i) >= '0' && input.charAt(i) <= '9'
                    || input.charAt(i) >= 'A' && input.charAt(i) <= 'F') {
                int v = Arrays.binarySearch("0123456789ABCDEF".getBytes(), (byte) input.charAt(i));
                if (state == 1) {
                    state = 2;
                    d = v;
                } else {
                    d = d * 16 + v;
                    sb.append((char) d);
                    state = 0;
                    start = i + 1;
                }
            } else {
                throw new IllegalArgumentException("Invalid input sequence at " + i);
            }
        }
    }
    if (state != 0) {
        throw new IllegalArgumentException("Invalid quoted printable termination");
    }
    sb.append(input.subSequence(start, input.length()));
    return sb.toString();
}

From source file:net.sourceforge.ajaxtags.helpers.AbstractHTMLElement.java

/**
 * @param csq/*from w w  w. j  a v a  2 s. co  m*/
 *            the char sequence
 * @param start
 *            the start index
 * @param end
 *            the end index
 * @return self
 */
public final AbstractHTMLElement append(final CharSequence csq, final int start, final int end) {
    return append(csq.subSequence(start, end));
}

From source file:org.cleverbus.common.Strings.java

/**
 * @param input the {@link CharSequence} to be trimmed
 * @return the trimmed char sequence//from   ww w  .  j  a v a 2  s.  co m
 * @since 3.8.2
 */
@Nullable
public static CharSequence trim(@Nullable CharSequence input) {
    if (input == null) {
        return null;
    }

    if (input.length() == 0) {
        return input;
    }

    if (input instanceof String) {
        return ((String) input).trim();
    }

    int count = input.length();
    int len = count;
    int st = 0;
    int off = 0;

    while ((st < len) && (input.charAt(off + st) <= ' ')) {
        st++;
    }
    while ((st < len) && (input.charAt((off + len) - 1) <= ' ')) {
        len--;
    }

    if ((st == 0) && (input instanceof StringBuilder)) {
        ((StringBuilder) input).setLength(len);
        return input;
    }

    return ((st > 0) || (len < count)) ? input.subSequence(st, len) : input;
}

From source file:org.apache.hadoop.streaming.StreamBaseRecordReader.java

String getStatus(CharSequence record) {
    long pos = -1;
    try {//from  ww  w  .  j a va  2 s  .  co m
        pos = getPos();
    } catch (IOException io) {
    }
    String recStr;
    if (record.length() > statusMaxRecordChars_) {
        recStr = record.subSequence(0, statusMaxRecordChars_) + "...";
    } else {
        recStr = record.toString();
    }
    String unqualSplit = split_.getPath().getName() + ":" + split_.getStart() + "+" + split_.getLength();
    String status = "HSTR " + StreamUtil.HOST + " " + numRec_ + ". pos=" + pos + " " + unqualSplit
            + " Processing record=" + recStr;
    status += " " + splitName_;
    return status;
}

From source file:org.apache.hadoop.streaming.mapreduce.StreamBaseRecordReader.java

String getStatus(CharSequence record) {
    long pos = -1;
    try {// w ww.  j  a  v  a 2s.  com
        pos = getPos();
    } catch (IOException io) {
    }
    String recStr;
    if (record.length() > statusMaxRecordChars_) {
        recStr = record.subSequence(0, statusMaxRecordChars_) + "...";
    } else {
        recStr = record.toString();
    }
    String unqualSplit = split_.getPath().getName() + ":" + split_.getStart() + "+" + split_.getLength();
    String status = "HSTR " + StreamUtil.getHost() + " " + numRec_ + ". pos=" + pos + " " + unqualSplit
            + " Processing record=" + recStr;
    status += " " + splitName_;
    return status;
}

From source file:org.archive.modules.forms.ExtractorHTMLForms.java

/**
 * Run analysis: find form METHOD, ACTION, and all INPUT names/values
 * //from w  w w  . j  a  va  2s .c o  m
 * Log as configured. 
 * 
 * @param curi CrawlURI we're processing.
 * @param cs Sequence from underlying ReplayCharSequence. This
 * is TRANSIENT data. Make a copy if you want the data to live outside
 * of this extractors' lifetime.
 */
protected void analyze(CrawlURI curi, CharSequence cs) {
    for (Object offset : curi.getDataList(ExtractorHTML.A_FORM_OFFSETS)) {
        int offsetInt = (Integer) offset;
        CharSequence relevantSequence = cs.subSequence(offsetInt, cs.length());
        String method = findAttributeValueGroup("(?i)^[^>]*\\smethod\\s*=\\s*([^>\\s]+)[^>]*>", 1,
                relevantSequence);
        String action = findAttributeValueGroup("(?i)^[^>]*\\saction\\s*=\\s*([^>\\s]+)[^>]*>", 1,
                relevantSequence);
        String enctype = findAttributeValueGroup("(?i)^[^>]*\\senctype\\s*=\\s*([^>\\s]+)[^>]*>", 1,
                relevantSequence);
        HTMLForm form = new HTMLForm();
        form.setMethod(method);
        form.setAction(action);
        form.setEnctype(enctype);
        for (CharSequence input : findGroups("(?i)(<input\\s[^>]*>)|(</?form>)", 1, relevantSequence)) {
            String type = findAttributeValueGroup("(?i)^[^>]*\\stype\\s*=\\s*([^>\\s]+)[^>]*>", 1, input);
            String name = findAttributeValueGroup("(?i)^[^>]*\\sname\\s*=\\s*([^>\\s]+)[^>]*>", 1, input);
            String value = findAttributeValueGroup("(?i)^[^>]*\\svalue\\s*=\\s*([^>\\s]+)[^>]*>", 1, input);
            Matcher m = TextUtils.getMatcher("(?i)^[^>]*\\schecked\\s*[^>]*>", input);
            boolean checked = false;
            try {
                checked = m.find();
            } finally {
                TextUtils.recycleMatcher(m);
            }
            form.addField(type, name, value, checked);
        }
        if (form.seemsLoginForm() || getExtractAllForms()) {
            curi.getDataList(A_HTML_FORM_OBJECTS).add(form);
            curi.getAnnotations().add(form.asAnnotation());
        }
    }
}

From source file:org.shredzone.cilla.plugin.flattr.FlattrPublicationServiceImpl.java

/**
 * Prepares a {@link CharSequence}. Strips all HTML and limits its length to the given
 * maximum length.//ww w.j a v  a  2 s.c  om
 *
 * @param str
 *            {@link CharSequence} to prepare
 * @param maxlen
 *            maximum length
 * @return prepared {@link CharSequence}
 */
private CharSequence prepare(CharSequence str, int maxlen) {
    CharSequence result = textFormatter.stripHtml(str.toString().trim());
    if (result.length() > maxlen) {
        return result.subSequence(0, maxlen);
    } else {
        return result;
    }
}