Example usage for java.lang CharSequence length

List of usage examples for java.lang CharSequence length

Introduction

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

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:org.ttrssreader.utils.Utils.java

public static String getTextFromClipboard(Context context) {
    // New Clipboard API
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard.hasPrimaryClip()) {

        if (!clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN))
            return null;

        ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
        CharSequence chars = item.getText();
        if (chars != null && chars.length() > 0) {
            return chars.toString();
        } else {//from  ww w .j  a  v a 2s .  com
            Uri pasteUri = item.getUri();
            if (pasteUri != null) {
                return pasteUri.toString();
            }
        }
    }
    return null;
}

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

public static String escapeHtml(CharSequence text) {
    if (text == null)
        return null;

    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < text.length(); i++) {
        char c = text.charAt(i);

        if (c == '<')
            builder.append("&lt;");
        else if (c == '>')
            builder.append("&gt;");
        else if (c == '&')
            builder.append("&amp;");
        else/*from www . j av  a  2s . c om*/
            builder.append(c);

    }
    return builder.toString();
}

From source file:de.undercouch.citeproc.helper.Levenshtein.java

/**
 * Searches the given collection of strings and returns a collection of
 * strings similar to a given string <code>t</code>. Uses reasonable default
 * values for human-readable strings. The returned collection will be
 * sorted according to their similarity with the string with the best
 * match at the first position./*from   w w w  .jav a 2  s .  c o  m*/
 * @param <T> the type of the strings in the given collection
 * @param ss the collection to search
 * @param t the string to compare to
 * @return a collection with similar strings
 */
public static <T extends CharSequence> Collection<T> findSimilar(Collection<T> ss, CharSequence t) {
    //look for strings prefixed by 't'
    Collection<T> result = new LinkedHashSet<T>();
    for (T s : ss) {
        if (StringUtils.startsWithIgnoreCase(s, t)) {
            result.add(s);
        }
    }

    //find strings according to their levenshtein distance
    Collection<T> mins = findMinimum(ss, t, 5, Math.min(t.length() - 1, 7));
    result.addAll(mins);

    return result;
}

From source file:com.fiveamsolutions.nci.commons.audit.DefaultProcessor.java

/**
 * encodes individual values in multi-value (eg Collection) attribute.
 * @param result where to write the encoded value.
 * @param val an individual value in the collection.
 *///w  w w  .  ja va2s .c  o  m
public static void escape(StringBuffer result, CharSequence val) {
    if (val == null) {
        return;
    } else if (val.length() == 0) {
        result.append("\"\"");
    } else {
        for (int i = 0; i < val.length(); i++) {
            char c = val.charAt(i);
            if (c == '\\' || c == ',' || c == '(' || c == ')') {
                result.append('\\');
            }
            result.append(c);
        }
    }
}

From source file:edu.cornell.med.icb.goby.reads.ColorSpaceConverter.java

/**
 * Converts a sequence into the equivalent sequence in color space.
 *
 * @param input  The sequence to be converted
 * @param output where the converted sequence should be placed
 * @param anyN   if true, converts color space codes larger or equal to 4 to 'N' characters.
 */// ww w . j av a 2  s. c o  m
public static void convert(final CharSequence input, final MutableString output, final boolean anyN) {
    assert output != null : "The output location must not be null";

    output.setLength(0);
    if (input != null) {
        int position = 0;
        final int length = input.length() - 1; // -1 since we enumerate digrams
        if (input.length() > 0) {

            output.setLength(position + 1);
            output.setCharAt(position++, input.charAt(0));
        }
        for (int index = 0; index < length; ++index) {
            final char code = Character.forDigit(getColorCode(input.charAt(index), input.charAt(index + 1)),
                    10);
            output.setLength(position + 1);
            output.setCharAt(position++, (code >= '4') ? (anyN ? 'N' : code) : code);
        }
        output.setLength(position);
    }
}

From source file:com.tecapro.inventory.common.util.StringUtil.java

