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:com.facebook.buck.cli.AbstractContainerCommand.java

protected void printUsage(PrintStream stream) {
    String prefix = getContainerCommandPrefix();

    stream.println("buck build tool");

    stream.println("usage:");
    stream.println("  " + prefix + " [options]");
    stream.println("  " + prefix + " command --help");
    stream.println("  " + prefix + " command [command-options]");
    stream.println("available commands:");

    SubCommands subCommands;//from w  w w  .  j  a v a 2s  .co  m
    try {
        subCommands = this.getClass().getDeclaredField(getSubcommandsFieldName())
                .getAnnotation(SubCommands.class);
    } catch (NoSuchFieldException e) {
        throw new RuntimeException(e);
    }
    int lengthOfLongestCommand = 0;
    for (SubCommand subCommand : subCommands.value()) {
        String name = subCommand.name();
        if (name.length() > lengthOfLongestCommand) {
            lengthOfLongestCommand = name.length();
        }
    }

    for (SubCommand subCommand : subCommands.value()) {
        Command command;
        try {
            command = (Command) subCommand.impl().newInstance();
        } catch (IllegalAccessException | InstantiationException e) {
            throw new RuntimeException(e);
        }
        String name = subCommand.name().toLowerCase();
        stream.printf("  %s%s  %s\n", name, Strings.repeat(" ", lengthOfLongestCommand - name.length()),
                command.getShortDescription());
    }

    stream.println("options:");
    new AdditionalOptionsCmdLineParser(this).printUsage(stream);
}

From source file:com.reprezen.swagedit.validation.SwaggerError.java

String getMessage(boolean withIndent) {
    if (withIndent) {
        final StringBuilder builder = new StringBuilder();
        builder.append(Strings.repeat("\t", indent));
        builder.append(" - ");
        builder.append(message);//w w w .j ava 2 s. c  o m
        builder.append("\n");

        return builder.toString();
    }

    return message;
}

From source file:org.robotframework.ide.eclipse.main.plugin.project.build.fix.CreateVariableFixer.java

@Override
public Optional<ICompletionProposal> asContentProposal(final IMarker marker, final IDocument document,
        final RobotSuiteFile suiteModel) {
    if (variableName == null) {
        return Optional.empty();
    }/*w w  w . jav  a 2  s . c  o m*/

    final String lineDelimiter = DocumentUtilities.getDelimiter(document);

    final boolean isTsvFile = suiteModel.getFileExtension().equals("tsv");
    final String separator = RedPlugin.getDefault().getPreferences().getSeparatorToUse(isTsvFile);

    final Optional<RobotVariablesSection> section = suiteModel.findSection(RobotVariablesSection.class);

    final String toInsert;
    int offsetOfChange;

    final String variableDefinition = lineDelimiter + variableName + separator;
    if (section.isPresent()) {
        try {
            toInsert = variableDefinition;
            final int line = section.get().getHeaderLine();
            final IRegion lineInformation = document.getLineInformation(line - 1);

            offsetOfChange = lineInformation.getOffset() + lineInformation.getLength();
        } catch (final BadLocationException e) {
            return Optional.empty();
        }
    } else {
        toInsert = Strings.repeat(lineDelimiter, 2) + "*** Variables ***" + variableDefinition;
        offsetOfChange = document.getLength();
    }

    final IRegion regionOfChange = new Region(offsetOfChange, 0);
    final String info = Snippets.createSnippetInfo(document, regionOfChange, toInsert);
    final RedCompletionProposal proposal = RedCompletionBuilder.newProposal().willPut(toInsert)
            .byInsertingAt(regionOfChange.getOffset()).secondaryPopupShouldBeDisplayedUsingHtml(info)
            .thenCursorWillStopAtTheEndOfInsertion().displayedLabelShouldBe(getLabel())
            .proposalsShouldHaveIcon(ImagesManager.getImage(RedImages.getRobotVariableImage())).create();
    return Optional.<ICompletionProposal>of(proposal);
}

From source file:org.geogit.api.plumbing.diff.MutableTree.java

private void append(StringBuilder sb, Node node, int indent) {
    sb.append(Strings.repeat("    ", indent)).append(node.getName()).append("->").append(node.getObjectId())
            .append(" (").append(node.getMetadataId()).append(")\n");
}

From source file:piecework.security.data.MaskRestrictedValuesFilter.java

@Override
public List<Value> filter(String key, List<Value> values) {
    if (values == null || values.isEmpty())
        return Collections.emptyList();

    List<Value> list = new ArrayList<Value>(values.size());
    for (Value value : values) {
        if (value instanceof Secret) {
            Secret secret = Secret.class.cast(value);
            try {
                String plaintext = encryptionService.decrypt(secret);
                list.add(new Value(Strings.repeat("*", plaintext.length())));
                if (LOG.isInfoEnabled())
                    LOG.info("Masking value of " + coreMessage);
            } catch (Exception exception) {
                LOG.error("Failed to mask value of " + coreMessage, exception);
            }//from   ww  w.  j a  v  a 2s  .  c o  m
        } else {
            list.add(value);
        }
    }

    return list;
}

From source file:com.spotify.helios.cli.command.DeploymentGroupWatchCommand.java

