Example usage for com.google.common.base Strings padEnd

List of usage examples for com.google.common.base Strings padEnd

Introduction

In this page you can find the example usage for com.google.common.base Strings padEnd.

Prototype

public static String padEnd(String string, int minLength, char padChar) 

Source Link

Document

Returns a string, of length at least minLength , consisting of string appended with as many copies of padChar as are necessary to reach that length.

Usage

From source file:com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.Data.Component.TypeInstanceTableDatamodel.java

private FormattedCharacterBuffer stringToFormattedCharacterBuffer(String string, int rowIndex,
        int columnIndex) {
    return new FormattedCharacterBuffer(Strings.padEnd(string, columns[columnIndex].getWidth(), ' '),
            STANDARD_FONT, columns[columnIndex].getDefaultFontColor(),
            getBackgroundColor(rowIndex, columnIndex));
}

From source file:org.eclipse.xtext.formatting2.debug.TextRegionAccessToString.java

protected String quote(String string) {
    if (string == null)
        return "null";
    string = string.replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t");
    int textLen = textWidth - 2;
    if (string.length() > textLen)
        return "\"" + string.substring(0, textLen - 3) + "...\"";
    else/*  ww w  .  j a v a  2s  .c o m*/
        return Strings.padEnd("\"" + string + "\"", textWidth, ' ');
}

From source file:CurrentUserAccounts.java

/**
 * Writes the current user accounts file in memory to file, over-writing
 * the old current user accounts file./*w  ww.  ja va 2 s. co  m*/
 * 
 * @throws FatalError Fatal errors occur under the following circumstances:
 *          <br>The current user accounts file is corrupted.
 * @throws IOException 
 */
public void write() throws IOException {
    BufferedWriter writer;
    String entry;

    File file = new File(cuaFile);

    writer = new BufferedWriter(new FileWriter(file.getAbsoluteFile()));

    /* Format each entry and write it to the file */
    for (User user : users) {
        /* Format the username */
        entry = Strings.padEnd(user.getUsername(), 16, '_');

        /* Format the account type */
        entry += user.getType() + "_";

        /* Format the credit amount */
        entry += Strings.padStart(String.format("%.2f", user.getCredit()), 9, '0') + "\n";

        writer.write(entry);
    }

    /* Add the END of file identifier and close the file */
    writer.write("END________________000000.00");
    writer.close();
}

From source file:org.carrot2.core.test.assertions.ClusterListAssertion.java

private void tabularizedReport(List<String> l1, List<String> l2) {
    Logger logger = LoggerFactory.getLogger(ClusterListAssertion.class);

    int maxL1Width = 0;
    for (String s : l1)
        maxL1Width = Math.max(maxL1Width, s.length());

    final StringBuilder sb = new StringBuilder();
    final Set<String> l1s = Sets.newTreeSet(l1);
    final Set<String> l2s = Sets.newTreeSet(l2);

    if (l1s.equals(l2s)) {
        sb.append("PROBLEM: Same sets different order or hierarchy.\n");

        sb.append("Clusters side-by-side (same-line order changes marked):\n");
        for (int i = 0; i < Math.max(l1.size(), l2.size()); i++) {
            String lbl = l1.get(i);
            sb.append(l2.get(i).equals(lbl) ? "  " : "* ");
            sb.append(Strings.padEnd(lbl, maxL1Width, ' '));
            sb.append(" | ");

            lbl = l2.get(i);//  ww w . j  av  a 2s. c o m
            sb.append(l1.get(i).equals(lbl) ? "  " : "* ");
            sb.append(lbl);
            sb.append("\n");
        }
    } else {
        Set<String> common = Sets.newTreeSet(l1s);
        common.retainAll(l2s);
        l1s.removeAll(common);
        l2s.removeAll(common);

        sb.append("Clusters in the previous set only:\n");
        for (String s : l1s)
            sb.append("  '" + s + "'\n");
        sb.append("Clusters in the actual set only:\n");
        for (String s : l2s)
            sb.append("  '" + s + "'\n");

        sb.append("Clusters side-by-side (order changes not shown):\n");
        for (int i = 0; i < Math.max(l1.size(), l2.size()); i++) {
            String lbl = (i < l1.size() ? l1.get(i) : "--");
            sb.append(l1s.contains(lbl) ? "* " : "  ");
            sb.append(Strings.padEnd(lbl, maxL1Width, ' '));
            sb.append(" | ");

            lbl = (i < l2.size() ? l2.get(i) : "--");
            sb.append(l2s.contains(lbl) ? "* " : "  ");
            sb.append(lbl);
            sb.append("\n");
        }
    }

    logger.error("Failed cluster list comparison (previous | now):\n" + sb.toString());
}

