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

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

Introduction

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

Prototype

public static String repeat(String string, int count) 

Source Link

Document

Returns a string consisting of a specific number of concatenated copies of an input string.

Usage

From source file:de.flapdoodle.java2pandoc.javadoc.JavaDocFormatingToPandocConverter.java

public JavaDocFormatingToPandocConverter(int tabHasSpaces) {
    _tabHasSpaces = tabHasSpaces;
    _tabAsSpaces = Strings.repeat(" ", _tabHasSpaces);
}

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

protected String box(String title, String content) {
    final int width = 80;
    final int min = 3;
    int titleLength = title.length() + 2;
    final int left = Math.max((width - titleLength) / 2, min);
    StringBuilder result = new StringBuilder();
    result.append(Strings.repeat("-", left));
    result.append(" ");
    result.append(title);/*from  www .  j  av a  2 s.c  o  m*/
    result.append(" ");
    if (left > min)
        result.append(Strings.repeat("-", width - left - titleLength));
    result.append("\n");
    result.append(org.eclipse.xtext.util.Strings.trimTrailingLineBreak(content));
    result.append("\n");
    result.append(Strings.repeat("-", width));
    return result.toString();
}

From source file:org.apache.parquet.tools.read.SimpleRecord.java

public void prettyPrint(PrintWriter out, int depth) {
    for (NameValue value : values) {
        out.print(Strings.repeat(".", depth));

        out.print(value.getName());/*from  w  w w. j  a v a  2  s .  c  om*/
        Object val = value.getValue();
        if (val == null) {
            out.print(" = ");
            out.print("<null>");
        } else if (byte[].class == val.getClass()) {
            out.print(" = ");
            out.print(new BinaryNode((byte[]) val).asText());
        } else if (short[].class == val.getClass()) {
            out.print(" = ");
            out.print(Arrays.toString((short[]) val));
        } else if (int[].class == val.getClass()) {
            out.print(" = ");
            out.print(Arrays.toString((int[]) val));
        } else if (long[].class == val.getClass()) {
            out.print(" = ");
            out.print(Arrays.toString((long[]) val));
        } else if (float[].class == val.getClass()) {
            out.print(" = ");
            out.print(Arrays.toString((float[]) val));
        } else if (double[].class == val.getClass()) {
            out.print(" = ");
            out.print(Arrays.toString((double[]) val));
        } else if (boolean[].class == val.getClass()) {
            out.print(" = ");
            out.print(Arrays.toString((boolean[]) val));
        } else if (val.getClass().isArray()) {
            out.print(" = ");
            out.print(Arrays.deepToString((Object[]) val));
        } else if (SimpleRecord.class.isAssignableFrom(val.getClass())) {
            out.println(":");
            ((SimpleRecord) val).prettyPrint(out, depth + 1);
            continue;
        } else {
            out.print(" = ");
            out.print(String.valueOf(val));
        }

        out.println();
    }
}

From source file:org.gradle.api.internal.tasks.testing.logging.FullExceptionFormatter.java

private void printException(TestDescriptor descriptor, Throwable exception,
        @Nullable List<StackTraceElement> parentTrace, int exceptionLevel, StringBuilder builder) {
    String exceptionIndent = Strings.repeat(INDENT, exceptionLevel + 1);
    String exceptionText = exceptionLevel == 0 ? exception.toString() : "\nCaused by:\n" + exception.toString();
    String indentedText = TextUtil.indent(exceptionText, exceptionIndent);
    builder.append(indentedText);/*from  w w w . j a  v a2s .c o m*/
    builder.append('\n');

    String stackTraceIndent = exceptionIndent + INDENT;
    List<StackTraceElement> stackTrace = null;

    if (testLogging.getShowStackTraces()) {
        stackTrace = filterStackTrace(exception, descriptor);
        int commonElements = countCommonElements(stackTrace, parentTrace);
        for (int i = 0; i < stackTrace.size() - commonElements; i++) {
            builder.append(stackTraceIndent);
            builder.append("at ");
            builder.append(stackTrace.get(i));
            builder.append('\n');
        }
        if (commonElements != 0) {
            builder.append(stackTraceIndent);
            builder.append("... ");
            builder.append(commonElements);
            builder.append(" more");
            builder.append('\n');
        }
    }

    if (testLogging.getShowCauses() && exception.getCause() != null) {
        printException(descriptor, exception.getCause(), stackTrace, exceptionLevel + 1, builder);
    }
}

From source file:org.apache.servicecomb.demo.perf.PerfConfiguration.java

@Value(value = "${response-size}")
public void setResponseSize(int responseSize) {
    PerfConfiguration.responseSize = responseSize;
    PerfConfiguration.responseData = Strings.repeat("a", responseSize);
}

From source file:exec.plm12.DistributedWorker.java

