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:edu.msu.nscl.olog.Logs.java

public static String toLogger(List<Log> data) {
    if (data.size() == 0) {
        return "[None]";
    } else {//  w w  w  .  ja v a 2 s .c o  m
        StringBuilder s = new StringBuilder();
        s.append("[");
        for (Log c : data) {
            s.append(Log.toLogger(c) + ",");
        }
        s.delete(s.length() - 1, s.length());
        s.append("]");
        return s.toString();
    }
}

From source file:Main.java

public static boolean getNextPermutation(StringBuilder sb) {
    List<Character> list = asList(sb.toString().toCharArray());
    boolean ret = getNextPermutation(list);

    Object[] array = list.toArray();
    sb.delete(0, sb.length());
    sb.append(toCharArray(array));//from ww w  . ja v a 2  s .com

    return ret;
}

From source file:com.hoiio.sdk.util.StringUtil.java

/**
 * Converts the {@code List} to comma-separated {@code String}
 * @param dests {@code List<String>}
 * @return The comma-separated {@code String}
 *//*  w  w  w .j ava 2  s. c o m*/
public static String convertListToString(List<String> dests) {
    StringBuilder destString = new StringBuilder();
    for (String dest : dests) {
        destString.append(dest + ",");
    }

    // remove the last ","
    destString.deleteCharAt(destString.length() - 1);
    return destString.toString();
}

From source file:com.epam.dlab.core.parser.CommonFormat.java

/**
 * Add the column value to string in CSV format.
 *
 * @param sb    the buffer of sting.//from  w w  w  .ja v a2 s.co m
 * @param value the value.
 * @return the buffer of string.
 */
private static StringBuilder addToStringBuilder(StringBuilder sb, String value) {
    if (sb.length() > 0) {
        sb.append(FIELD_SEPARATOR);
    }
    return sb.append(FIELD_DELIMITER)
            .append(StringUtils.replace(value, DELIMITER_REPLACE_FROM, DELIMITER_REPLACE_TO))
            .append(FIELD_DELIMITER);
}

From source file:com.exampleka.jksonlib.JacksonRequest.java

/**
 * Converts a base URL, endpoint, and parameters into a full URL
 *
 * @param method The {@link com.android.volley.Request.Method} of the URL
 * @param baseUrl The base URL//from  www. j a  v  a  2 s. c  o  m
 * @param endpoint The endpoint being hit
 * @param params The parameters to be appended to the URL if a GET method is used
 *
 * @return The full URL
 */
private static String getUrl(int method, String baseUrl, String endpoint, Map<String, String> params) {
    if (params != null) {
        for (Map.Entry<String, String> entry : params.entrySet()) {
            if (entry.getValue() == null || entry.getValue().equals("null")) {
                entry.setValue("");
            }
        }
    }

    if (method == Method.GET && params != null && !params.isEmpty()) {
        final StringBuilder result = new StringBuilder(baseUrl + endpoint);
        final int startLength = result.length();
        for (String key : params.keySet()) {
            try {
                final String encodedKey = URLEncoder.encode(key, "UTF-8");
                final String encodedValue = URLEncoder.encode(params.get(key), "UTF-8");
                if (result.length() > startLength) {
                    result.append("&");
                } else {
                    result.append("?");
                }
                result.append(encodedKey);
                result.append("=");
                result.append(encodedValue);
            } catch (Exception e) {
            }
        }
        return result.toString();
    } else {
        return baseUrl + endpoint;
    }
}

From source file:com.jaeksoft.searchlib.util.ActiveDirectory.java

private static String getDomainSearch(String domain) {
    String[] dcs = StringUtils.split(domain.toUpperCase(), '.');
    StringBuilder sb = new StringBuilder();
    for (String dc : dcs) {
        if (sb.length() > 0)
            sb.append(',');
        sb.append("DC=");
        sb.append(dc);//from w w w . j  a  va2s .  c o  m
    }
    return sb.toString();
}

From source file:dk.dma.msiproxy.web.TldFunctions.java

/**
 * Formats the lat-lon position in the given locale and format
 * @param locale the locale/* ww w  .j  av  a  2 s.c o m*/
 * @param format the format, either "dec" or "sec" for decimal and second formats respectively
 * @param lat the latitude
 * @param lon the longitude
 * @return the formatted position
 */
public static String formatPos(Locale locale, String format, Double lat, Double lon) {
    PositionFormatter.Format fmt = ("sec".equalsIgnoreCase(format)) ? PositionFormatter.LATLON_SEC
            : PositionFormatter.LATLON_DEC;
    if (locale == null) {
        locale = Locale.ENGLISH;
    }
    StringBuilder pos = new StringBuilder();
    if (lat != null) {
        pos.append(PositionFormatter.format(locale, fmt.getLatFormat(), lat));
    }
    if (lon != null) {
        if (pos.length() > 0) {
            pos.append(" ");
        }
        pos.append(PositionFormatter.format(locale, fmt.getLonFormat(), lon));
    }
    return pos.toString();
}

From source file:Main.java

public static String _10_to_62(long number, int length) {
    Long rest = number;/*from w w w .  j ava  2s . co m*/
    Stack<Character> stack = new Stack<Character>();
    StringBuilder result = new StringBuilder(0);
    while (rest != 0) {
        stack.add(charSet[new Long((rest - (rest / 62) * 62)).intValue()]);
        rest = rest / 62;
    }
    for (; !stack.isEmpty();) {
        result.append(stack.pop());
    }
    int result_length = result.length();
    StringBuilder temp0 = new StringBuilder();
    for (int i = 0; i < length - result_length; i++) {
        temp0.append('0');
    }

    return temp0.toString() + result.toString();

}

From source file:Main.java

public static String hashMapToString(Map<? extends Object, ? extends Object> map) {
    Set<?> entrySet = map.entrySet();
    Iterator<?> it = entrySet.iterator();
    Map.Entry<? extends Object, ? extends Object> entry = null;
    StringBuilder strbldr = new StringBuilder();
    strbldr.append("{ ");
    while (it.hasNext()) {
        entry = (Entry<? extends Object, ? extends Object>) it.next();
        strbldr.append(entry.getKey() + ":" + entry.getValue() + ", ");
    }//from   w  ww  .  ja v  a  2 s .  c  o m
    return new StringBuilder(strbldr.substring(0, strbldr.length() - 2)).append(" }").toString();
}

From source file:hudson.plugins.ec2.EC2AxisPrivateKey.java

static String digest(PrivateKey k) throws IOException {
    try {// w  w  w .  ja v a  2s.c  o m
        MessageDigest md5 = MessageDigest.getInstance("SHA1");

        DigestInputStream in = new DigestInputStream(new ByteArrayInputStream(k.getEncoded()), md5);
        try {
            while (in.read(new byte[128]) > 0)
                ; // simply discard the input
        } finally {
            in.close();
        }
        StringBuilder buf = new StringBuilder();
        char[] hex = Hex.encodeHex(md5.digest());
        for (int i = 0; i < hex.length; i += 2) {
            if (buf.length() > 0)
                buf.append(':');
            buf.append(hex, i, 2);
        }
        return buf.toString();
    } catch (NoSuchAlgorithmException e) {
        throw new AssertionError(e);
    }
}