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:Main.java

private static boolean isEmpty(CharSequence str) {
    return (str == null || str.length() == 0);
}

From source file:Main.java

public static String escapeLiteralValueForSql(final CharSequence s) {

    final int len = s.length();
    final StringBuilder out = new StringBuilder(len * 2);

    for (int i = 0; i < len; i++) {
        final char c = s.charAt(i);
        if ((int) c == (int) '\'') {
            out.append("\\\'");
        } else if ((int) c == (int) '\\') {
            out.append("\\\\\\\\");
        } else if ((int) c == (int) '"') {
            out.append("\\\\\"");
        } else if ((int) c == (int) '\n') {
            out.append("\\\\n");
        } else if ((int) c == (int) '\r') {
            out.append("\\\\r");
        } else if ((int) c == (int) '\t') {
            out.append("\\\\t");
        } else if (isLowUnicode((int) c)) {
            out.append("\\\\u");
            out.append(hexString((int) c, SHORT_ESCAPE_LENGTH - 1));
        } else if (isHighUnicode((int) c)) {
            out.append("\\\\U");
            out.append(hexString((int) c, LONG_ESCAPE_LENGTH - 2));
        } else {/* w  w  w  .j av a  2  s .  co  m*/
            out.append(c);
        }
    }

    return out.toString();
}

From source file:Main.java

/**
 * Green implementation of toCharArray./* www  . j a  v a  2s .c  o  m*/
 *
 * @param cs the {@code CharSequence} to be processed
 * @return the resulting char array
 */
static char[] toCharArray(final CharSequence cs) {
    if (cs instanceof String) {
        return ((String) cs).toCharArray();
    }
    final int sz = cs.length();
    final char[] array = new char[cs.length()];
    for (int i = 0; i < sz; i++) {
        array[i] = cs.charAt(i);
    }
    return array;
}

From source file:Main.java

/**
 * Green implementation of toCharArray.//from w  w w  .j  a  v  a2  s .c  om
 *
 * @param cs the {@code CharSequence} to be processed
 * @return the resulting char array
 */
static char[] toCharArray(CharSequence cs) {
    if (cs instanceof String) {
        return ((String) cs).toCharArray();
    } else {
        int sz = cs.length();
        char[] array = new char[cs.length()];
        for (int i = 0; i < sz; i++) {
            array[i] = cs.charAt(i);
        }
        return array;
    }
}

From source file:com.cloudera.oryx.rdf.computation.WineQualityIT.java

private static List<Example> readWineQualityExamples() throws IOException {
    List<Example> allExamples = Lists.newArrayList();
    Pattern delimiter = Pattern.compile(";");
    File dataFile = new File(TEST_TEMP_INBOUND_DIR, "winequality-white.csv");
    for (CharSequence line : new FileLineIterable(dataFile)) {
        if (line.length() == 0) {
            continue;
        }//from  w  w w .  j  a v  a 2 s .com
        String[] tokens = delimiter.split(line);
        Feature[] features = new Feature[11];
        for (int i = 0; i < features.length; i++) {
            features[i] = NumericFeature.forValue(Float.parseFloat(tokens[i]));
        }
        Example trainingExample = new Example(NumericFeature.forValue(Float.parseFloat(tokens[11])), features);
        allExamples.add(trainingExample);
    }
    return allExamples;
}

From source file:Main.java

public static boolean isMyChar(CharSequence label) {
    if (label == null)
        return false;
    boolean isMyChar = false;
    for (int i = 0; i < label.length(); i++) {
        if (isMyChar(label.charAt(i))) {
            isMyChar = true;/*from  w  w w  .  j  a va 2 s  .c  o m*/
            break;
        }
    }
    return isMyChar;
}

From source file:Main.java

/**
 * Check whether the given CharSequence contains any whitespace characters.
 * @param str the CharSequence to check (may be {@code null})
 * @return {@code true} if the CharSequence is not empty and
 * contains at least 1 whitespace character
 * @see Character#isWhitespace/*from   w w  w .j a va  2s .  c  o m*/
 */
public static boolean containsWhitespace(CharSequence str) {
    if (!hasLength(str)) {
        return false;
    }
    int strLen = str.length();
    for (int i = 0; i < strLen; i++) {
        if (Character.isWhitespace(str.charAt(i))) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

/**
 * Helper method to validate the phone number
 */// w w w .ja  v  a  2  s  .c  om
public static boolean isPhoneNumberValid(CharSequence phoneNumber) {
    boolean isGoodPhone = false;
    if (!Pattern.matches("[a-zA-Z]+", phoneNumber)) {
        isGoodPhone = !(phoneNumber.length() < 5 || phoneNumber.length() > 14);
    } else {
        isGoodPhone = false;
    }
    return isGoodPhone;
}

From source file:Main.java

public static CharSequence setTextStyleBold(CharSequence text) {
    final StyleSpan style = new StyleSpan(Typeface.BOLD);
    final SpannableString str = new SpannableString(text);
    str.setSpan(style, 0, text.length(), 0);

    return str;//from   ww  w  .  j  a va  2 s  .  c o m
}

From source file:Main.java

public static CharSequence setTextStyleNormal(CharSequence text) {
    final StyleSpan style = new StyleSpan(Typeface.NORMAL);
    final SpannableString str = new SpannableString(text);
    str.setSpan(style, 0, text.length(), 0);

    return str;//w w w . j a v  a2 s .c om
}