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:de.micromata.genome.util.text.StringCommaList.java

/**
 * Join.//from  ww w . j  a  v  a 2  s .c om
 * 
 * @param parts the parts
 * @param sep the sep
 * @return the string
 */
public static String join(String[] parts, char sep) {
    StringBuilder sb = new StringBuilder();
    for (String p : parts) {
        if (sb.length() > 0) {
            sb.append(sep);
        }
        sb.append(escape(p, sep));
    }
    return sb.toString();
}

From source file:Main.java

public static String decodePath(String path, String delimiter, String characterSet)
        throws UnsupportedEncodingException {
    final StringTokenizer tokenizer = new StringTokenizer(path, delimiter);
    final StringBuilder builder = new StringBuilder(path.length());

    while (tokenizer.hasMoreTokens()) {
        builder.append(URLDecoder.decode(tokenizer.nextToken(), characterSet));
        builder.append(delimiter);/*from  w  w  w  .  j a  v  a  2s . c  o m*/
    }
    builder.delete(builder.length() - delimiter.length(), builder.length());
    return builder.toString();
}

From source file:Main.java

public static String encodePath(String path, String delimiter, String characterSet)
        throws UnsupportedEncodingException {
    final StringTokenizer tokenizer = new StringTokenizer(path, delimiter);
    final StringBuilder builder = new StringBuilder(path.length());

    while (tokenizer.hasMoreTokens()) {
        builder.append(URLEncoder.encode(tokenizer.nextToken(), characterSet));
        builder.append(delimiter);//from w ww.  j  av  a2  s. c o m
    }
    builder.delete(builder.length() - delimiter.length(), builder.length());
    return builder.toString();
}

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(",");
        }/*  www  . ja  va 2 s.  com*/
        localStringBuilder.append(str);
    }
    return localStringBuilder.toString();
}

From source file:com.cloudera.cdk.data.PartitionExpression.java

private static String toExpression(FieldPartitioner fieldPartitioner) {
    // TODO: add other strategies
    if (fieldPartitioner instanceof HashFieldPartitioner) {
        return String.format("hash(\"%s\", \"%s\", %s)", fieldPartitioner.getSourceName(),
                fieldPartitioner.getName(), fieldPartitioner.getCardinality());
    } else if (fieldPartitioner instanceof IdentityFieldPartitioner) {
        return String.format("identity(\"%s\", %s)", fieldPartitioner.getName(),
                fieldPartitioner.getCardinality());
    } else if (fieldPartitioner instanceof RangeFieldPartitioner) {
        List<String> upperBounds = ((RangeFieldPartitioner) fieldPartitioner).getUpperBounds();

        StringBuilder builder = new StringBuilder();

        for (String bound : upperBounds) {
            if (builder.length() > 0) {
                builder.append(", ");
            }/* www .  j av  a  2s .c  om*/
            builder.append("\"").append(bound).append("\"");
        }

        return String.format("range(\"%s\", %s", fieldPartitioner.getName(), builder.toString());
    } else if (fieldPartitioner instanceof YearFieldPartitioner) {
        return String.format("year(\"%s\", \"%s\")", fieldPartitioner.getSourceName(),
                fieldPartitioner.getName());
    } else if (fieldPartitioner instanceof MonthFieldPartitioner) {
        return String.format("month(\"%s\", \"%s\")", fieldPartitioner.getSourceName(),
                fieldPartitioner.getName());
    } else if (fieldPartitioner instanceof DayOfMonthFieldPartitioner) {
        return String.format("day(\"%s\", \"%s\")", fieldPartitioner.getSourceName(),
                fieldPartitioner.getName());
    } else if (fieldPartitioner instanceof HourFieldPartitioner) {
        return String.format("hour(\"%s\", \"%s\")", fieldPartitioner.getSourceName(),
                fieldPartitioner.getName());
    } else if (fieldPartitioner instanceof MinuteFieldPartitioner) {
        return String.format("minute(\"%s\", \"%s\")", fieldPartitioner.getSourceName(),
                fieldPartitioner.getName());
    }

    throw new IllegalArgumentException("Unrecognized PartitionStrategy: " + fieldPartitioner);
}

From source file:com.example.wrappers.PlaceWrapper.java

/**
 * concatURLValues format a param's arguments correctly.
 * Only used for params that accept multiple values.
 * @param values the array of strings which represent all the values which should be included in the request.
 * @returns A string which has proper URL encoding of the list of values.
 *///from   w ww  .j  a v  a 2s  . com
public static String concatURLValues(String... values) {
    if (values.length == 0)
        return "";

    StringBuilder sb = new StringBuilder("");
    for (String v : values) {
        sb.append(v);
        if (v != "")
            sb.append('|');
    }
    if (sb.length() > 0)
        sb.deleteCharAt(sb.length() - 1);

    try {
        return URLEncoder.encode(sb.toString(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("UTF-8 encoding not supported");
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.penntree.PennTreeUtils.java

private static void toText(StringBuilder aBuffer, PennTreeNode aNode) {
    if (aNode.isTerminal()) {
        if (aBuffer.length() > 0) {
            aBuffer.append(" ");
        }/* ww w. j  ava 2s.c o  m*/
        aBuffer.append(unescapeToken(aNode.getLabel()));
    } else {
        for (PennTreeNode n : aNode.getChildren()) {
            toText(aBuffer, n);
        }
    }
}

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

/**
 * Creates a compact string representation for the log.
 *
 * @param data JSONTags to create the string representation for
 * @return string representation/*www . j  a  va 2 s  .c om*/
 */
public static String toLog(JSONTags data) {
    if (data.getTags().size() == 0) {
        return "[None]";
    } else {
        StringBuilder s = new StringBuilder();
        s.append("[");
        for (JSONTag t : data.getTags()) {
            s.append(JSONTag.toLog(t) + ",");
        }
        s.delete(s.length() - 1, s.length());
        s.append("]");
        return s.toString();
    }
}

From source file:org.obiba.opal.web.security.AuthorizationInterceptor.java

static String asHeader(Iterable<String> values) {
    StringBuilder sb = new StringBuilder();
    for (String s : values) {
        if (sb.length() > 0)
            sb.append(", ");
        sb.append(s);/*from w  ww. j a  v  a 2s.c  o  m*/
    }
    return sb.toString();
}

From source file:com.prowidesoftware.deprecation.DeprecationUtils.java

/**
 * Helper hack to set the environment variable from Java.
 * /*from www  .  j a v  a2 s  .c o  m*/
 * <p>For example if all keys are passed as parameter, this will set 
 * the environment variable PW_DEPRECATED=nolog,nodelay,noexception</p>
 *  
 * @param keys the variables to set in the environment variable
 */
public static void setEnv(EnvironmentVariableKey... keys) {
    if (keys != null && keys.length > 0) {
        StringBuilder value = new StringBuilder();
        for (EnvironmentVariableKey key : keys) {
            if (value.length() > 0) {
                value.append(",");
            }
            value.append(key.name().toLowerCase());
        }
        setEnv(PW_DEPRECATED, value.toString());
    }
}