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:Main.java

public static Pair<String, String> ReorderRTLTextForPebble(String source, int charLimit) {
    if (source == null || source.equals(""))
        return new Pair<>("", "");

    if (!hebrewPattern.matcher(source).find()) {
        return new Pair<>(source, "");
    } else {//from w  ww .j a  v a 2  s.com

        StringBuilder sbResult = new StringBuilder();
        StringBuilder sbExtraResult = new StringBuilder();
        StringBuilder sbTemp = new StringBuilder();
        String[] words = source.split(" ");
        int charCount = 0;

        for (int wordIndex = 0; wordIndex < words.length; wordIndex++, sbTemp.setLength(0)) {
            sbTemp.append(words[wordIndex]);
            charCount += sbTemp.length();
            Matcher hebrewWord = hebrewPattern.matcher(words[wordIndex]);

            if (hebrewWord.find()) {
                sbTemp.reverse();
                if (sbTemp.charAt(0) == ')') {
                    sbTemp.replace(0, 1, "(");
                }
                if (sbTemp.charAt(sbTemp.length() - 1) == '(') {
                    sbTemp.replace(sbTemp.length() - 1, sbTemp.length(), ")");
                }
            }

            if (charCount <= charLimit) {
                sbResult.insert(0, sbTemp + " ");
            } else {
                sbExtraResult.insert(0, sbTemp + " ");
            }

            charCount++;
        }

        if (sbExtraResult.length() > charLimit) {
            sbExtraResult.replace(0, sbExtraResult.length() - charLimit, "...");
        }

        return new Pair<>(sbResult.toString().trim(), sbExtraResult.toString().trim());
    }
}

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

public static String composeId(final POJO... pojos) {
    final StringBuilder sb = new StringBuilder();
    for (final POJO p : pojos) {
        final String pid = (p == null ? null : p.getId());
        if (!StringUtils.isEmpty(pid)) {
            if (sb.length() > 0) {
                sb.append(COMPOSE_ID_SEPARATOR);
            }/* w  ww .ja  v a2 s .  c  o m*/
            sb.append(pid);
        }
    }
    return sb.toString();
}

From source file:eu.prestoprime.p4gui.connection.SearchConnection.java

/**
 * encode all facet values into a string.
 * /*from  w  ww. j ava2  s  .  c  o m*/
 * @param facetMap
 * @return
 */
private static String wrapParams(Map<String, String> facetMap) {
    StringBuilder sb = new StringBuilder();

    for (Entry<String, String> e : facetMap.entrySet()) {
        if (sb.length() > 0) {
            sb.append(SearchConstants.KV_SEP);
        }
        if (e.getValue() != null && !filter(e.getValue()).isEmpty()) {
            sb.append(filter(e.getKey()) + SearchConstants.KV_CON + filter(e.getValue()));
        }
    }
    return sb.toString();
}

From source file:com.indoqa.lang.util.URLStringUtils.java

public static StringBuilder cleanMultipleChar(StringBuilder text, char doubleCh) {
    if (text == null) {
        return null;
    }//w w  w. ja  v a 2  s.  c  o  m

    StringBuilder result = new StringBuilder();

    char previousChar = 0;
    for (int i = 0; i < text.length(); i++) {
        char currentChar = text.charAt(i);

        if (previousChar == doubleCh && previousChar == currentChar) {
            previousChar = currentChar;
            continue;
        }

        previousChar = currentChar;
        result.append(currentChar);
    }

    return result;
}

From source file:Main.java

/**
 * Returns a String that is suitable for use as an <code>application/x-www-form-urlencoded</code>
 * list of parameters in an HTTP PUT or HTTP POST.
 *
 * @param parameters  The parameters to include.
 * @param encoding The encoding to use./*w  w w.java 2s  .co m*/
 */
public static String format(final List<Pair<String, String>> parameters, final String encoding) {
    final StringBuilder result = new StringBuilder();
    for (final Pair<String, String> parameter : parameters) {
        final String encodedName = encode(parameter.first, encoding);
        final String value = parameter.second;
        final String encodedValue = value != null ? encode(value, encoding) : "";
        if (result.length() > 0)
            result.append(PARAMETER_SEPARATOR);
        result.append(encodedName);
        result.append(NAME_VALUE_SEPARATOR);
        result.append(encodedValue);
    }
    return result.toString();
}

