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:ch.rasc.wampspring.message.BaseMessageTest.java

@SuppressWarnings({ "rawtypes", "unchecked" })
static String toJsonArray(Object... arguments) {
    StringBuilder sb = new StringBuilder();
    sb.append("[");

    for (Object argument : arguments) {
        if (sb.length() > 1) {
            sb.append(",");
        }//from   w ww . j  a v a2s  . c o m
        if (argument != null) {
            if (argument instanceof Number) {
                sb.append(argument);
            } else if (argument instanceof Boolean) {
                sb.append(argument);
            } else if (argument instanceof String) {
                sb.append("\"").append(argument).append("\"");
            } else if (argument instanceof List) {
                sb.append("[");
                boolean first = true;
                for (Object entry : (List) argument) {
                    if (!first) {
                        sb.append(",");
                    } else {
                        first = false;
                    }
                    if (entry instanceof String) {
                        sb.append("\"").append(entry).append("\"");
                    } else {
                        sb.append(entry);
                    }
                }
                sb.append("]");
            } else if (argument instanceof Map) {
                Map<String, Object> map = (Map<String, Object>) argument;
                sb.append("{");
                boolean first = true;
                for (String key : map.keySet()) {
                    if (!first) {
                        sb.append(",");
                    } else {
                        first = false;
                    }
                    sb.append("\"").append(key).append("\"");
                    sb.append(":");
                    Object value = map.get(key);
                    if (value instanceof String) {
                        sb.append("\"").append(value).append("\"");
                    } else {
                        sb.append(value);
                    }
                }
                sb.append("}");
            }
        } else {
            sb.append("null");
        }
    }

    sb.append("]");
    return sb.toString();
}

From source file:com.wiiyaya.framework.common.utils.NumberFormatUtils.java

private static void removeFstOne(StringBuilder sb, String[] numCn, String[] digitCnLow) {
    if (sb.length() > 1 && sb.substring(0, 2).equals(numCn[1] + digitCnLow[1])) {
        sb.deleteCharAt(0);/*from w w w .  ja  v a  2  s . c  o m*/
    }
}

From source file:Main.java

/**
 * For logging, extremely unnecessary.//  www.  j a v  a2s.  co  m
 *
 * @param list
 * @return
 */
public static <T> String list2str(List<T> list) {
    StringBuilder sb = new StringBuilder();
    if (list != null && !list.isEmpty()) {
        sb.append("[");
        for (T t : list) {
            sb.append(t.toString()).append(", ");
        }
        sb.delete(sb.length() - 2, sb.length());
        sb.append("]");
    }
    return sb.toString();
}

From source file:Main.java

public static String encodeUrl(String url) {
    Uri uri = Uri.parse(url);/*from   w  ww  .j a  va  2 s.  c  o m*/

    try {
        Map<String, List<String>> splitQuery = splitQuery(uri);
        StringBuilder encodedQuery = new StringBuilder();
        for (String key : splitQuery.keySet()) {
            for (String value : splitQuery.get(key)) {
                if (encodedQuery.length() > 0) {
                    encodedQuery.append("&");
                }
                encodedQuery.append(key + "=" + URLEncoder.encode(value, "UTF-8"));
            }
        }
        String queryString = encodedQuery != null && encodedQuery.length() > 0 ? "?" + encodedQuery : "";

        URI baseUri = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, uri.getFragment());
        return baseUri + queryString;
    } catch (UnsupportedEncodingException ignore) {
    } catch (URISyntaxException ignore) {
    }

    return uri.toString();
}

From source file:Main.java

public static URL getString(URL str) {
    String ssString = str.toString();
    String[] aaStrings = ssString.split("/");
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < aaStrings.length; i++) {
        if (i == 4) {
            aaStrings[i] = "180";
        }//ww  w  . jav a  2 s.  c  o  m
        sb.append(aaStrings[i] + "/");
    }
    sb.deleteCharAt(sb.length() - 1);
    URL url = null;
    try {
        url = new URL(sb.toString());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return url;
}