@Override
int run(Namespace options, HeliosClient client, PrintStream out, boolean json, BufferedReader stdin)
        throws ExecutionException, InterruptedException, IOException {
    final String name = options.getString(nameArg.getDest());
    final boolean full = options.getBoolean(fullArg.getDest());
    final Integer interval = options.getInt(intervalArg.getDest());
    final DateTimeFormatter formatter = DateTimeFormat.forPattern(DATE_TIME_PATTERN);

    if (!json) {// w  w  w .  jav a  2  s  .  c  o  m
        out.println("Control-C to stop");
        out.println("STATUS               HOST                           STATE");
    }

    final int timestampLength = String.format("[%s UTC]", DATE_TIME_PATTERN).length();

    int rc = 0;
    while (rc == 0) {
        final Instant now = new Instant();
        if (!json) {
            out.printf(Strings.repeat("-", MAX_WIDTH - timestampLength - 1) + " [%s UTC]%n",
                    now.toString(formatter));
        }

        rc = DeploymentGroupStatusCommand.run0(client, out, json, name, full);
        if (out.checkError()) {
            break;
        }

        Thread.sleep(1000 * interval);
    }
    return 0;
}

From source file:com.facebook.presto.cli.QueryPreprocessor.java

public static String preprocessQuery(Optional<String> catalog, Optional<String> schema, String query,
        List<String> preprocessorCommand, Duration timeout) throws QueryPreprocessorException {
    Thread clientThread = Thread.currentThread();
    SignalHandler oldHandler = Signal.handle(SIGINT, signal -> clientThread.interrupt());
    try {/*from   www .  ja v  a  2 s  . c  om*/
        if (REAL_TERMINAL) {
            System.out.print(PREPROCESSING_QUERY_MESSAGE);
            System.out.flush();
        }
        return preprocessQueryInternal(catalog, schema, query, preprocessorCommand, timeout);
    } finally {
        if (REAL_TERMINAL) {
            System.out.print("\r" + Strings.repeat(" ", PREPROCESSING_QUERY_MESSAGE.length()) + "\r");
            System.out.flush();
        }
        Signal.handle(SIGINT, oldHandler);
        Thread.interrupted(); // clear interrupt status
    }
}

From source file:org.shaf.shell.view.StructuredView.java

/**
 * Shows the structured content on the text-based terminal.
 *///from ww  w .ja v a 2 s .  com
@Override
public void show(final StructuredContent content) {
    /*
     * Defines the maximum widths for every table's column.
     */
    TextMatrix table = content.getTable();

    /*
     * Defines the total table width. The table width computes as a sum of
     * all column's width plus (2 * number of columns + 1 ). The twice
     * number of colum plus one provide an extra space for inserting columns
     * separators '|' with one blank character. This blank character intends
     * to provide a padding from the left for every cell value.
     */
    int total = (2 * table.getNumColumns()) + 1;
    int[] widths = table.getColumnWidths();
    for (int width : widths) {
        total += width;
    }

    /*
     * Expands table's columns if it total table width less them 30
     * characters. The next loop expands each column's width to make their
     * overall equals 30 characters.
     */
    if (table.getNumColumns() > 0) {
        int index = -1;
        while (total < 30) {
            ++widths[index = (index + 1 < widths.length) ? ++index : 0];
            ++total;
        }
    } else {
        total = 30;
    }

    /*
     * Prints the top line. The top line of the structured content shows the
     * execution time spend by a process for generating this result.
     */
    String time = TimeUtils.formatTimeInterval(content.getTime());
    super.terminal.println(String.format(
            Strings.repeat("-", total - (time.length() + 5)) + "[%1$s]" + Strings.repeat("-", 3), time));

    /*
     * Constructs the formating string.
     */
    String fmt = "";
    for (int width : widths) {
        fmt += " %-" + (width + 1) + "s";
    }
    fmt += " ";

    /*
     * Prints the table to the terminal.
     */
    for (int row = 0; row < table.getNumRows(); row++) {
        super.terminal.println(String.format(fmt, (Object[]) table.getRow(row)));
    }

    /*
     * Prints the top bottom. The bottom line of the structured content
     * shows the total number of rows included into the result.
     */
    String count = String.valueOf(table.getNumRows());
    super.terminal.println(String.format(
            Strings.repeat("-", total - (count.length() + 12)) + "[Total: %1$s]" + Strings.repeat("-", 3),
            count));
}

From source file:ninja.leaping.configurate.gson.GsonConfigurationLoader.java

protected GsonConfigurationLoader(Builder builder) {
    super(builder, new CommentHandler[] { CommentHandlers.DOUBLE_SLASH, CommentHandlers.SLASH_BLOCK,
            CommentHandlers.HASH });/*from   www . ja v  a 2s  .  c o  m*/
    this.lenient = builder.isLenient();
    this.indent = Strings.repeat(" ", builder.getIndent());
}

From source file:com.chiorichan.ConsoleLogger.java

public void log(Level l, String client, String msg) {
    if (client.length() < 15) {
        client = client + Strings.repeat(" ", 15 - client.length());
    }//w  w w.  ja v  a  2  s .  c  o  m

    printHeader();

    log(l, ConsoleColor.LIGHT_PURPLE + client + " " + ConsoleColor.AQUA + msg);
}