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.igormaznitsa.sciareto.preferences.FileHistoryManager.java

@Nonnull
private static String packToString(@Nonnull @MustNotContainNull final File[] files) {
    final StringBuilder result = new StringBuilder();
    for (final File f : files) {
        if (result.length() > 0) {
            result.append(File.pathSeparatorChar);
        }//from  w  w  w  .j av  a 2 s  .com
        result.append(FilenameUtils.normalize(f.getAbsolutePath()));
    }
    return result.toString();
}

From source file:com.ms.commons.test.math.expression.util.MathExpressionParseUtil.java

private static void checkIndex(int i, int fromIndex, int endIndex, char[] cs, StringBuilder lastTokens)
        throws MathParseException {
    if ((fromIndex == i) || (i == endIndex) || (lastTokens.length() == 0)) {
        StringBuilder sb = new StringBuilder(cs.length + 2);
        for (int csIndex = 0; csIndex < cs.length; csIndex++) {
            if (csIndex == i) {
                sb.append('[').append(cs[csIndex]).append(']');
            } else {
                sb.append(cs[csIndex]);//  w w  w. j a v  a2s  .  c om
            }
        }
        throw new MathParseException("Error grammer for '" + cs[i] + "' of '" + sb.toString() + "'.");
    }

}

From source file:io.wcm.maven.plugins.i18n.SlingI18nMap.java

/**
 * Creates a valid node name. Replaces all chars not in a-z, A-Z and 0-9 or '_', '.' with '-'.
 * @param value String to be labelized./*from  ww w. j  ava2  s  .co m*/
 * @return The labelized string.
 */
private static String validName(String value) {

    // replace some special chars first
    String text = value;
    text = StringUtils.replace(text, "", "ae");
    text = StringUtils.replace(text, "", "oe");
    text = StringUtils.replace(text, "", "ue");
    text = StringUtils.replace(text, "", "ss");

    // replace all invalid chars
    StringBuilder sb = new StringBuilder(text);
    for (int i = 0; i < sb.length(); i++) {
        char ch = sb.charAt(i);
        if (!((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9') || (ch == '_')
                || (ch == '.'))) {
            ch = '-';
            sb.setCharAt(i, ch);
        }
    }
    return sb.toString();
}

From source file:org.acra.HttpUtils.java

/**
 * Send an HTTP(s) request with POST parameters.
 * //ww  w. j  a  v  a  2 s.  c o  m
 * @param parameters
 * @param url
 * @throws UnsupportedEncodingException
 * @throws IOException
 * @throws KeyManagementException
 * @throws NoSuchAlgorithmException
 */
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());
    Log.d(LOG_TAG, "Posting crash report data");
    wr.write(dataBfr.toString());
    wr.flush();
    wr.close();

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

    String line;
    while ((line = rd.readLine()) != null) {
        Log.d(LOG_TAG, line);
    }
    rd.close();
}

From source file:com.acc.storefront.util.MetaSanitizerUtil.java

/**
 * Takes a List of KeywordModels and returns a comma separated list of keywords as String.
 * /*from w w w  .  j  a va2  s .c o  m*/
 * @param keywords
 *           List of KeywordModel objects
 * @return String of comma separated keywords
 */
public static String sanitizeKeywords(final List<KeywordModel> keywords) {
    if (keywords != null && !keywords.isEmpty()) {
        // Remove duplicates
        final Set<String> keywordSet = new HashSet<String>(keywords.size());
        for (final KeywordModel keyword : keywords) {
            keywordSet.add(keyword.getKeyword());
        }

        // 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:com.homesnap.webserver.utils.JSonTools.java

public final static String toJsonGroups(List<Group> groups) {
    StringBuilder sb = new StringBuilder("[");
    for (Group group : groups) {
        sb.append(JSonTools.toJson(group));
        sb.append(",");
    }/*from  www.  j av a 2s  .  com*/
    if (sb.length() > 1) {
        sb.setLength(sb.length() - 1);
    }
    sb.append("]");
    return sb.toString();
}

From source file:com.homesnap.webserver.utils.JSonTools.java

public final static String toJson(List<Label> labels) {
    StringBuilder sb = new StringBuilder("[");
    for (Label label : labels) {
        sb.append(JSonTools.toJson(label));
        sb.append(",");
    }/*  w w  w.  ja  v  a 2s . c o  m*/
    if (sb.length() > 1) {
        sb.setLength(sb.length() - 1);
    }
    sb.append("]");
    return sb.toString();
}

From source file:Main.java

public static String getQuanBuFenLeiName(String[] choices, String defaultQuanbufenlei, String defaultItemName) {

    if (choices.length < 3) {

        return defaultQuanbufenlei;
    }/*from www. j ava  2s  . c o m*/

    if (choices[0].equals(defaultItemName) && choices[1].equals(defaultItemName)
            && choices[2].equals(defaultItemName)) {

        return defaultQuanbufenlei;
    } else {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < choices.length; i++) {

            if (!choices[i].equals(defaultItemName)) {
                sb.append(choices[i] + "/");
            }
        }

        sb.deleteCharAt(sb.length() - 1);
        return sb.toString();
    }

}

From source file:gov.bnl.channelfinder.api.JSONProperties.java

/**
 * Creates a compact string representation for the log.
 *
 * @param data JSONChannel to create the string representation for
 * @return string representation//from  w ww  .j  a  v a  2s. co m
 */
public static String toLog(JSONProperties data) {
    if (data.getProperties().size() == 0) {
        return "[None]";
    } else {
        StringBuilder s = new StringBuilder();
        s.append("[");
        for (JSONProperty p : data.getProperties()) {
            s.append(JSONProperty.toLog(p) + ",");
        }
        s.delete(s.length() - 1, s.length());
        s.append("]");
        return s.toString();
    }
}

From source file:com.qwazr.utils.HtmlUtils.java

public final static String urlHostPathWrapReduce(String url, int maxSize) {
     URL u;//from  w  ww .j  a v  a2s.c  o  m
     try {
         u = new URL(url);
     } catch (MalformedURLException e) {
         return url;
     }
     String path = StringUtils.fastConcat(u.getHost(), '/', u.getPath());
     String[] frags = StringUtils.split(path, '/');
     if (frags.length < 2)
         return path;
     int startPos = 1;
     int endPos = frags.length - 2;
     StringBuilder sbStart = new StringBuilder(frags[0]);
     StringBuilder sbEnd = new StringBuilder(frags[frags.length - 1]);
     int length = sbStart.length() + sbEnd.length();
     for (;;) {
         boolean bHandled = false;
         if (startPos != -1 && startPos < endPos) {
             if (frags[startPos].length() + length < maxSize) {
                 sbStart.append('/');
                 sbStart.append(frags[startPos++]);
                 bHandled = true;
             }
         }
         if (endPos != -1 && endPos > startPos) {
             if (frags[endPos].length() + length < maxSize) {
                 sbEnd.insert(0, '/');
                 sbEnd.insert(0, frags[endPos--]);
                 bHandled = true;
             }
         }
         if (!bHandled)
             break;
     }
     return StringUtils.fastConcat(sbStart, "//", sbEnd);
 }