Example usage for java.lang StringBuilder length

List of usage examples for java.lang StringBuilder length

Introduction

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

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:com.github.alexfalappa.nbspringboot.Utils.java

public static String vmOptsFromPrefs() {
    StringBuilder sb = new StringBuilder();
    if (NbPreferences.forModule(Utils.class).getBoolean(PREF_VM_OPTS_LAUNCH, true)) {
        sb.append(BootPanel.VMOPTS_OPTIMIZE);
    }// w  ww.  ja v a  2s.  c o  m
    if (sb.length() > 0) {
        sb.append(' ');
    }
    sb.append(NbPreferences.forModule(Utils.class).get(PREF_VM_OPTS, ""));
    return sb.toString();
}

From source file:com.wareninja.opensource.common.wsrequest.HttpUtils.java

/**
 * Send an HTTP(s) request with POST parameters.
 * /*from  w  w w  .  ja  va  2 s  .  com*/
 * @param parameters
 * @param url
 * @throws UnsupportedEncodingException
 * @throws IOException
 * @throws KeyManagementException
 * @throws NoSuchAlgorithmException
 */
public static void doPost(Map<?, ?> parameters, URL url)
        throws UnsupportedEncodingException, IOException, KeyManagementException, NoSuchAlgorithmException {

    URLConnection cnx = getConnection(url);

    // Construct data
    StringBuilder dataBfr = new StringBuilder();
    Iterator<?> iKeys = parameters.keySet().iterator();
    while (iKeys.hasNext()) {
        if (dataBfr.length() != 0) {
            dataBfr.append('&');
        }
        String key = (String) iKeys.next();
        dataBfr.append(URLEncoder.encode(key, "UTF-8")).append('=')
                .append(URLEncoder.encode((String) parameters.get(key), "UTF-8"));
    }
    // POST data
    cnx.setDoOutput(true);

    OutputStreamWriter wr = new OutputStreamWriter(cnx.getOutputStream());
    if (LOGGING.DEBUG)
        Log.d(LOG_TAG, "Posting crash report data");
    wr.write(dataBfr.toString());
    wr.flush();
    wr.close();

    if (LOGGING.DEBUG)
        Log.d(LOG_TAG, "Reading response");
    BufferedReader rd = new BufferedReader(new InputStreamReader(cnx.getInputStream()));

    String line;
    int linecount = 0;
    while ((line = rd.readLine()) != null) {
        linecount++;
        if (linecount <= 2) {
            if (LOGGING.DEBUG)
                Log.d(LOG_TAG, line);
        }
    }
    rd.close();
}

From source file:Main.java

/**
 * Removes the first occurrence of the given character from the string
 * @param c - character to remove (first occurrence)
 * @param str- string to search/*from   w w w . ja v a2  s  .  com*/
 * @return - a copy of str without the character c
 */
public static String removeCharFromString(char c, String str) {
    StringBuilder resultStrBuilder = new StringBuilder(str);
    String returnStr = "";
    int charPos = str.indexOf(c);
    int strLen = str.length();
    if ((charPos >= 0) && (strLen > 0)) {
        resultStrBuilder.deleteCharAt(charPos);
    }
    if (resultStrBuilder.length() > 0) {
        returnStr = resultStrBuilder.toString();
    }
    return returnStr;
}

From source file:Main.java

private static <T> String formatCollection(Collection<T> collection, int maxLen) {
    StringBuilder builder = new StringBuilder();
    builder.append("[");

    boolean first = true;
    for (T elem : collection) {
        String val = ((first) ? ", " : "") + ((elem != null) ? elem.toString() : "null");
        first = false;/*ww w  . j a  v a  2 s.  c o m*/
        if ((builder.length() + val.length()) > maxLen - "...]".length()) {
            builder.append("...");
            break;
        } else {
            builder.append(val);
        }
    }
    builder.append("]");
    return builder.toString();
}

From source file:org.psikeds.resolutionengine.interfaces.pojos.POJO.java

protected static String composeId(final String... ids) {
    final StringBuilder sb = new StringBuilder();
    for (final String pid : ids) {
        if (!StringUtils.isEmpty(pid)) {
            if (sb.length() > 0) {
                sb.append(COMPOSE_ID_SEPARATOR);
            }//  w  w w . jav a2 s .  c o  m
            sb.append(pid);
        }
    }
    return sb.toString();
}

From source file:org.psikeds.queryagent.interfaces.presenter.pojos.POJO.java

public static String composeId(final String... ids) {
    final StringBuilder sb = new StringBuilder();
    for (final String pid : ids) {
        if (!StringUtils.isEmpty(pid)) {
            if (sb.length() > 0) {
                sb.append(COMPOSE_ID_SEPARATOR);
            }/*from  w w  w.j a  v  a  2  s .c o m*/
            sb.append(pid);
        }
    }
    return sb.toString();
}

From source file:de.hybris.platform.acceleratorstorefrontcommons.util.MetaSanitizerUtil.java

/**
 * Takes a List of keyword Strings and returns a comma separated list of keywords as String.
 *
 * @param keywords//w ww .  ja  va2s .  c  om
 *           List of KeywordModel objects
 * @return String of comma separated keywords
 */
public static String sanitizeKeywords(final Collection<String> keywords) {
    if (keywords != null && !keywords.isEmpty()) {
        // Remove duplicates
        final Set<String> keywordSet = new HashSet<String>(keywords);

        // Format keywords, join with comma
        final StringBuilder stringBuilder = new StringBuilder();
        for (final String keyword : keywordSet) {
            stringBuilder.append(keyword).append(',');
        }
        if (stringBuilder.length() > 0) {
            // Remove last comma
            return stringBuilder.substring(0, stringBuilder.length() - 1);
        }
    }
    return "";
}

From source file:Main.java

public static <E> void print(E[] objs) {
    StringBuilder builder = new StringBuilder();
    for (E e : objs) {
        if (e == null) {
            builder.append(",null");
        } else {//ww w  . ja v  a2 s  . c o m
            builder.append("," + e.toString());
        }
    }
    System.out.println(builder.substring(1, builder.length()));
}

From source file:com.intuit.tank.search.util.SearchUtils.java

/**
 * creates a compound field term using the terms provided.
 * /* www .  j  av a  2  s . c  om*/
 * @param delimiter
 *            the delimiter to use
 * @param term
 *            varargs terms to concatenate
 * @return the concatenated string separated by the delimiter.
 */
public static final String makeCompoundField(String delimiter, String... term) {
    StringBuilder sb = new StringBuilder();
    for (String s : term) {
        if (s.length() != 0) {
            if (delimiter != null && sb.length() != 0) {
                sb.append(delimiter);
            }
            sb.append(s);
        }
    }
    return sb.toString();
}

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  w  w . j  a  v  a2 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();
}