public void run(String serverIp, String rootFolder, String version) throws Exception {

    Asserts.assertNotNull(serverIp);/*from ww  w  . j a va 2  s .c o m*/

    RmiUtils.setRmiDefaults();

    while (true) {
        Logger.log(Strings.padEnd("#### restarting worker ", 80, '#'));

        runGarbageCollection();

        try {
            Config config = RmiUtils.request(Config.class, serverIp);
            assertVersion(version, config.getVersion());

            Logger.log("# version: %s", version);
            Logger.log("# root: %s", rootFolder);
            Logger.log("# dataset: %s", config.getDatasetName());

            Injector injector = Guice.createInjector(new Module(rootFolder, config.getDatasetName()));

            ITaskScheduler<?> tp = RmiUtils.request(ITaskScheduler.class, serverIp);
            Logger.log("# requesting task...");
            Runnable task = tp.getNextNullableTask();
            if (task != null) {
                if (task instanceof InjectableRunnable) {
                    ((InjectableRunnable) task).injectionForMembers(injector);
                }
                Logger.log(Strings.repeat("#", 80));
                task.run();
            } else {
                Logger.log("# no tasks available. waiting...");
                Logger.log(Strings.repeat("#", 80));
                Thread.sleep(5000);
            }
        } catch (Exception e) {
            Logger.log("# communication error:\n%s", e.getMessage());
            Logger.log("# waiting...");
            Logger.log(Strings.repeat("#", 80));
            Thread.sleep(5000);
        }
        Logger.log("");
    }
}

From source file:eu.itesla_project.modules.topo.TopologyChoice.java

public void print(PrintStream out, int indent) {
    out.print(Strings.repeat(" ", indent) + "topoChoice");
    if (num != null) {
        out.print(" num=" + num);
    }/*from   w w w .  ja v  a 2  s.c om*/
    if (clusterId != null) {
        out.print(" clusterId=" + clusterId);
    }
    out.println(" count=" + possibleTopologies.size());
    for (PossibleTopology possibleTopology : possibleTopologies) {
        possibleTopology.print(out, 8);
    }
}

From source file:natlab.options.OptionsBase.java

private String pad(int initial, String opts, int tab, String desc) {
    StringBuilder sb = new StringBuilder();
    sb.append(Strings.repeat(" ", initial)).append(opts);
    int i = opts.length() + initial;
    if (tab <= opts.length()) {
        sb.append("\n");
        i = 0;/*from   w w  w. j  a  va2  s.  c o m*/
    }
    sb.append(Strings.repeat(" ", tab - i + 1));
    for (String s : Splitter.on(CharMatcher.WHITESPACE).split(desc)) {
        if (i + s.length() > 78) {
            sb.append("\n");
            i = 0;
            sb.append(Strings.repeat(" ", tab - i + 1));
        }
        sb.append(s).append(" ");
        i += s.length() + 1;
    }
    return sb.append("\n").toString();
}

From source file:com.google.security.zynamics.zylib.gui.tables.CopySelectionAction.java

@Override
public void actionPerformed(final ActionEvent event) {
    final int[] rows = table.getSelectedRows();

    final int cols = table.getColumnCount();

    final int[] maximums = new int[cols];

    for (final int row : rows) {
        for (int i = 0; i < cols; i++) {
            if (table.getValueAt(row, i) != null) {
                final int maximum = table.getValueAt(row, i).toString().length();
                if (maximum > maximums[i]) {
                    maximums[i] = maximum;
                }//from   w  w w . j a v  a 2 s .  c  om
            }
        }
    }

    final StringBuffer sb = new StringBuffer();

    for (final int row : rows) {
        for (int i = 0; i < cols; i++) {
            if (table.getValueAt(row, i) != null) {
                final String value = table.getValueAt(row, i).toString();

                final int differenceToMaximum = maximums[i] - value.length();

                sb.append(value);
                sb.append(Strings.repeat(" ", differenceToMaximum));

                if (i != (cols - 1)) {
                    sb.append("  ");
                }
            }
        }

        sb.append("\n");
    }

    ClipboardHelpers.copyToClipboard(sb.toString());
}

From source file:com.bennavetta.aeneas.cli.Table.java

@Override
public String toString() {
    if (rows.isEmpty())
        return "";

    int numColumns = rows.get(0).size();
    List<Integer> columnWidths = Lists.newArrayList();
    for (int i = 0; i < numColumns; i++) {
        columnWidths.add(extractColumn(i).mapToInt(String::length).max().getAsInt());
    }//from  w  ww . j  av  a2  s.  c o m

    return rows.stream().map(row -> {
        List<String> paddedRow = Lists.newArrayListWithCapacity(row.size());
        for (int i = 0; i < row.size(); i++) {
            int columnWidth = columnWidths.get(i);
            paddedRow.add(Strings.padEnd(row.get(i), columnWidth, padChar));
        }
        return Joiner.on(Strings.repeat(String.valueOf(padChar), padAmount)).join(paddedRow);
    }).collect(Collectors.joining("\n"));
}