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

public static String encode(CharSequence target) {
    if (target == null) {
        return "";
    }//from w w w .j  av  a 2  s .  com
    String result = target.toString();
    try {
        result = URLEncoder.encode(result, "UTF8");
    } catch (UnsupportedEncodingException ex) {
        ex.printStackTrace();
    }
    return result;
}

From source file:Main.java

/**
 * Used by the indexOf(CharSequence methods) as a green implementation of indexOf.
 *
 * @param cs         the {@code CharSequence} to be processed
 * @param searchChar the {@code CharSequence} to be searched for
 * @param start      the start index/*from   w w  w. j  av  a2 s . co  m*/
 * @return the index where the search sequence was found
 */
static int indexOf(final CharSequence cs, final CharSequence searchChar, final int start) {
    return cs.toString().indexOf(searchChar.toString(), start);
    //        if (cs instanceof String && searchChar instanceof String) {
    //            // TODO: Do we assume searchChar is usually relatively small;
    //            //       If so then calling toString() on it is better than reverting to
    //            //       the green implementation in the else block
    //            return ((String) cs).indexOf((String) searchChar, start);
    //        } else {
    //            // TODO: Implement rather than convert to String
    //            return cs.toString().indexOf(searchChar.toString(), start);
    //        }
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static void setClipboardText(Context context, CharSequence text) {
    ClipboardManager ClipMan = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipMan.setText(text.toString());
}

From source file:Main.java

/**
 * Used by the lastIndexOf(CharSequence methods) as a green implementation of lastIndexOf
 *
 * @param cs the {@code CharSequence} to be processed
 * @param searchChar the {@code CharSequence} to be searched for
 * @param start the start index//from ww  w.  j a v a2s.  co  m
 * @return the index where the search sequence was found
 */
static int lastIndexOf(final CharSequence cs, final CharSequence searchChar, final int start) {
    return cs.toString().lastIndexOf(searchChar.toString(), start);
    //        if (cs instanceof String && searchChar instanceof String) {
    //            // TODO: Do we assume searchChar is usually relatively small;
    //            //       If so then calling toString() on it is better than reverting to
    //            //       the green implementation in the else block
    //            return ((String) cs).lastIndexOf((String) searchChar, start);
    //        } else {
    //            // TODO: Implement rather than convert to String
    //            return cs.toString().lastIndexOf(searchChar.toString(), start);
    //        }
}

From source file:org.matrix.security.crypto.encrypt.Encryptors.java

/**
 * Creates a standard password-based bytes encryptor using 256 bit AES encryption.
 * Derives the secret key using PKCS #5's PBKDF2 (Password-Based Key Derivation Function #2).
 * Salts the password to prevent dictionary attacks against the key.
 * The provided salt is expected to be hex-encoded; it should be random and at least 8 bytes in length.
 * Also applies a random 16 byte initialization vector to ensure each encrypted message will be unique.
 * Requires Java 6./*  w ww  . ja  va 2 s .  com*/
 *
 * @param password the password used to generate the encryptor's secret key; should not be shared
 * @param salt a hex-encoded, random, site-global salt value to use to generate the key
 */
public static BytesEncryptor standard(CharSequence password, CharSequence salt) {
    return new AesBytesEncryptor(password.toString(), salt, KeyGenerators.secureRandom(16));
}

From source file:gsn.storage.SQLUtils.java

public static int getWhereIndex(CharSequence c) {
    return c.toString().toLowerCase().lastIndexOf(" where ");
}

From source file:gsn.storage.SQLUtils.java

public static int getOrderByIndex(CharSequence c) {
    return c.toString().toLowerCase().lastIndexOf(" order by ");
}

From source file:gsn.storage.SQLUtils.java

public static int getGroupByIndex(CharSequence c) {
    return c.toString().toLowerCase().lastIndexOf(" group by ");
}

From source file:com.berniesanders.fieldthebern.parsing.FormValidator.java

public static boolean isPhoneValid(CharSequence phone) {
    if (Patterns.PHONE.matcher(phone).matches()) {
        return passesPhoneRequirements(phone.toString());
    } else {/*from ww w.  java  2s.  c  o m*/
        return false;
    }
}

From source file:Main.java

/**
 * Detect name.// w ww  .  j  a  v  a2  s. com
 *
 * @param view the view
 * @return the string
 */
public static String detectName(View view) {
    String name = new String();
    if (view instanceof TextView) {
        name = ((TextView) view).getText().toString();
        if (view instanceof EditText) {
            CharSequence hint = ((EditText) view).getHint();
            name = (hint == null) ? new String() : hint.toString();
        }
        return name;
    }
    if (view instanceof RadioGroup) {
        RadioGroup group = (RadioGroup) view;
        int max = group.getChildCount();
        String text = new String();
        for (int item = 0; item < max; item++) {
            View child = group.getChildAt(item);
            text = detectName(child);
            if (!text.equals("")) {
                name = text;
                break;
            }
        }
    }
    return name;
}