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 String join(Map<?, ?> elements, String keySeparator, String entrySeparator) {
    if (elements == null)
        return "";
    StringBuilder buf = new StringBuilder();
    if (keySeparator == null)
        keySeparator = " ";
    if (entrySeparator == null)
        entrySeparator = " ";

    Iterator<?> elementsIt = elements.entrySet().iterator();
    while (elementsIt.hasNext()) {
        if (buf.length() > 0)
            buf.append(entrySeparator);/*from  w w w.  ja v a 2 s  . com*/
        Map.Entry<?, ?> element = (Map.Entry<?, ?>) elementsIt.next();
        buf.append(element.getKey()).append(keySeparator).append(element.getValue());
    }
    return buf.toString();
}

From source file:Main.java

public static String getSetClause(String fieldName, Collection col, String in) {
    final StringBuilder builder = new StringBuilder();

    if (col.size() > 0) {
        builder.append(fieldName + " " + in + " (");
    }//from www  .  j  a  va  2 s .  c o m

    for (int i = 0; i < col.size(); i++) {
        builder.append("?, ");
    }

    if (col.size() > 0) {
        builder.setLength(builder.length() - 2);
        builder.append(")");
    }

    return builder.toString();
}

From source file:Main.java

public static String getSetClause(String fieldName, String[] arr, String in) {
    final StringBuilder builder = new StringBuilder();

    if (arr.length > 0) {
        builder.append(fieldName + " " + in + " (");
    }/*from   ww w .j av a 2 s .c o  m*/

    for (int i = 0; i < arr.length; i++) {
        builder.append("?, ");
    }

    if (arr.length > 0) {
        builder.setLength(builder.length() - 2);
        builder.append(")");
    }

    return builder.toString();
}

From source file:HexUtil.java

public static final void bytesToHexAppend(byte[] bs, int off, int length, StringBuilder sb) {
    if (bs.length <= off || bs.length < off + length)
        throw new IllegalArgumentException();
    sb.ensureCapacity(sb.length() + length * 2);
    for (int i = off; i < (off + length); i++) {
        sb.append(Character.forDigit((bs[i] >>> 4) & 0xf, 16));
        sb.append(Character.forDigit(bs[i] & 0xf, 16));
    }/* ww w  . j  a  va  2 s.  co  m*/
}

From source file:com.github.hateoas.forms.spring.uber.UberUtils.java

private static String buildModel(List<String> variableNames, String prefix, String separator, String suffix,
        String parameterTemplate) {
    StringBuilder sb = new StringBuilder();
    for (String variable : variableNames) {
        if (sb.length() == 0) {
            sb.append(prefix);/*from ww w  . j  a v a  2  s. co m*/
        } else {
            sb.append(separator);
        }
        sb.append(String.format(parameterTemplate, variable, variable));
    }
    if (sb.length() > 0) {
        sb.append(suffix);
    }
    return sb.toString();
}

From source file:com.hmsinc.epicenter.webapp.map.MapCacheService.java

/**
 * @param attributeList/*  w  w  w  .  j a  v  a2  s  .  com*/
 * @return
 */
private static String makeKeyFromCollection(final Collection<? extends QueryableAttribute> attributeList) {
    final StringBuilder builder = new StringBuilder();
    for (QueryableAttribute attribute : attributeList) {
        if (builder.length() > 0) {
            builder.append(",");
        }
        builder.append(attribute.getId());
    }
    return builder.toString();
}

From source file:Main.java

private static String getString(InputStream stream) throws IOException {
    if (stream != null) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
        StringBuilder content = new StringBuilder();

        String newLine;/*www.j  av  a  2  s  .c  o m*/
        do {
            newLine = reader.readLine();
            if (newLine != null) {
                content.append(newLine).append('\n');
            }
        } while (newLine != null);

        if (content.length() > 0) {
            content.setLength(content.length() - 1);
        }

        return content.toString();
    }
    return null;
}

From source file:cop.raml.utils.Utils.java

@NotNull
public static StringBuilder comma(@NotNull StringBuilder buf) {
    if (buf == null)
        buf = new StringBuilder();
    else if (buf.length() > 0)
        buf.append(", ");
    return buf;//from w w w  . j ava2s .com
}

From source file:com.google.openrtb.json.OpenRtbJsonUtils.java

/**
 * Reads from either a JSON Value String (containing CSV) or a JSON Array.
 * The dual input format is needed because some fields (e.g. keywords) were allowed
 * to be of either type in OpenRTB 2.2; now in 2.3 they are all CSV strings only.
 * TODO: Simplify this to only accept CSV strings after 2.2 compatibility is dropped.
 */// ww w.  j av  a2  s .c o  m
public static String readCsvString(JsonParser par) throws IOException {
    JsonToken currentToken = par.getCurrentToken();
    if (currentToken == JsonToken.START_ARRAY) {
        StringBuilder keywords = new StringBuilder();
        for (startArray(par); endArray(par); par.nextToken()) {
            if (keywords.length() != 0) {
                keywords.append(',');
            }
            keywords.append(par.getText());
        }
        return keywords.toString();
    } else if (currentToken == JsonToken.VALUE_STRING) {
        return par.getText();
    } else {
        throw new JsonParseException(par, "Expected string or array");
    }
}

From source file:Main.java

public static String URLFormatQuery(List<Pair<String, String>> parameters) {
    if ((null != parameters) && (parameters.size() > 0)) {
        final StringBuilder result = new StringBuilder();
        for (final Pair<String, String> parameter : parameters) {
            final String encodedName = parameter.first;
            final String value = parameter.second;
            final String encodedValue = (value != null ? value : "");
            if (result.length() > 0) {
                result.append(PARAMETER_SEPARATOR);
            }// w  w w.  j  a  v a 2s.  co  m
            result.append(encodedName);
            result.append(NAME_VALUE_SEPARATOR);
            result.append(encodedValue);
        }
        return result.toString();
    }

    return null;
}