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:org.matrix.security.crypto.bcrypt.BCryptPasswordEncoder.java

public String encode(CharSequence rawPassword) {
    String salt;//from   ww  w.  java2  s  .  co m
    if (strength > 0) {
        if (random != null) {
            salt = BCrypt.gensalt(strength, random);
        } else {
            salt = BCrypt.gensalt(strength);
        }
    } else {
        salt = BCrypt.gensalt();
    }
    return BCrypt.hashpw(rawPassword.toString(), salt);
}

From source file:org.yamj.core.hibernate.HibernateDao.java

/**
 * Find entries by id.//from ww w.  jav a2  s  . c o m
 *
 * @param queryString the query string.
 * @param id the id
 * @return list of entities
 */
@SuppressWarnings("rawtypes")
public List findById(CharSequence queryString, Long id) {
    Query queryObject = getSession().createQuery(queryString.toString());
    queryObject.setCacheable(true);
    queryObject.setParameter("id", id);
    return queryObject.list();
}

From source file:net.oxmall.base.common.crypto.bycrpt.BCryptPasswordEncoder.java

public String encode(CharSequence rawPassword) {
    String salt;/*w  w w .  j  a va 2 s.  c o  m*/
    if (strength > 0) {
        if (random != null) {
            salt = BCrypt.gensalt(strength, random);
        } else {
            salt = BCrypt.gensalt(strength);
        }
    } else {
        salt = BCrypt.gensalt();
    }

    return BCrypt.hashpw(rawPassword.toString(), salt);
}

From source file:com.ruesga.rview.fragments.SnippetFragment.java

public void onActionPressed() {
    if (mNeedPermissions) {
        return;/*from   w w w  .ja  v  a  2s  . com*/
    }
    if (!mReadOnly) {
        // Paste
        //noinspection ConstantConditions
        ClipboardManager clipboard = (ClipboardManager) getContext()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        if (clipboard.getPrimaryClip() != null && clipboard.getPrimaryClip().getItemCount() > 0) {
            ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
            CharSequence data = item.getText();
            if (data != null) {
                byte[] content = data.toString().getBytes();
                loadContent(content);
                mUiHandler.post(() -> saveContent(content));
            }
        }

    } else {
        // Open in external
        String action = getString(R.string.action_share);
        //noinspection ConstantConditions
        Uri uri = FileProvider.getUriForFile(getContext(), "com.ruesga.rview.content",
                new File(mUri.getPath()));
        ActivityHelper.open(getContext(), action, uri, "text/plain");
        dismiss();
    }
}

From source file:i2p.bote.imap.ImapService.java

/** Creates an <code>Authenticator</code> that checks the I2P-Bote password. */
private Authenticator createAuthenticator(final PasswordVerifier passwordVerifier) {
    return new Authenticator() {

        @Override/*from  w ww.j  a v a2  s. co  m*/
        public boolean isAuthentic(String userid, CharSequence passwd) {
            if (!IMAP_USER.equals(userid))
                return false;

            byte[] passwordBytes = passwd.toString().getBytes();
            try {
                passwordVerifier.tryPassword(passwordBytes);
            } catch (PasswordException e) {
                return false;
            } catch (Exception e) {
                log.error("Can't check password", e);
            }

            return true;
        }
    };
}

From source file:org.yamj.core.hibernate.HibernateDao.java

/**
 * Find list of entities by named parameters.
 *
 * @param queryString the query string.//from  w w  w .ja va2 s. c  o  m
 * @param params the named parameters
 * @return list of entities
 */
@SuppressWarnings("rawtypes")
public List findByNamedParameters(CharSequence queryString, Map<String, Object> params) {
    Query query = getSession().createQuery(queryString.toString());
    query.setCacheable(true);
    for (Entry<String, Object> param : params.entrySet()) {
        applyNamedParameterToQuery(query, param.getKey(), param.getValue());
    }
    return query.list();
}

From source file:CharArrayMap.java

public V put(CharSequence key, V val) {
    return put(key.toString(), val); // could be more efficient
}

From source file:com.schnee.tweetgeister.visualization.TweetgeisterBalloonLayout.java

private void walk(Node<CharSequence> element, int tabLevel) {

    CharSequence text = element.getData();
    String theData = text.toString();

    theData = cleanNewLines(theData);/*  w w w  .j ava  2 s . com*/

    tabLevel++;
    for (Node<CharSequence> data : element.getChildren()) {

        graph.addEdge(edgeFactory.create(), element, data);
        walk(data, tabLevel);

    }

}

From source file:HSqlManager.java

