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.smartitengineering.version.api.factory.VersionAPI.java

/**
 * Throw away all the '/' from beginning and end of the resourceId.
 * @param resourceId Id to trim//from  www  .ja  v a2 s.  com
 * @return Trimmed version of the resourceId
 */
public static String trimToProperResourceId(String resourceId) {
    if (StringUtils.isBlank(resourceId)) {
        return "";
    }
    StringBuilder result = new StringBuilder(resourceId.trim());
    while (result.charAt(0) == '/') {
        result.deleteCharAt(0);
    }
    while (result.charAt(result.length() - 1) == '/') {
        result.deleteCharAt(result.length() - 1);
    }
    return result.toString();
}

From source file:ru.org.linux.tag.TagService.java

public static String toString(Collection<String> tags) {
    if (tags.isEmpty()) {
        return "";
    }/*from w  w w  . jav  a 2s .  c  om*/

    StringBuilder str = new StringBuilder();

    for (String tag : tags) {
        str.append(str.length() > 0 ? "," : "").append(tag);
    }

    return str.toString();
}

From source file:br.msf.commons.text.HexUtils.java

/**
 * Puts a separator between groups of <tt>groupLen</tt> nibbles.
 * <p/>/*from  w w  w. j  a va  2 s . co m*/
 * Also, puts leading zeroes when necessary.
 *
 * @param hexString The hex string to be formatted.
 * @param groupLen  The length of the groups of nibbles.
 * @return The formatted hex string.
 */
public static String format(final String hexString, final int groupLen) {
    final String unformatted = unformat(hexString);
    ArgumentUtils.rejectIfDontMatches(unformatted, HEX_PATTERN);
    final StringBuilder buffer = new StringBuilder();
    final StringBuilder formatted = new StringBuilder();
    for (int i = CharSequenceUtils.indexOfLastChar(unformatted); i >= 0; i--) {
        buffer.insert(0, unformatted.charAt(i));
        if (buffer.length() == groupLen) {
            /* When the buffer reaches 'groupLen' size, its contents is passed to 'formatted'. */
            if (i > 0) {
                /*
                 * If unprocessed chars remains on the original string, them we put the separator on the buffer
                 * start.
                 */
                buffer.insert(0, GROUP_SEPARATOR);
            }
            /* we pass the buffer value to the 'formatted' accumulator */
            formatted.insert(0, buffer);
            /* empty the buffer */
            buffer.replace(0, buffer.length(), "");
        }
    }
    /* If unprocessed chars remains on the buffer, it means that we need to fill it up with trailing zeroes. */
    if (buffer.length() > 0) {
        buffer.insert(0, StringUtils.repeat("0", groupLen - buffer.length()));
        /* we pass the buffer value to the 'formatted' accumulator */
        formatted.insert(0, buffer);
    }
    return formatted.toString();
}

From source file:com.github.gekoh.yagen.api.DefaultNamingStrategy.java

public static String concatColumnNames(String columnNameList) {
    StringBuilder colName = new StringBuilder();
    for (String s : columnNameList.split("[, ]")) {
        if (s.trim().length() < 1) {
            continue;
        }//from   w  ww .  jav a 2  s .c om

        if (colName.length() > 0) {
            colName.append("_");
        }
        colName.append(s.replace("_", ""));
    }
    return colName.toString();
}

From source file:Main.java

/**
 * Python-like joining strings!/*from  ww  w  . ja va 2  s.  c  om*/
 */
@Nullable
public static CharSequence join(@Nullable CharSequence divider, @NonNull CharSequence... array) {
    StringBuilder sb = new StringBuilder();

    boolean divide = false;
    for (CharSequence cs : array) {
        if (cs != null) {
            if (divide && divider != null) {
                sb.append(divider);
            } else {
                divide = true;
            }
            sb.append(cs);
        }
    }

    return sb.length() == 0 ? null : sb;
}

From source file:com.symphony.jirabot.clients.QuandlClient.java

private static String mapToQueryString(HashMap<String, Object> parameters) {
    if (parameters == null || parameters.size() == 0) {
        return "";
    }/*  w w  w  .j  a  va  2  s . c om*/

    StringBuilder queryString = new StringBuilder("&");
    for (String key : parameters.keySet()) {
        queryString.append(urlEncodeUTF8(key));
        queryString.append("=");
        queryString.append(urlEncodeUTF8(parameters.get(key).toString()));
        queryString.append("&");
    }

    if (queryString.charAt(queryString.length() - 1) == '&') {
        queryString = queryString.deleteCharAt(queryString.length() - 1);
    }

    return queryString.toString();
}

From source file:au.org.ala.delta.editor.EditorPreferences.java

/**
 * Removes the specified file from the most recently used file list
 * @param filename The filename to remove
 *//*from   www. ja va 2  s  .  com*/
public static void removeFileFromMRU(String filename) {

    String[] existingFiles = getPreviouslyUsedFiles();

    StringBuilder b = new StringBuilder();
    for (int i = 0; i < existingFiles.length; ++i) {

        if (!existingFiles[i].equalsIgnoreCase(filename)) {

            if (b.length() > 0) {
                b.append(MRU_SEPARATOR);
            }
            b.append(existingFiles[i]);
        }
    }

    Preferences prefs = Preferences.userNodeForPackage(DeltaEditor.class);
    prefs.put(MRU_PREF_KEY, b.toString());
    try {
        prefs.sync();
    } catch (BackingStoreException e) {
        throw new RuntimeException(e);
    }

}

From source file:Main.java

public static <T> T unsupported(final String op, final Object... a) {
    final StringBuilder msg = new StringBuilder(INITIAL_SIZE);
    msg.append("Nobody told me how to run ");
    msg.append(op);/*from  w w  w .ja v a2 s.c  om*/
    if (a.length > 0) {
        msg.append(" with parameters of class: ");
        for (final Object o : a) {
            msg.append(o == null ? "null" : o.getClass().getSimpleName());
            msg.append(", ");
        }
        msg.delete(msg.length() - 2, msg.length());
        msg.append('.');
    }
    throw new UnsupportedOperationException(msg.toString());
}

From source file:at.gv.egiz.slbinding.SLUnmarshaller.java

private static JAXBContext createJAXBContext(Collection<String> packageNames) throws JAXBException {
    StringBuilder contextPath = new StringBuilder();
    for (String pkg : packageNames) {
        if (contextPath.length() > 0) {
            contextPath.append(':');
        }//from w  w w  .  ja  v a  2s  .co m
        contextPath.append(pkg);
    }
    return JAXBContext.newInstance(contextPath.toString());
}

From source file:com.aliyun.odps.local.common.utils.SchemaUtils.java

/**
 * ???//  ww w . j  a  v  a 2  s  .c  om
 *
 * @param cols
 *     
 * @return ??
 * @see #fromString(String)
 */
public static String toString(Column[] cols) {
    if (cols == null) {
        return "";
    }
    StringBuilder sb = new StringBuilder();
    for (Column c : cols) {
        if (c == null) {
            continue;
        }
        if (sb.length() > 0) {
            sb.append(SEPERATOR);
        }
        sb.append(c.getName()).append(DELIMITER).append(c.getType().toString());
    }
    return sb.toString();
}