From source file:com.thoughtworks.gauge.Table.java

private Function<String, String> format(final int maxStringLength) {

    return new Function<String, String>() {

        @Override/*  www. j a  v a 2s . co  m*/
        public String apply(String input) {

            return Strings.padEnd(input, maxStringLength, SPACE_AS_CHAR);
        }
    };
}

From source file:tech.tablesaw.columns.strings.StringMapFunctions.java

default StringColumn padEnd(int minLength, char padChar) {

    StringColumn newColumn = StringColumn.create(name() + "[pad]");

    for (int r = 0; r < size(); r++) {
        String value = getString(r);
        newColumn.append(Strings.padEnd(value, minLength, padChar));
    }/*from w ww  .  j  a va2s  . c  o m*/
    return newColumn;
}

From source file:de.brands4friends.daleq.core.internal.formatting.MarkdownTableFormatter.java

private void appendColumnHeader(final Column column, final Appendable appendable) throws IOException {
    appendWhitespace(appendable);/*from  w ww . j  av a2 s . c  o  m*/
    appendable.append(Strings.padEnd(column.name, column.width, PAD_CHAR));
    appendWhitespace(appendable);
}

From source file:fathom.rest.RestService.java

private void logEngines() {
    if (!settings.getBoolean(SETTING_ENGINES_LOG, true)) {
        return;//  ww  w .  j a  v a2  s.  co m
    }

    TemplateEngine templateEngine = application.getTemplateEngine();
    ContentTypeEngines engines = application.getContentTypeEngines();

    List<String> contentTypes = new ArrayList<>(engines.getContentTypes());
    Collections.sort(contentTypes);

    int maxContentTypeLen = 0;
    int maxTemplateEngineLen = templateEngine == null ? 0 : templateEngine.getClass().getName().length();

    for (String contentType : contentTypes) {

        ContentTypeEngine engine = engines.getContentTypeEngine(contentType);

        maxContentTypeLen = Math.max(maxContentTypeLen, contentType.length());
        maxTemplateEngineLen = Math.max(maxTemplateEngineLen, engine.getClass().getName().length());

    }

    if (templateEngine != null) {
        log.info("{}  =>  {}", Strings.padEnd("templates", maxContentTypeLen, ' '),
                templateEngine.getClass().getName());
    }

    for (String contentType : contentTypes) {

        ContentTypeEngine engine = engines.getContentTypeEngine(contentType);
        log.info("{}  =>  {}", Strings.padEnd(contentType, maxContentTypeLen, ' '),
                engine.getClass().getName());

    }

}

From source file:io.jeo.cli.JeoCLI.java

/**
 * Displays cli usage.//from   w  w  w  .  j a v a  2  s  . c o  m
 */
public void usage() {
    Set<String> commands = cmdr.getCommands().keySet();
    int maxLength = new Ordering<String>() {
        public int compare(String left, String right) {
            return Ints.compare(left.length(), right.length());
        };
    }.max(commands).length();

    try {
        console.println("usage: jeo <command> [<args>]");
        console.println();
        console.println("Commands:");
        console.println();
        for (String cmd : commands) {
            console.print("\t");
            console.print(Strings.padEnd(cmd, maxLength, ' '));
            console.print("\t");
            console.println(cmdr.getCommandDescription(cmd));
        }
        console.println();
        console.println("For detailed help on a specific command use jeo <command> -h");
        console.flush();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:fathom.utils.Util.java

public static void logSetting(Logger log, String name, Object value) {
    log.info(Strings.padEnd(name, 32, '.')
            + (value == null ? "" : (name.toLowerCase().contains("password") ? "<masked>" : value.toString())));
}