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:io.crate.testing.Utils.java

static <T> String join(T[] items, String on) {
    StringBuilder sb = new StringBuilder();
    for (T item : items) {
        if (sb.length() > 0) {
            sb.append(on);//from ww  w.  j a  va 2s  .co  m
        }
        sb.append(item.toString());
    }
    return sb.toString();
}

From source file:Main.java

public static String getModifiers(Element d, Modifier ignore) {
    Collection<Modifier> mods = d.getModifiers();
    if (mods.size() == 0)
        return "";
    StringBuilder sbuf = new StringBuilder(mods.size() * 20);
    for (Modifier mod : mods) {
        if (!mod.equals(ignore))
            sbuf.append(mod);/* ww w .  j av a 2  s .  c  om*/
        sbuf.append(' ');
    }
    sbuf.setLength(sbuf.length() - 1);
    return sbuf.toString();
}

From source file:io.fabric8.insight.activemq.audit.ScriptUtils.java

public static String toJson(Object o) {
    try {//  www.j  a  v a2  s . co  m
        if (o instanceof Collection) {
            StringBuilder sb = new StringBuilder();
            sb.append("[");
            for (Object c : (Collection) o) {
                if (sb.length() > 1) {
                    sb.append(",");
                }
                sb.append(toJson(c));
            }
            sb.append("]");
            return sb.toString();
        } else if (o instanceof Map) {
            StringBuilder sb = new StringBuilder();
            sb.append("{");
            for (Map.Entry<Object, Object> e : ((Map<Object, Object>) o).entrySet()) {
                if (sb.length() > 1) {
                    sb.append(",");
                }
                sb.append(toJson(e.getKey().toString()));
                sb.append(":");
                sb.append(toJson(e.getValue()));
            }
            sb.append("}");
            return sb.toString();
        } else if (o == null) {
            return "null";
        } else if (o instanceof Date) {
            return "\"" + toIso((Date) o) + "\"";
        } else {
            return mapper.writeValueAsString(o.toString());
        }
    } catch (Exception e) {
        throw new IllegalArgumentException("Could not serialize " + o, e);
    }
}

From source file:cop.raml.utils.javadoc.JavaDocUtils.java

public static String getText(List<String> lines) {
    if (CollectionUtils.isEmpty(lines))
        return null;

    StringBuilder buf = new StringBuilder();
    int emptyLines = 0;

    for (String line : lines) {
        if (StringUtils.isBlank(line)) {
            if (buf.length() > 0)
                emptyLines++;//from ww  w  .  ja  v a  2 s . c  o m
        } else if (JavaDocTag.startsWith(line))
            break;
        else
            buf.append(StringUtils.repeat("\n", emptyLines + (buf.length() > 0 ? 1 : 0))).append(line);
    }

    return clearMacros(buf.toString());
}

From source file:Main.java

/** Returns whitespace-separated strings from the input stream, or null if the end of the stream has been reached */
public static String readToken(InputStream in) {
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    int ch;/*from   w w  w .j a  v  a2s . c o m*/
    while (true) {
        try {
            ch = in.read();
            if (ch == -1)
                return sb.length() > 0 ? sb.toString() : null;
            if (Character.isWhitespace(ch)) {
                if (first)
                    continue;
                break;
            }
            sb.append((char) ch);
            first = false;
        } catch (IOException e) {
            break;
        }
    }
    return sb.toString();
}

From source file:Main.java

public static <T> String join(T[] array, String cement) {
    StringBuilder builder = new StringBuilder();

    if (array == null || array.length == 0) {
        return null;
    }//from w  w w  . j  a va  2 s  .co  m
    for (T t : array) {
        builder.append(t).append(cement);
    }

    builder.delete(builder.length() - cement.length(), builder.length());

    return builder.toString();
}

From source file:Main.java

public static String paramsmap2ParamsString(Map<String, String> params) {
    if (params == null)
        return "";
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<String, String> param : params.entrySet()) {
        sb.append(param.getKey()).append("=").append(param.getValue()).append("&");
    }//from   www  .ja v a2 s.  c om
    if (sb.charAt(sb.length() - 1) == '&')
        sb.deleteCharAt(sb.length() - 1);
    return sb.toString();
}

From source file:com.cyberway.issue.io.arc.ARC2WCDX.java

protected static void appendTimeField(StringBuilder builder, Object obj) {
    if (builder.length() > 0) {
        // prepend with delimiter
        builder.append(' ');
    }//from  www .  j  a  v  a  2  s .c o m
    if (obj == null) {
        builder.append("-");
        return;
    }
    if (obj instanceof Header) {
        String s = ((Header) obj).getValue().trim();
        try {
            Date date = DateUtil.parseDate(s);
            String d = ArchiveUtils.get14DigitDate(date);
            if (d.startsWith("209")) {
                d = "199" + d.substring(3);
            }
            obj = d;
        } catch (DateParseException e) {
            builder.append('e');
            return;
        }

    }
    builder.append(obj);
}

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

private static void removeLstZero(StringBuilder sb, String[] numCn) {
    if (sb.length() > 1 && sb.substring(sb.length() - 1).equals(numCn[0])) {
        sb.deleteCharAt(sb.length() - 1);
        removeLstZero(sb, numCn);// w  w w . ja v a 2  s. com
    }
}

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

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