Example usage for java.lang StringBuilder deleteCharAt

List of usage examples for java.lang StringBuilder deleteCharAt

Introduction

In this page you can find the example usage for java.lang StringBuilder deleteCharAt.

Prototype

@Override
public StringBuilder deleteCharAt(int index) 

Source Link

Usage

From source file:Main.java

/**
 * Converts the given instances into comma-separated elements of a string,
 * optionally escapes commas and double quotes with backslahses.
 *///from   w  w w.ja  v a 2  s  .  co  m
public static String toCommaSeparatedList(Object[] o, boolean escapeCommas, boolean escapeDoubleQuotes) {
    if (o == null) {
        return "";
    }
    StringBuilder sb = new StringBuilder();
    for (Object obj : o) {
        String objString = obj.toString();
        objString = objString.replaceAll("\\\\", "\\\\\\\\"); // Replace one backslash with two (nice, eh?)
        if (escapeCommas) {
            objString = objString.replaceAll(",", "\\\\,");
        }
        if (escapeDoubleQuotes) {
            objString = objString.replaceAll("\"", "\\\"");
        }
        sb.append(objString).append(",");
    }
    if (sb.length() > 1) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();

}

From source file:jongo.JongoUtils.java

/**
 * Generates a string like {call stmt(?,?,?)} to be used by a CallableStatement to execute a function
 * or a procedure./*from  w w w .  j  a  v  a2 s  .  co  m*/
 * @param queryName the name of the function or procedure
 * @param paramsSize the amount of parameters to be passed to the function/procedure
 * @return a string ready to be fed to a CallableStatement
 */
public static String getCallableStatementCallString(final String queryName, final Integer paramsSize) {
    if (StringUtils.isBlank(queryName))
        throw new IllegalArgumentException("The name can't be null, empty or blank");

    StringBuilder b = new StringBuilder("{CALL ");
    b.append(queryName);
    b.append("(");
    for (int i = 0; i < paramsSize; i++) {
        b.append("?,");
    }
    if (b.charAt(b.length() - 1) == ',') {
        b.deleteCharAt(b.length() - 1);
    }
    b.append(")}");
    return b.toString();
}

From source file:org.synyx.hades.dao.query.QueryUtils.java

/**
 * Adds {@literal order by} clause to the JPQL query.
 * /* w  w  w  .  j  a  va2 s  . c o m*/
 * @param query
 * @param sort
 * @param alias
 * @return
 */
public static String applySorting(String query, Sort sort, String alias) {

    if (null == sort) {
        return query;
    }

    Assert.hasText(alias);

    StringBuilder builder = new StringBuilder(query);
    builder.append(" order by");

    for (Property property : sort) {
        builder.append(String.format(" %s.", alias));
        builder.append(property.getName());
        builder.append(" ");
        builder.append(property.getOrder().getJpaValue());
        builder.append(",");
    }

    builder.deleteCharAt(builder.length() - 1);

    return builder.toString();
}

From source file:com.moviejukebox.tools.StringTools.java

/**
 * Generate the pattern string for all available quote marks
 *
 * @return//from   w ww  .  j  a  v a2  s .  c  o m
 */
private static String generateQuoteList() {
    Set<String> quotes = new HashSet<>();
    // Double quote - "
    quotes.add("\"");
    // Single left quote - 
    quotes.add("\u2018");
    // Single right quote - 
    quotes.add("\u2019");
    // Double left quote - 
    quotes.add("\u201C");
    // Double right quote - ?
    quotes.add("\u201D");
    // Low single quote - 
    quotes.add("\u201A");
    // Low double quote - 
    quotes.add("\u201E");
    // Backtick "quote" - `
    quotes.add("`");
    // Odd quote character that comes across from TheTVDB
    quotes.add("");
    // Add the XML version of '
    quotes.add("&#x27;");

    StringBuilder quoteString = new StringBuilder();
    for (String quote : quotes) {
        quoteString.append(quote).append("|");
    }
    quoteString.deleteCharAt(quoteString.length() - 1);
    return quoteString.toString();
}

From source file:com.vake.ArrayUtils.java

public static String bytesToMac(byte[] bytes) {
    final StringBuilder sb = new StringBuilder();
    for (byte element : bytes) {
        final String fragment = Integer.toHexString(0xFF & element);
        if (fragment.length() < 2) {
            sb.append(0);//from  ww  w .  j av  a  2  s .  com
        }
        sb.append(fragment);
        sb.append("-");
        sb.append((byte) (element & 0x0F));
    }
    sb.deleteCharAt(sb.length() - 1);
    return sb.toString();
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static String getUniqueDeviceId(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(CMAccount.SETTINGS_PREFERENCES,
            Context.MODE_PRIVATE);
    String udid = prefs.getString(KEY_UDID, null);
    if (udid != null)
        return udid;
    String wifiInterface = SystemProperties.get("wifi.interface");
    if (wifiInterface != null) {
        try {/*from w  w w.java 2  s .c  o m*/
            List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
            for (NetworkInterface networkInterface : interfaces) {
                if (wifiInterface.equals(networkInterface.getDisplayName())) {
                    byte[] mac = networkInterface.getHardwareAddress();
                    if (mac != null) {
                        StringBuilder buf = new StringBuilder();
                        for (int i = 0; i < mac.length; i++)
                            buf.append(String.format("%02X:", mac[i]));
                        if (buf.length() > 0)
                            buf.deleteCharAt(buf.length() - 1);
                        if (CMAccount.DEBUG)
                            Log.d(TAG, "using wifi mac for id : " + buf.toString());
                        return digest(prefs, context.getPackageName() + buf.toString());
                    }
                }

            }
        } catch (SocketException e) {
            Log.e(TAG, "Unable to get wifi mac address", e);
        }
    }
    //If we fail, just use android id.
    return digest(prefs, context.getPackageName()
            + Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID));
}

