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:net.daporkchop.porkselfbot.util.HTTPUtils.java

/**
 * Turns the specified Map into an encoded & escaped query
 *
 * @param query Map to convert into a text based query
 * @return Resulting query./* ww  w.java2s .  com*/
 */
public static String buildQuery(final Map<String, Object> query) {
    if (query == null) {
        return "";
    }
    final StringBuilder builder = new StringBuilder();

    for (final Map.Entry<String, Object> entry : query.entrySet()) {
        if (builder.length() > 0) {
            builder.append('&');
        }

        try {
            builder.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
        } catch (final UnsupportedEncodingException e) {
        }

        if (entry.getValue() != null) {
            builder.append('=');
            try {
                builder.append(URLEncoder.encode(entry.getValue().toString(), "UTF-8"));
            } catch (final UnsupportedEncodingException e) {
            }
        }
    }

    return builder.toString();
}

From source file:ai.susi.mind.SusiPhrase.java

public static String parsePattern(String expression) {
    String[] expressions = expression.split("\\|");
    if (expressions.length == 0)
        return "";
    if (expressions.length == 1)
        return parseOnePattern(expressions[0]);
    StringBuilder sb = new StringBuilder();
    for (String e : expressions)
        sb.append("(?:").append(parseOnePattern(e)).append(")|");
    return sb.substring(0, sb.length() - 1);
}

From source file:com.github.benyzhous.springboot.web.core.gateway.sign.backend.Sign.java

/**
 * Map?&?=/*from w w w  . ja  v  a 2s.  co m*/
 */
private static String buildMapToSign(Map<String, Object> paramMap) {
    StringBuilder builder = new StringBuilder();

    for (Map.Entry<String, Object> e : paramMap.entrySet()) {
        if (builder.length() > 0) {
            builder.append('&');
        }

        String key = e.getKey();
        Object value = e.getValue();

        if (value != null) {
            if (value instanceof List) {
                @SuppressWarnings("rawtypes")
                List list = (List) value;
                if (list.size() == 0) {
                    builder.append(key);
                } else {
                    builder.append(key).append("=").append(String.valueOf(list.get(0)));
                }
            } else if (value instanceof Object[]) {
                Object[] objs = (Object[]) value;
                if (objs.length == 0) {
                    builder.append(key);
                } else {
                    builder.append(key).append("=").append(String.valueOf(objs[0]));
                }
            } else {
                builder.append(key).append("=").append(String.valueOf(value));
            }
        }
    }

    return builder.toString();
}

From source file:Main.java

/**
 * Converts a {@link android.os.Bundle} object to a {@code String}.
 *
 * @param bundle The converted bundle.//  ww w . j a v  a2s.  c  om
 * @return The string representation of the bundle.
 */
@NonNull
public static String toString(@Nullable final Bundle bundle) {
    if (bundle == null) {
        return "null";
    }

    if (bundle.isEmpty()) {
        return "";
    }

    final StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append('[');
    for (String key : bundle.keySet()) {
        stringBuilder.append('"').append(key).append("\":\"").append(bundle.get(key)).append('"')
                .append(ITEM_DIVIDER);
    }
    stringBuilder.setLength(stringBuilder.length() - ITEM_DIVIDER.length());
    stringBuilder.append(']');
    return stringBuilder.toString();
}

From source file:Main.java

