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:br.msf.commons.util.CharSequenceUtils.java

public static String castToString(final CharSequence sequence) {
    if (sequence != null) {
        return isString(sequence) ? (String) sequence : sequence.toString();
    }//  ww w.j a va  2 s.  c  o m
    return null;
}

From source file:com.lillicoder.newsblurry.util.FileLogger.java

/**
 * Dumps the given {@link CharSequence} to a file with the given
 * filename in the app storage directory.
 * @param filename Filename of the file to dump to. If the specified file already
 *                exists, its contents will be overwritten.
 * @param textToDump {@link CharSequence} to write to file.
 * @return <code>true</code> if the log was successfully written,
 *          <code>false</code> otherwise.
 *///from  w w  w  .j a  v a  2s.  com
public boolean logText(String filename, CharSequence textToDump) {
    Assert.assertTrue(!TextUtils.isEmpty(filename) && !TextUtils.isEmpty(textToDump));

    if (this.isDebugMode())
        Log.d(TAG, String.format(DEBUG_WRITING_TEXT_TO_FILE, filename, textToDump));

    File logFile = this.getLogFile(filename);
    return this.writeLog(logFile, textToDump.toString());
}

From source file:org.tradex.jdbc.JDBCHelper.java

/**
 * Executes the update defined in the passed sql 
 * @param sql The sql//w ww .  ja  va 2 s .c  om
 * @param binds The bind values
 * @return the number of rows updated
 */
public int execute(CharSequence sql, Object... binds) {
    NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(ds);
    return template.update(sql.toString(), getBinds(sql.toString().trim().toUpperCase(), binds));
}

From source file:HSqlManager.java

public static void uniqueDB(Connection connection, int bps) throws ClassNotFoundException, SQLException,
        InstantiationException, IllegalAccessException, IOException {
    DpalLoad.main(new String[1]);
    HSqlPrimerDesign.Dpal_Inst = DpalLoad.INSTANCE_WIN64;
    String base = new File("").getAbsolutePath();
    if (!written) {
        CSV.makeDirectory(new File(base + "/PhageData"));
        INSTANCE.readFileAll(INSTANCE.path).stream().forEach(x -> {
            try {
                CSV.writeDataCSV(x[1], Fasta.process(x[1], bps), bps);
            } catch (IOException e) {
                e.printStackTrace();//from www. j  a  v  a 2  s . c om
            }
        });
    }
    Connection db = connection;
    db.setAutoCommit(false);
    Statement stat = db.createStatement();
    PrintWriter log = new PrintWriter(new File("javalog.log"));
    stat.execute("SET FILES LOG FALSE;\n");
    PreparedStatement st = db
            .prepareStatement("UPDATE Primerdb.Primers" + " SET UniqueP = true, Tm = ?, GC =?, Hairpin =?"
                    + "WHERE Cluster = ? and Strain = ? and " + "Sequence = ? and Bp = ?");
    ResultSet call = stat.executeQuery("Select * From Primerdb.Phages;");
    List<String[]> phages = new ArrayList<>();
    while (call.next()) {
        String[] r = new String[3];
        r[0] = call.getString("Strain");
        r[1] = call.getString("Cluster");
        r[2] = call.getString("Name");
        phages.add(r);
    }
    phages.stream().map(x -> x[0]).collect(Collectors.toSet()).stream().forEach(x -> {
        phages.stream().filter(y -> y[0].equals(x)).map(y -> y[1]).collect(Collectors.toSet()).parallelStream()
                .forEach(z -> {
                    try {
                        Set<String> nonclustphages = phages.stream()
                                .filter(a -> a[0].equals(x) && !a[1].equals(z)).map(a -> a[2])
                                .collect(Collectors.toSet());
                        ResultSet resultSet = stat.executeQuery("Select Sequence from primerdb.primers"
                                + " where Strain ='" + x + "' and Cluster ='" + z + "' and CommonP = true"
                                + " and Bp = " + Integer.valueOf(bps) + " ");
                        Set<CharSequence> primers = Collections.synchronizedSet(new HashSet<>());
                        while (resultSet.next()) {
                            primers.add(resultSet.getString("Sequence"));
                        }
                        for (String phage : nonclustphages) {
                            CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + phage + ".csv")
                                    .parallelStream().filter(primer -> primers.contains(primer))
                                    .forEach(primers::remove);

                        }
                        int i = 0;
                        for (CharSequence a : primers) {
                            try {
                                st.setDouble(1, HSqlPrimerDesign.primerTm(a, 0, 800, 1.5, 0.2));
                                st.setDouble(2, HSqlPrimerDesign.gcContent(a));
                                st.setBoolean(3, HSqlPrimerDesign.calcHairpin((String) a, 4));
                                st.setString(4, z);
                                st.setString(5, x);
                                st.setString(6, a.toString());
                                st.setInt(7, bps);
                                st.addBatch();
                            } catch (SQLException e) {
                                e.printStackTrace();
                                System.out.println("Error occurred at " + x + " " + z);
                            }
                            i++;
                            if (i == 1000) {
                                i = 0;
                                st.executeBatch();
                                db.commit();
                            }
                        }
                        if (i > 0) {
                            st.executeBatch();
                            db.commit();
                        }
                    } catch (SQLException e) {
                        e.printStackTrace();
                        System.out.println("Error occurred at " + x + " " + z);
                    }
                    log.println(z);
                    log.flush();
                    System.gc();
                });
    });
    stat.execute("SET FILES LOG TRUE\n");
    st.close();
    stat.close();
    System.out.println("Unique Updated");
}