@SuppressWarnings("Duplicates")
@Deprecated/* w w  w.  j  a  v  a2s  .c  o  m*/
public static void mycoUniqueDB(Connection connection, int bps) throws ClassNotFoundException, SQLException,
        InstantiationException, IllegalAccessException, IOException {
    long time = System.currentTimeMillis();
    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.parseAllPhages(bps);
    }
    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<>();
    String strain = "";
    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);
        if (r[2].equals("xkcd")) {
            strain = r[0];
        }
    }
    call.close();
    String x = strain;
    Set<String> clust = phages.stream().filter(y -> y[0].equals(x)).map(y -> y[1]).collect(Collectors.toSet());
    String[] clusters = clust.toArray(new String[clust.size()]);
    for (String z : clusters) {
        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"));
            }
            resultSet.close();
            for (String phage : nonclustphages) {
                //                    String[] seqs = Fasta.parse(base + "/Fastas/" + phage + ".fasta");
                //                    String sequence =seqs[0]+seqs[1];
                //                        Map<String, List<Integer>> seqInd = new HashMap<>();
                //                        for (int i = 0; i <= sequence.length()-bps; i++) {
                //                            String sub=sequence.substring(i,i+bps);
                //                            if(seqInd.containsKey(sub)){
                //                                seqInd.get(sub).add(i);
                //                            }else {
                //                                List<Integer> list = new ArrayList<>();
                //                                list.add(i);
                //                                seqInd.put(sub,list);
                //                            }
                //                        }
                //                    primers = primers.stream().filter(primer->!seqInd.containsKey(primer)).collect(Collectors.toSet());
                //                    primers =Sets.difference(primers,CSV.readCSV(base + "/PhageData/"+Integer.toString(bps)
                //                                    + phage + ".csv"));
                CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + phage + ".csv").stream()
                        .filter(primers::contains).forEach(primers::remove);
                //                    System.gc();

            }
            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");
    System.out.println((System.currentTimeMillis() - time) / Math.pow(10, 3) / 60);
}

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

/**
 * Injects all arguments in the specified char sequence. The arguments are
 * injected by replacement of keys between braces. To exclude keys, just
 * double braces (like {{key}} will return {key}). If some keys aren't
 * found, they are ignored.//www . jav  a 2 s  .c om
 * 
 * <p>
 * precondition: {@code charSequence} cannot be {@code null}
 * </p>
 * 
 * <pre>
 * StringUtils.injectKeys(Pair.of("${", "}"), Pair.of("${{", "}}"), "", Pair.of("key", "test"));
 * // =&gt; ""
 * 
 * StringUtils.injectKeys(Pair.of("${", "}"), Pair.of("${{", "}}"), "I'll go to the {where} this {when}", Pair.of("where", "beach"),
 *         Pair.of("when", "afternoon"));
 * // =&gt; "I'll go to the beach this afternoon"
 * 
 * StringUtils.injectKeys(Pair.of("${", "}"), Pair.of("${{", "}}"), "I'll go to {key}{{key}}{key}", Pair.of("key", "beach"));
 * // =&gt; "I'll go to beach{key}beach"
 * </pre>
 * 
 * @param include
 *            the characters that surround the property key to replace
 * @param exclude
 *            the characters that surround the property key to exclude of
 *            replacement
 * @param charSequence
 *            the input char sequence
 * @param arguments
 *            the pairs to inject
 * @param <T>
 *            the type arguments
 * @return the result with replacements
 */
@SafeVarargs
public static <T extends Map.Entry<String, Object>> String injectKeys(final Pair<String, String> include,
        final Pair<String, String> exclude, final CharSequence charSequence, final T... arguments) {

    checkParamsInjectKeys(include, exclude, charSequence);

    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(include.getLeft()) < 0) {
        return output.toString();
    }

    for (T argument : arguments) {
        if (argument != null) {
            int index = 0;

            final String key = new StringBuilder(include.getLeft()).append(argument.getKey())
                    .append(include.getRight()).toString();
            final String keyExclude = new StringBuilder(exclude.getLeft()).append(argument.getKey())
                    .append(exclude.getRight()).toString();

            // replace the excluded braces by a temporary string
            while ((index = output.indexOf(keyExclude, index)) > -1) {
                output.replace(index, index + keyExclude.length(), TEMP_REPLACEMENT);
            }

            // replace the key by the argument
            index = 0;
            while ((index = output.indexOf(key, index)) > -1) {
                output.replace(index, index + key.length(), String.valueOf(argument.getValue()));
            }

            // replace the temporary string by the excluded braces
            index = 0;
            while ((index = output.indexOf(TEMP_REPLACEMENT, index)) > -1) {
                output.replace(index, index + TEMP_REPLACEMENT.length(), key);
            }
        }
    }

    return output.toString();
}