@Nullable
public static CharSequence join(@NonNull CharSequence divider, @NonNull CharSequence... array) {
    StringBuilder sb = new StringBuilder();

    boolean divide = false;
    for (CharSequence cs : array) {
        if (cs != null) {
            if (divide) {
                sb.append(divider);/*  w  w  w . j a va 2  s  . c o m*/
            } else {
                divide = true;
            }
            sb.append(cs);
        }
    }

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

From source file:it.geosolutions.geostore.services.rest.auditing.AuditInfoExtractor.java

private static String groupsToString(Set<UserGroup> groups) {
    if (groups.isEmpty()) {
        return null;
    }/*from ww w.ja  v a 2 s .  c  o m*/
    StringBuilder groupsString = new StringBuilder();
    for (UserGroup userGroup : groups) {
        groupsString.append(userGroup.getGroupName()).append(",");
    }
    groupsString.deleteCharAt(groupsString.length() - 1);
    return groupsString.toString();
}

From source file:net.sourceforge.vulcan.subversion.SubversionProjectConfigurator.java

protected static SubversionRepositoryProfileDto findOrCreateProfile(SVNRepository repo,
        SubversionConfigDto globalConfig, ProjectConfigDto project, SubversionProjectConfigDto raProjectConfig,
        String absoluteUrl, String username, String password) throws SVNException {
    SubversionRepositoryProfileDto profile = findProfileByUrlPrefix(globalConfig, absoluteUrl);

    if (profile == null) {
        if (isNotBlank(username)) {
            repo.setAuthenticationManager(new BasicAuthenticationManager(username, password));
        }/*from   w w w .  j  a v a  2  s. co m*/

        final String root = repo.getRepositoryRoot(true).toString();

        profile = new SubversionRepositoryProfileDto();
        profile.setRootUrl(root);
        profile.setUsername(username);
        profile.setPassword(password);

        try {
            profile.setDescription(new URL(root).getHost());
        } catch (MalformedURLException e) {
            profile.setDescription(root);
        }

    }

    project.setRepositoryAdaptorPluginId(SubversionConfigDto.PLUGIN_ID);
    project.setRepositoryAdaptorConfig(raProjectConfig);

    raProjectConfig.setRepositoryProfile(profile.getDescription());

    final StringBuilder relativePath = new StringBuilder(absoluteUrl.substring(profile.getRootUrl().length()));

    relativePath.delete(relativePath.lastIndexOf("/"), relativePath.length());

    raProjectConfig.setPath(relativePath.toString());

    return profile;
}

From source file:com.ctriposs.rest4j.tools.idlcheck.Rest4JResourceModelCompatibilityChecker.java

private static String listCompatLevelOptions() {
    final StringBuilder options = new StringBuilder("<");
    for (CompatibilityLevel compatLevel : CompatibilityLevel.values()) {
        options.append(compatLevel.name().toLowerCase()).append("|");
    }//from   w  ww  .j a va 2s  .c o  m
    options.replace(options.length() - 1, options.length(), ">");

    return options.toString();
}

From source file:com.cinchapi.concourse.importer.util.Importables.java

/**
 * Given a {@code line} that is separated by a {@code delimiter} character,
 * convert each token to fields within a single JSON object.
 * /*from  w  w w.ja v  a2s . c o m*/
 * @param line the data to convert
 * @param resolveKey a key that the
 *            {@link com.cinchapi.concourse.importer.Importer importer} uses
 *            to determine the existing records into which the data should
 *            be imported. The method places the appropriate resolve
 *            instruction in the JSON blob so Concourse Server can perform
 *            the resolution during the import
 * @param delimiter the delimiter character
 * @param header the list of header keys. If this list is empty, this method
 *            will return {@code null} and instead place the tokens from the
 *            {@code line} into the list
 * @param transformer the {@link Transformer} that is used to potentially
 *            alter key/value pairs before import
 * @return a JSON string that contains the raw {@code line} in the new
 *         format or {@code null} if {@code header} is
 *         {@link List#isEmpty() empty}
 * @throws IndexOutOfBoundsException if the line has more columns that there
 *             are header keys (as long as the number of header keys is >
 *             0); it is fine for a line to have fewer columns that header
 *             keys
 */
@Nullable
public static String delimitedStringToJsonObject(String line, @Nullable String resolveKey, char delimiter,
        List<String> header, @Nullable Transformer transformer) {
    StringBuilder builder = new StringBuilder();
    delimitedStringToJsonObject(line, resolveKey, delimiter, header, transformer, builder);
    return builder.length() == 0 ? null : builder.toString();
}

From source file:com.yahoo.sql4d.sql4ddriver.Util.java

public static String capitalize(String word) {
    StringBuilder buff = new StringBuilder(word);
    if (word.charAt(0) != '_') {
        buff.setCharAt(0, Character.toUpperCase(word.charAt(0)));
    }//  w w  w .  j a va2 s .  co m
    for (int i = 1; i < buff.length(); i++) {
        if (buff.charAt(i - 1) == '_') {
            buff.setCharAt(i, Character.toUpperCase(word.charAt(i)));
        }
    }
    return buff.toString().replace("_", "");
}