From source file:com.evolveum.midpoint.repo.sql.data.common.RObjectTextInfo.java

private static Set<RObjectTextInfo> createItemsSet(RObject repo, List<String> allWords) {
    Set<RObjectTextInfo> rv = new HashSet<>();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < allWords.size(); i++) {
        String word = allWords.get(i);
        if (sb.length() + word.length() + 2 <= MAX_TEXT_SIZE) {
            sb.append(" ").append(word);
        } else {//  w  w w  .  j  a  v a2 s  .co m
            if (sb.length() > 0) {
                sb.append(" ");
                rv.add(new RObjectTextInfo(repo, sb.toString()));
                sb = new StringBuilder();
                i--; // to reiterate
            } else {
                // a problem - too large string
                LOGGER.warn("Word too long to be correctly indexed: {}", word);
                rv.add(new RObjectTextInfo(repo, " " + word.substring(0, MAX_TEXT_SIZE - 2) + " "));
                allWords.set(i, word.substring(MAX_TEXT_SIZE - 2));
                i--; // to reiterate (with shortened word)
            }
        }
    }
    if (sb.length() > 0) {
        sb.append(" ");
        rv.add(new RObjectTextInfo(repo, sb.toString()));
    }
    return rv;
}

From source file:com.ebay.cloud.cms.service.resources.impl.CMSResourceUtils.java

private static String joinToParameter(int[] values) {
    StringBuilder sb = new StringBuilder();
    for (Object o : values) {
        sb.append(o.toString()).append(',');
    }/*w w  w  . j  av  a2  s . c o m*/
    if (sb.length() > 0) {
        sb.setLength(sb.length() - 1);
    }
    return sb.toString();
}

From source file:com.expedia.tesla.compiler.Util.java

/**
 * Convert a list of elements to a single delimiter separated string.
 * /*  w w w .j  a  va  2  s .co  m*/
 * @param list
 *       the collection of values to join together.
 * @param delimiter
 *       the delimiter that separates values.
 * 
 * @return
 *       a single delimiter separated string.
 */
public static <T> String delimiterSeparate(Collection<T> list, String delimiter) {
    StringBuilder sb = new StringBuilder();
    for (T e : list) {
        if (sb.length() > 0) {
            sb.append(delimiter);
        }
        sb.append(e.toString());
    }
    return sb.toString();
}

From source file:com.modcrafting.ultrabans.util.Formatting.java

public static String combineSplit(int startIndex, String[] string, String seperator) {
    StringBuilder builder = new StringBuilder();
    if (string.length >= 1) {
        for (int i = startIndex; i < string.length; i++) {
            builder.append(string[i]);/* w w w . j  a v  a2s .com*/
            builder.append(seperator);
        }

        if (builder.length() > seperator.length()) {
            builder.deleteCharAt(builder.length() - seperator.length()); // remove
            return builder.toString();
        }
    }
    return Ultrabans.DEFAULT_REASON;
}

From source file:com.quatico.base.aem.test.api.values.TestFile.java

public static String path(String... segments) {
    StringBuilder buf = new StringBuilder();
    for (int count = 0, idx = 0; idx < segments.length; idx++) {
        String cur = segments[idx];
        if (StringUtils.isBlank(cur) && count == 0 || StringUtils.isNotBlank(cur) && buf.length() > 1) {
            buf.append(File.separator);
        }//w  w w . ja  va  2  s .  c o  m
        if (StringUtils.isNotBlank(cur)) {
            buf.append(cur);
        }
        count++;
    }
    String result = buf.toString();
    if (result.matches("^\\\\[\\w]{1}:")) { // java.io.File cannot handle leading slashes before drive letters on Windows
        result = result.substring(1);
    }
    return result.replace(ILLEGAL_FILE_SEPARATOR, File.separatorChar);
}