From source file:fr.landel.utils.commons.StringUtils.java

/**
 * Injects all arguments in the specified char sequence. The arguments are
 * injected by replacement of the braces. If no index is specified between
 * braces, an internal index is created and the index is automatically
 * incremented. The index starts from 0. To exclude braces, just double them
 * (like {{0}} will return {0}). If number greater than arguments number are
 * specified, they are ignored./*w  ww. j a  va 2  s .c om*/
 * 
 * <p>
 * precondition: {@code charSequence} cannot be {@code null}
 * </p>
 * 
 * <pre>
 * StringUtils.inject("", "test"); // =&gt; ""
 * 
 * StringUtils.inject("I'll go to the {} this {}", "beach", "afternoon");
 * // =&gt; "I'll go to the beach this afternoon"
 * 
 * StringUtils.inject("I'll go to the {1} this {0}", "afternoon", "beach");
 * // =&gt; "I'll go to the beach this afternoon"
 * 
 * StringUtils.inject("I'll go to the {1} this {}", "afternoon", "beach");
 * // =&gt; "I'll go to the beach this afternoon"
 * 
 * StringUtils.inject("I'll go to {} {3} {} {2}", "the", "this", "afternoon", "beach");
 * // =&gt; "I'll go to the beach this afternoon"
 * 
 * StringUtils.inject("I'll go to {{}}{3} {} {2}{{0}} {4} {text}", "the", "this", "afternoon", "beach");
 * // =&gt; "I'll go to {}beach the afternoon{0} {4} {text}"
 * </pre>
 * 
 * @param charSequence
 *            the input char sequence
 * @param arguments
 *            the arguments to inject
 * @param <T>
 *            the arguments type
 * @return the result with replacements
 */
@SafeVarargs
public static <T> String inject(final CharSequence charSequence, final T... arguments) {
    if (charSequence == null) {
        throw new IllegalArgumentException("The input char sequence cannot be null");
    } else if (isEmpty(charSequence) || arguments == null || arguments.length == 0) {
        return charSequence.toString();
    }

    final StringBuilder output = new StringBuilder(charSequence);

    // if no brace, just returns the string
    if (output.indexOf(BRACE_OPEN) < 0) {
        return output.toString();
    }

    // replace the excluded braces by a temporary string
    replaceBrace(output, BRACE_OPEN_EXCLUDE, BRACE_OPEN_TMP);
    replaceBrace(output, BRACE_CLOSE_EXCLUDE, BRACE_CLOSE_TMP);

    // replace the braces without index by the arguments
    int i = 0;
    int index = 0;
    while ((index = output.indexOf(BRACES, index)) > -1 && i < arguments.length) {
        output.replace(index, index + BRACES.length(), String.valueOf(arguments[i++]));
        index += BRACES.length();
    }

    // replace braces with index by the arguments
    int len;
    String param;
    for (i = 0; i < arguments.length; ++i) {
        index = 0;
        param = new StringBuilder(BRACE_OPEN).append(i).append(BRACE_CLOSE).toString();
        len = param.length();
        while ((index = output.indexOf(param, index)) > -1) {
            output.replace(index, index + len, String.valueOf(arguments[i]));
            index += len;
        }
    }

    // replace the temporary brace by the simple brace
    replaceBrace(output, BRACE_OPEN_TMP, BRACE_OPEN);
    replaceBrace(output, BRACE_CLOSE_TMP, BRACE_CLOSE);

    return output.toString();
}

From source file:RadixTree.java

/**
 * Adds string to the set/*w  ww . ja va2s.  c  o m*/
 * 
 * @param string
 */
public void add(CharSequence string) {
    if (!caseSensitive) {
        string = string.toString().toLowerCase();
    }

    root.addString(string);
}

From source file:RadixTree.java

/**
 * Removes a string from the set/*from  w  w w .  j  a va  2  s.c o  m*/
 * 
 * @param string
 */
public void remove(CharSequence string) {
    if (!caseSensitive) {
        string = string.toString().toLowerCase();
    }

    root.removeString(string);
}

From source file:RadixTree.java

/**
 * Tests if the string is contained in the set
 * /*from   ww  w.j  a  v  a2  s .  c o m*/
 * @param string
 * @return <code>true</code> if the entire string is contained in
 *         the tree
 */
public boolean contains(CharSequence string) {
    if (!caseSensitive) {
        string = string.toString().toLowerCase();
    }

    return findPredecessor(string).length() == string.length();
}

From source file:org.tradex.jdbc.JDBCHelper.java

/**
 * Issues a query for an int/*from w w  w. j av  a 2 s  .  c  om*/
 * @param sql The SQL
 * @param binds The bind values
 * @return an int value
 */
public int templateQueryForInt(CharSequence sql, Object... binds) {
    NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(ds);
    return template.queryForInt(sql.toString(), getBinds(sql.toString().trim().toUpperCase(), binds));
}

From source file:com.chexiaoya.gaodemapdemo.SpeechSearchActivity.java

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    String newText = s.toString().trim();

    if (!TextUtils.isEmpty(newText)) {
        InputtipsQuery inputquery = new InputtipsQuery(newText, city);
        Inputtips inputTips = new Inputtips(this, inputquery);
        inputTips.setInputtipsListener(this);
        inputTips.requestInputtipsAsyn();
    }/*from w ww  . ja  va  2s .c o  m*/
}