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

/**
 * /*from w w  w .  j  ava 2  s  .  c  o  m*/
 * @param c
 * @param uid
 * @return
 * @throws JSONException
 */
public static JSONArray getPackagesForUid(Context c, int uid) throws JSONException {
    PackageManager pm = c.getPackageManager();
    JSONArray res = new JSONArray();
    String[] pkgs = pm.getPackagesForUid(uid);
    if (pkgs != null) {
        for (int i = 0; i < pkgs.length; i++) {
            try {
                CharSequence appLabel = pm
                        .getApplicationLabel(pm.getApplicationInfo(pkgs[i], PackageManager.GET_META_DATA));
                JSONObject pkg = new JSONObject();
                pkg.put("package", pkgs[i]);
                pkg.put("app_label", appLabel.toString());
                res.put(pkg);
            } catch (NameNotFoundException e) {
            } catch (Exception e) {
            }
        }
    }
    return res;
}

From source file:com.jaeksoft.searchlib.util.StringUtils.java

public final static String fastConcat(final Object... objects) {
    CharSequence cs = fastConcatCharSequence(objects);
    return cs == null ? null : cs.toString();
}

From source file:com.jaeksoft.searchlib.util.StringUtils.java

public final static String fastConcat(final CharSequence... charSeqs) {
    CharSequence cs = fastConcatCharSequence(charSeqs);
    return cs == null ? null : cs.toString();
}

From source file:Main.java

public static byte[] toByteArray(CharSequence input, String encoding) throws UnsupportedEncodingException {
    if (input == null)
        return new byte[0];
    else//from ww w  .  j a v a2  s .c o m
        return input.toString().getBytes(encoding);
}

From source file:com.simiacryptus.mindseye.applications.HadoopUtil.java

/**
 * Gets file system./*from www . j av  a  2s  .com*/
 *
 * @param file the file
 * @return the file system
 */
public static FileSystem getFileSystem(final CharSequence file) {
    Configuration conf = getHadoopConfig();
    FileSystem fileSystem;
    try {
        fileSystem = FileSystem.get(new Path(file.toString()).toUri(), conf);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return fileSystem;
}

From source file:Main.java

public static void uppercaseEditText(final EditText editText) {
    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS
            | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    editText.addTextChangedListener(new TextWatcher() {

        @Override//  w w w .  j  a  va 2s .c  o m
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }

        @Override
        public void afterTextChanged(Editable arg0) {
            String s = arg0.toString();
            if (!s.equals(s.toUpperCase().trim())) {
                s = s.toUpperCase().trim();
                editText.setText(s);
                editText.setSelection(s.length());
            }
        }
    });
}

From source file:br.msf.maven.compressor.CompressorService.java

private static void writeContents(final CharSequence content, final File f, final Charset encoding)
        throws Exception {
    if (f == null) {
        return;//from  w w  w.j ava  2  s  .c  o m
    }
    final byte[] bytes = content.toString().getBytes(encoding);
    OutputStream os = null;
    try {
        if (!f.exists()) {
            f.getParentFile().mkdirs(); // create path directories
            f.createNewFile(); // create empty file
        }
        os = new FileOutputStream(f);
        os.write(bytes);
        os.flush();
    } finally {
        IOUtils.closeQuietly(os);
    }
}

From source file:de.cosmocode.junit.Asserts.java

/**
 * Asserts that the input matches the regex defined by the pattern.
 * //from w w w  .  jav  a 2  s  .co m
 * Fails if pattern is null.
 * Fails if input is null.
 * Fails if input does not match pattern.
 * 
 * @param pattern the {@link Pattern} to check against
 * @param input the input to check
 */
public static void assertMatches(Pattern pattern, CharSequence input) {
    if (pattern == null) {
        fail("Pattern must not be null");
    } else if (input == null) {
        fail("Input must not be null");
    } else {
        final boolean matches = pattern.matcher(input.toString()).matches();
        assertTrue("'" + input + "' doesn't match '" + pattern.pattern() + "'", matches);
    }
}

From source file:de.cosmocode.junit.Asserts.java

/**
 * Asserts that the input does not match the regex defined by the pattern.
 * /*from www.  j  a  va2  s.  c  om*/
 * Fails if pattern is null.
 * Fails if input is null.
 * Fails if input matches pattern.
 * 
 * @param pattern the {@link Pattern} to check against
 * @param input the input to check
 */
public static void assertDoesNotMatch(Pattern pattern, CharSequence input) {
    if (pattern == null) {
        fail("Pattern must not be null");
    } else if (input == null) {
        fail("Input must not be null");
    } else {
        final boolean matches = pattern.matcher(input.toString()).matches();
        assertFalse("'" + input + "' matches '" + pattern.pattern() + "'", matches);
    }
}

From source file:com.cyberway.issue.util.TextUtils.java

/**
 * Replaces HTML Entity Encodings.//from   w w  w  .  j  a v a 2s.  c om
 * @param cs The CharSequence to remove html codes from
 * @return the same CharSequence or an escaped String.
 */
public static CharSequence unescapeHtml(final CharSequence cs) {
    if (cs == null) {
        return cs;
    }

    return StringEscapeUtils.unescapeHtml(cs.toString());
}