From source file:eu.codebits.plasmas.util.NetworkInterfaces.java

/**
 *
 * @param interfaceName//from w w  w .ja  v a 2  s .co  m
 * @return
 */
public static String getMACAddress(String interfaceName) {
    try {
        List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface intf : interfaces) {
            if (interfaceName != null) {
                if (!intf.getName().equalsIgnoreCase(interfaceName))
                    continue;
            }
            byte[] mac = intf.getHardwareAddress();
            if (mac == null)
                continue;//return "";
            StringBuilder buf = new StringBuilder();
            for (int idx = 0; idx < mac.length; idx++)
                buf.append(String.format("%02X:", mac[idx]));
            if (buf.length() > 0)
                buf.deleteCharAt(buf.length() - 1);
            return buf.toString();
        }
    } catch (SocketException ex) {
    }
    return "";
}

From source file:io.wcm.devops.conga.generator.util.VariableStringResolver.java

@SuppressWarnings("unchecked")
private static String valueToString(Object value) {
    if (value == null) {
        return "";
    } else if (value instanceof List) {
        StringBuilder sb = new StringBuilder();
        for (Object item : ((List) value)) {
            if (sb.length() > 0) {
                sb.append(",");
            }/*from   w w w  .  ja v a2 s  . co m*/
            sb.append(valueToString(item));
        }
        return sb.toString();
    } else if (value instanceof Map) {
        StringBuilder sb = new StringBuilder();
        // use sorted map to ensure consistent order of keys
        SortedMap<Object, Object> sortedMap = new TreeMap<>((Map<Object, Object>) value);
        for (Map.Entry<Object, Object> entry : sortedMap.entrySet()) {
            if (sb.length() > 0) {
                sb.append(",");
            }
            sb.append(valueToString(entry.getKey()));
            sb.append("=");
            sb.append(valueToString(entry.getValue()));
        }
        return sb.toString();
    } else {
        return value.toString();
    }
}

From source file:StringUtil.java

/**
 * Convert the String s to proper case.// w  w w . j  a  v  a 2 s  .c  o m
 * 
 * @param s String
 * @return String
 */
public static String toProperCase(String s) {
    StringBuilder sb = new StringBuilder();

    for (String f : s.split(" ")) {
        if (sb.length() > 0) {
            sb.append(" ");
        }
        sb.append(f.substring(0, 1).toUpperCase()).append(f.substring(1, f.length()).toLowerCase());
    }

    return sb.toString();
}

From source file:de.micromata.genome.gwiki.web.tags.GWikiTagRenderUtils.java

public static void renderAttribute(Object tag, Pair<Field, ? extends Annotation> p, StringBuilder sb) {
    Object value = PrivateBeanUtils.readField(tag, p.getFirst());
    if (value == null) {
        return;/*  ww  w.ja va2  s  .  c  o m*/
    }

    if (sb.length() > 0) {
        sb.append(" ");
    }
    ElementProperty an = (ElementProperty) p.getSecond();
    String svalue = value.toString();
    if (an.ignoreValue().length() > 0 && an.ignoreValue().equals(svalue) == true) {
        return;
    }
    String name = an.name();
    if (StringUtils.isEmpty(name) == true) {
        name = p.getFirst().getName();
    }
    sb.append(name).append("=").append("\"").append(StringEscapeUtils.escapeXml(ObjectUtils.toString(value)))
            .append("\"");
}

From source file:Main.java

public static String join(String[] paramArrayOfString) {
    StringBuilder localStringBuilder = new StringBuilder(11 * paramArrayOfString.length);
    int i = paramArrayOfString.length;
    for (int j = 0; j < i; j++) {
        String str = paramArrayOfString[j];
        if (localStringBuilder.length() != 0)
            localStringBuilder.append(",");
        localStringBuilder.append(str);/*  w  w w. j a  va2s. co m*/
    }
    return localStringBuilder.toString();
}