public static boolean isMobileNumber(final CharSequence cs) {

    final int seqLength = cs.length();

    if (seqLength == 0) {
        return false;
    }/*from   w ww .  j  a v  a2 s. c om*/

    boolean hasMobiPrefix = false;
    char firstChar = cs.charAt(0);

    if (cs.charAt(0) == '8' && cs.charAt(1) == '4') { // two first digits are country code
        firstChar = cs.charAt(2);
    }

    for (int i = 0; i < Constants.MOBI_PREFIX.length; i++) {
        if (firstChar == Constants.MOBI_PREFIX[i]) {
            hasMobiPrefix = true;
            break;
        }
    }

    if (!hasMobiPrefix) {
        return false;
    }

    for (int i = 1; i < seqLength; i++) {
        if (!Character.isDigit(cs.charAt(i))) {
            return false;
        }
    }

    return true;
}

From source file:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java

private static final String plural(boolean plural, CharSequence text) {
    StringBuilder b = new StringBuilder();
    int mode = 0;
    for (int i = 0; i < text.length(); i++) {
        char c = text.charAt(i);
        switch (mode) {
        case 0: // regular mode
        {/*from  ww  w  .j a va2s. c o m*/
            if (c == '{') {
                mode = 1;
            } else {
                b.append(c); // always append
            }
            break;
        }
        case 1: // singular mode
        {
            if (c == '|') {
                mode = 2;
            } else if (!plural) {
                b.append(c); // append if singular
            }
            break;
        }
        case 2: // plural mode
        {
            if (c == '}') {
                mode = 0;
            } else if (plural) {
                b.append(c); // append if plural
            }

            break;
        }
        default:
            throw new RuntimeException();
        }
    }
    return b.toString();
}

From source file:eap.util.EDcodeUtil.java

public static byte[] hexDecode(CharSequence s) {
    int nChars = s.length();

    if (nChars % 2 != 0) {
        throw new IllegalArgumentException("Hex-encoded string must have an even number of characters");
    }//w w  w. ja v  a 2  s . co  m

    byte[] result = new byte[nChars / 2];

    for (int i = 0; i < nChars; i += 2) {
        int msb = Character.digit(s.charAt(i), 16);
        int lsb = Character.digit(s.charAt(i + 1), 16);

        if (msb < 0 || lsb < 0) {
            throw new IllegalArgumentException("Non-hex character in input: " + s);
        }
        result[i / 2] = (byte) ((msb << 4) | lsb);
    }
    return result;
}

From source file:com.openAtlas.bundleInfo.maker.PackageLite.java

private static String buildClassName(String str, CharSequence charSequence) {
    if (charSequence == null || charSequence.length() <= 0) {
        System.out.println("Empty class name in package " + str);
        return null;
    }//from w ww . j av  a  2  s.c  o  m
    String obj = charSequence.toString();
    char charAt = obj.charAt(0);
    if (charAt == '.') {
        return (str + obj).intern();
    }
    if (obj.indexOf(46) < 0) {
        StringBuilder stringBuilder = new StringBuilder(str);
        stringBuilder.append('.');
        stringBuilder.append(obj);
        return stringBuilder.toString().intern();
    } else if (charAt >= 'a' && charAt <= 'z') {
        return obj.intern();
    } else {
        System.out.println("Bad class name " + obj + " in package " + str);
        return null;
    }
}

From source file:com.shishu.utility.string.StringUtil.java

/**
 * ?//from   w  ww.ja v  a2 s. c  om
 * 
 * @author wangtao 2014-4-29
 */
public static boolean isContainChar(CharSequence pat, CharSequence sub) {
    for (int i = 0; i < sub.length(); i++) {
        char subChar = sub.charAt(i);
        boolean isContain = false;
        for (int j = 0; j < pat.length(); j++) {
            if (pat.charAt(j) == subChar) {
                isContain = true;
            }
        }
        if (!isContain) {
            return false;
        }
    }
    return true;
}