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:com.asakusafw.runtime.windows.WinUtilsInstaller.java

private static String getUserHash() {
    String base = System.getProperty("user.name", UUID.randomUUID().toString()); //$NON-NLS-1$
    StringBuilder buf = new StringBuilder();
    for (char c : base.toCharArray()) {
        if ('0' <= c && c <= '9' || 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || c == '_' || c == '-') {
            buf.append(c);/*  w  w w. j a  v  a  2  s.  c o  m*/
        }
    }
    if (buf.length() < 4) {
        buf.append('-');
        buf.append(Integer.toHexString(base.hashCode()));
    }
    return buf.toString();
}

From source file:Main.java

static String map2UrlQueryString(Map<String, Object> map) {
    StringBuilder sb = new StringBuilder();
    for (HashMap.Entry<String, Object> e : map.entrySet()) {
        try {//from   w  ww.  ja v  a 2 s  .  c o  m
            sb.append(e.getKey());
            sb.append('=');
            sb.append(URLEncoder.encode(String.valueOf(e.getValue()), "UTF-8"));
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
        sb.append('&');
    }
    if (sb.length() == 0)
        return "";
    else
        return sb.substring(0, sb.length() - 1);
}

From source file:com.hmsinc.epicenter.surveillance.notification.EventNotifierUtils.java

private static String makeAttributeString(final Collection<? extends Attribute> attributes) {
    final StringBuilder sb = new StringBuilder();
    if (attributes.size() == 1) {
        sb.append(attributes.iterator().next().getName().toLowerCase());
    } else if (attributes.size() > 1) {
        int i = 0;
        for (Attribute a : attributes) {
            i++;/*from w  ww .  ja  va2s. c o m*/
            if (sb.length() > 0) {
                if (i == attributes.size()) {
                    sb.append(" or ");
                } else {
                    sb.append(", ");
                }
            }
            sb.append(a.getName().toLowerCase());
        }
    }
    return sb.toString();
}

From source file:com.linkedin.d2.D2BaseTest.java

protected static String print(String[] arr) {
    StringBuilder sb = new StringBuilder();
    for (String a : arr) {
        sb.append(((sb.length() > 0) ? "," : ""));
        sb.append(a);//from   w ww.  j  a  va2  s  . com
    }

    return sb.toString();
}

From source file:com.servoy.j2db.server.ngclient.startup.resourceprovider.ComponentResourcesExporter.java

/**
 * Used in war export to create a services.properties file, which is needed to load services specs in the war.
 * @return the locations of services folders relative to the war dir.
 *//*from  w ww  .j a v a2 s .co  m*/
public static String getServicesDirectoryNames() {
    StringBuilder locations = new StringBuilder();
    Enumeration<String> paths = Activator.getContext().getBundle().getEntryPaths("/war/");
    while (paths.hasMoreElements()) {
        String name = paths.nextElement().replace("war/", "");
        if (name.endsWith("services/"))
            locations.append("/" + name + ";");
    }
    if (locations.length() > 0)
        locations.deleteCharAt(locations.length() - 1);
    return locations.toString();
}

From source file:au.com.addstar.SpigotUpdater.java

private static void doOutHeader(List<Plugin> plugins) {
    List<String> out = new ArrayList<>();
    System.out.println("Processing " + plugins.size() + " plugins.... ");
    String name = StringUtils.rightPad("Plugin Name", 25, " ");
    out.add(name);/*w ww .jav  a  2  s  .  co  m*/
    out.add(StringUtils.rightPad("Res. ID", 7));
    out.add(StringUtils.rightPad("Version", 10));
    out.add(StringUtils.rightPad("Latest", 10));
    out.add(StringUtils.rightPad("Update?", 7));
    out.add(StringUtils.rightPad("Date Upd.", 10));
    out.add("Extra Notes");
    StringBuilder sb = new StringBuilder();
    String[] message = new String[out.size()];
    out.toArray(message);
    sb.append(StringUtils.join(message, " | "));
    System.out.println(sb.toString());
    System.out.println(StringUtils.rightPad("", sb.length(), "-"));
}

From source file:net.sf.jabref.exporter.ExportFormats.java

/**
 * Build a string listing of all available export formats.
 *
 * @param maxLineLength/*from   w w w  .  j  av a  2  s  .  c  o m*/
 *            The max line length before a line break must be added.
 * @param linePrefix
 *            If a line break is added, this prefix will be inserted at the
 *            beginning of the next line.
 * @return The string describing available formats.
 */
public static String getConsoleExportList(int maxLineLength, int firstLineSubtr, String linePrefix) {
    StringBuilder sb = new StringBuilder();
    int lastBreak = -firstLineSubtr;

    for (String name : ExportFormats.EXPORT_FORMATS.keySet()) {
        if (((sb.length() + 2 + name.length()) - lastBreak) > maxLineLength) {
            sb.append(",\n");
            lastBreak = sb.length();
            sb.append(linePrefix);
        } else if (sb.length() > 0) {
            sb.append(", ");
        }
        sb.append(name);
    }

    return sb.toString();
}

From source file:com.ushahidi.android.app.util.Util.java

/**
 * Limit a string to defined length/*from   ww  w  . j av  a2s  . c o m*/
 * 
 * @param int limit - the total length
 * @param string limited - the limited string
 */
public static String limitString(String value, int length) {
    StringBuilder buf = new StringBuilder(value);
    if (buf.length() > length) {
        buf.setLength(length);
        buf.append(" ...");
    }
    return buf.toString();
}

From source file:com.leshazlewood.scms.cli.Main.java

private static void printHelp(Options options, Exception e, boolean debug) {
    HelpFormatter help = new HelpFormatter();
    help.setWidth(80);//  w  ww.  j  a v a2s .  c  o m
    String command = "scms [options] [src_dir] dest_dir";
    String header = "Injests content files in [src dir] and renders a static website into dest_dir.\n\n"
            + "  [src_dir] is optional and defaults to the current working directory.\n"
            + "  dest_dir is required and cannot be the same as src_dir.";
    /*String footer = "\n" +
        "Injests source content files and page templates in [src dir] and renders a\n" +
        "renders a static website into destination_directory.\n\n" +
        "If unspecified, [source directory] defaults to the current working\n" +
        "directory.  destination_directory is required and cannot be the same\n" +
        "as the source directory.";*/

    printException(e, debug);

    System.out.println();

    System.out.println("Usage:");
    System.out.print("  ");
    System.out.println(command);
    System.out.println();
    System.out.println("Description:");
    System.out.print("  ");
    System.out.println(header);
    System.out.println();
    System.out.println("Options:");

    StringBuilder sb = new StringBuilder();

    int columnWidth = calculateColumnWidth(options);

    for (Object o : options.getOptions()) {
        Option option = (Option) o;
        StringBuilder csb = new StringBuilder("  ");
        csb.append("-").append(option.getOpt()).append(",--").append(option.getLongOpt());
        if (option.hasArg()) {
            csb.append(" <arg>");
        }
        int csbLength = csb.length();
        for (int i = 0; i < (columnWidth - csbLength); i++) {
            csb.append(" ");
        }
        sb.append(csb.toString()).append("   ").append(option.getDescription()).append("\n");
    }
    System.out.println(sb);

    //help.printHelp("", "", options, null);
    //System.out.println(footer);
}