From source file:info.mtgdb.api.Db.java

/**
 * Retrieve cards based upon their multiverse ids.
 * //from  www.  jav a2 s. c o  m
 * @param multiverseIds A {@link List} of multiverse ids
 * @return An {@link ArrayList} of {@link Card} objects corresponding to the ids.
 */
public static ArrayList<Card> getCards(ArrayList<Integer> multiverseIds) {
    StringBuilder sb = new StringBuilder();

    /* Make a list of the ids to fetch. */
    for (Integer i : multiverseIds) {
        sb.append(i + ",");
    }
    /* Remove trailing ',' */
    if (multiverseIds.size() > 0)
        sb.deleteCharAt(sb.length() - 1);
    String url = API_URL + "/cards/" + sb.toString();

    return getCardsFromUrl(url);

}

From source file:com.l2jfree.util.Introspection.java

/**
 * Returns a single line string representing a subset of this object's status. <BR>
 * <BR>/*from w ww .j  a  v a 2  s.  c om*/
 * The string consists of the simple name of the given class followed by all non-static fields
 * of that class in name = value pairs, separated with comma followed by a space and enclosed in
 * simple parenthesis. If that class does not declare any non-static fields, no parenthesis are
 * added. <BR>
 * If the given class is {@code null}, then the complete status is reported, as in
 * {@link #toString(Object)}. <BR>
 * <BR>
 * Example outputs could be:<BR>
 * <CODE>
 * SomeClass<BR>
 * SomeClass(number = 15, object = this)
 * </CODE>
 * 
 * @param o an object (of type {@code T})
 * @param c {@code Class<T>} or {@code Class<? super T>}
 * @return a textual representation of the given object
 */
public static String toString(Object o, Class<?> c) {
    if (o == null)
        return "null".intern();
    Class<?> actual = (c == null ? o.getClass() : c);
    StringBuilder sb = new StringBuilder(actual.getSimpleName());
    int open = sb.length();
    sb.append('(');
    boolean written = writeFields(actual, o, sb, null, true);
    if (c == null)
        while ((actual = actual.getSuperclass()) != null)
            if (writeFields(actual, o, sb, null, !written))
                written = true;
    if (!written)
        sb.deleteCharAt(open);
    else
        sb.append(')');
    return sb.toString();
}

From source file:com.phonemetra.account.util.AccountUtils.java

public static String getUniqueDeviceId(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(Account.SETTINGS_PREFERENCES, Context.MODE_PRIVATE);
    String udid = prefs.getString(KEY_UDID, null);
    if (udid != null)
        return udid;
    String wifiInterface = SystemProperties.get("wifi.interface");
    if (wifiInterface != null) {
        try {/*  w  w  w . j a  v  a2s.co  m*/
            List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
            for (NetworkInterface networkInterface : interfaces) {
                if (wifiInterface.equals(networkInterface.getDisplayName())) {
                    byte[] mac = networkInterface.getHardwareAddress();
                    if (mac != null) {
                        StringBuilder buf = new StringBuilder();
                        for (int i = 0; i < mac.length; i++)
                            buf.append(String.format("%02X:", mac[i]));
                        if (buf.length() > 0)
                            buf.deleteCharAt(buf.length() - 1);
                        if (Account.DEBUG)
                            Log.d(TAG, "using wifi mac for id : " + buf.toString());
                        return digest(prefs, context.getPackageName() + buf.toString());
                    }
                }

            }
        } catch (SocketException e) {
            Log.e(TAG, "Unable to get wifi mac address", e);
        }
    }
    //If we fail, just use android id.
    return digest(prefs, context.getPackageName()
            + Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID));
}

From source file:com.impetus.client.cassandra.common.CassandraUtilities.java

/**
 * Append columns.//www  .  j a va  2  s .  c o m
 * 
 * @param builder
 *            the builder
 * @param columns
 *            the columns
 * @param selectQuery
 *            the select query
 * @param translator
 *            the translator
 */
public static StringBuilder appendColumns(StringBuilder builder, List<String> columns, String selectQuery,
        CQLTranslator translator) {
    if (columns != null) {
        for (String column : columns) {
            translator.appendColumnName(builder, column);
            builder.append(",");
        }
    }
    if (builder.lastIndexOf(",") != -1) {
        builder.deleteCharAt(builder.length() - 1);
        selectQuery = StringUtils.replace(selectQuery, CQLTranslator.COLUMNS, builder.toString());
    }

    builder = new StringBuilder(selectQuery);
    return builder;
}