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:org.opendaylight.infrautils.utils.TablePrinter.java

@Override
public String toString() {
    String separator = columnSeparator();
    int[] maxWidths = calculateWidths();
    StringBuilder sb = new StringBuilder();

    table.sort(comparator);//w  w w .ja v a  2 s. c  o  m

    printTitle(sb);
    printHeader(separator, maxWidths, sb);
    for (String[] row : table) {
        if (title != null) {
            sb.append(Strings.repeat(" ", SPACE_BEFORE_TABLES_WITH_TITLE));
        }
        printRow(separator, maxWidths, sb, row);
    }

    return sb.toString();
}

From source file:org.robotframework.ide.eclipse.main.plugin.tableeditor.source.SuiteSourceFormattingStrategy.java

private String formatLineWithConstantSeparator(final String line, final int separatorLength) {
    final String lineWithoutTabs = line.replaceAll("\t", "  ");
    final String constantlySeparatedLine = lineWithoutTabs.replaceAll("  +",
            Strings.repeat(" ", separatorLength));
    final String withTrimmedEnd = constantlySeparatedLine.replaceFirst(" +$", "");
    return withTrimmedEnd;
}

From source file:com.github.jcustenborder.kafka.connect.utils.config.MarkdownFormatter.java

static String markdownTable(List<List<String>> rows) {
    StringBuilder builder = new StringBuilder();
    List<Integer> lengths = lengths(rows);

    int index = 0;
    for (List<String> row : rows) {
        List<String> copy = new ArrayList<>(row.size());
        for (int i = 0; i < row.size(); i++) {
            String f = Strings.padEnd(row.get(i) == null ? "" : row.get(i), lengths.get(i), ' ');
            copy.add(f);//from   w ww . jav a  2s .co  m
        }

        builder.append("| ");
        Joiner.on(" | ").appendTo(builder, copy);
        builder.append(" |\n");

        if (index == 0) {
            List<String> bar = new ArrayList<>(lengths.size());

            for (Integer length : lengths) {
                bar.add(Strings.repeat("-", length + 2));
            }
            builder.append("|");
            Joiner.on("|").appendTo(builder, bar);
            builder.append("|\n");
        }

        index++;
    }

    return builder.toString();
}

From source file:bear.main.ProjectGenerator.java

protected static void addQuick(OpenStringBuilder sb, String number, String hostsString) {
    sb.append(Strings.repeat("    ", 3)).append(".addQuick(\"").append(number).append("\", \"")
            .append(hostsString).append("\")\n");
}

From source file:com.zimbra.common.auth.twofactor.TOTPAuthenticator.java

public String calculateHOTP(byte[] K, byte[] C) throws ServiceException {
    //step 1//  w  ww .ja  v a  2  s.c o m
    byte[] hash = calculateHash(K, C);
    //step 2
    int truncated = dynamicTruncate(hash);
    //step 3
    int code = generateFinalCode(truncated);

    String codeString = String.valueOf(code);
    int numDigits = config.getNumCodeDigits();
    if (codeString.length() == numDigits) {
        return codeString;
    } else {
        //pad with zeros
        return Strings.repeat("0", numDigits - codeString.length()) + codeString;
    }
}

From source file:com.b2international.snowowl.server.console.RemoteJobsCommandProvider.java

private void printSeparator(final CommandInterpreter interpreter) {
    interpreter.println(Strings.repeat("-", 135));
}

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

private static void runConsole(QueryRunner queryRunner, ClientSession session) {
    try (TableNameCompleter tableNameCompleter = new TableNameCompleter(queryRunner);
            LineReader reader = new LineReader(getHistory(), commandCompleter(), lowerCaseCommandCompleter(),
                    tableNameCompleter)) {
        tableNameCompleter.populateCache();
        StringBuilder buffer = new StringBuilder();
        while (true) {
            // read a line of input from user
            String prompt = PROMPT_NAME;
            if (session.getSchema() != null) {
                prompt += ":" + session.getSchema();
            }// w w  w . jav a2 s.  co  m
            if (buffer.length() > 0) {
                prompt = Strings.repeat(" ", prompt.length() - 1) + "-";
            }
            String commandPrompt = prompt + "> ";
            String line = reader.readLine(commandPrompt);

            // add buffer to history and clear on user interrupt
            if (reader.interrupted()) {
                String partial = squeezeStatement(buffer.toString());
                if (!partial.isEmpty()) {
                    reader.getHistory().add(partial);
                }
                buffer = new StringBuilder();
                continue;
            }

            // exit on EOF
            if (line == null) {
                System.out.println();
                return;
            }

            // check for special commands if this is the first line
            if (buffer.length() == 0) {
                String command = line.trim();

                if (HISTORY_INDEX_PATTERN.matcher(command).matches()) {
                    int historyIndex = parseInt(command.substring(1));
                    History history = reader.getHistory();
                    if ((historyIndex <= 0) || (historyIndex > history.index())) {
                        System.err.println("Command does not exist");
                        continue;
                    }
                    line = history.get(historyIndex - 1).toString();
                    System.out.println(commandPrompt + line);
                }

                if (command.endsWith(";")) {
                    command = command.substring(0, command.length() - 1).trim();
                }

                switch (command.toLowerCase(ENGLISH)) {
                case "exit":
                case "quit":
                    return;
                case "history":
                    for (History.Entry entry : reader.getHistory()) {
                        System.out.printf("%5d  %s%n", entry.index() + 1, entry.value());
                    }
                    continue;
                case "help":
                    System.out.println();
                    System.out.println(getHelpText());
                    continue;
                }
            }

            // not a command, add line to buffer
            buffer.append(line).append("\n");

            // execute any complete statements
            String sql = buffer.toString();
            StatementSplitter splitter = new StatementSplitter(sql, ImmutableSet.of(";", "\\G"));
            for (Statement split : splitter.getCompleteStatements()) {
                Optional<Object> statement = getParsedStatement(split.statement());
                if (statement.isPresent() && isSessionParameterChange(statement.get())) {
                    Map<String, String> properties = queryRunner.getSession().getProperties();
                    session = processSessionParameterChange(statement.get(), session, properties);
                    queryRunner.setSession(session);
                    tableNameCompleter.populateCache();
                } else {
                    OutputFormat outputFormat = OutputFormat.ALIGNED;
                    if (split.terminator().equals("\\G")) {
                        outputFormat = OutputFormat.VERTICAL;
                    }

                    process(queryRunner, split.statement(), outputFormat, true);
                }
                reader.getHistory().add(squeezeStatement(split.statement()) + split.terminator());
            }

            // replace buffer with trailing partial statement
            buffer = new StringBuilder();
            String partial = splitter.getPartialStatement();
            if (!partial.isEmpty()) {
                buffer.append(partial).append('\n');
            }
        }
    } catch (IOException e) {
        System.err.println("Readline error: " + e.getMessage());
    }
}

From source file:ezbake.deployer.utilities.Utilities.java

private static String ppTBaseObject(TBase t, int depth) {
    List<String> fields = Lists.newArrayList();
    final String indent = Strings.repeat("  ", depth);
    for (Map.Entry<? extends TFieldIdEnum, FieldMetaData> entry : FieldMetaData
            .getStructMetaDataMap(t.getClass()).entrySet()) {
        fields.add(indent + entry.getValue().fieldName + ": " + ppTBaseField(t, entry, depth));
    }/*  w  w w.  j  av  a2 s .  com*/
    return Joiner.on("\n").join(fields);
}

From source file:com.google.devtools.build.lib.rules.cpp.LibrariesToLinkCollector.java

public LibrariesToLinkCollector(boolean isNativeDeps, CppConfiguration cppConfiguration,
        CcToolchainProvider toolchain, PathFragment toolchainLibrariesSolibDir, LinkTargetType linkType,
        Link.LinkingMode linkingMode, Artifact output, PathFragment solibDir, boolean isLtoIndexing,
        Iterable<LtoBackendArtifacts> allLtoArtifacts, FeatureConfiguration featureConfiguration,
        Artifact thinltoParamFile, boolean allowLtoIndexing, Iterable<LinkerInput> linkerInputs,
        boolean needWholeArchive) {
    this.isNativeDeps = isNativeDeps;
    this.cppConfiguration = cppConfiguration;
    this.ccToolchainProvider = toolchain;
    this.toolchainLibrariesSolibDir = toolchainLibrariesSolibDir;
    this.outputArtifact = output;
    this.solibDir = solibDir;
    this.isLtoIndexing = isLtoIndexing;
    this.allLtoArtifacts = allLtoArtifacts;
    this.featureConfiguration = featureConfiguration;
    this.thinltoParamFile = thinltoParamFile;
    this.allowLtoIndexing = allowLtoIndexing;
    this.linkerInputs = linkerInputs;
    this.needWholeArchive = needWholeArchive;

    needToolchainLibrariesRpath = toolchainLibrariesSolibDir != null && (linkType.isDynamicLibrary()
            || (linkType == LinkTargetType.EXECUTABLE && linkingMode == LinkingMode.DYNAMIC));

    // Calculate the correct relative value for the "-rpath" link option (which sets
    // the search path for finding shared libraries).
    if (isNativeDeps && cppConfiguration.shareNativeDeps()) {
        // For shared native libraries, special symlinking is applied to ensure C++
        // toolchain libraries are available under $ORIGIN/_solib_[arch]. So we set the RPATH to find
        // them./*from  ww  w  . ja va2 s. co m*/
        //
        // Note that we have to do this because $ORIGIN points to different paths for
        // different targets. In other words, blaze-bin/d1/d2/d3/a_shareddeps.so and
        // blaze-bin/d4/b_shareddeps.so have different path depths. The first could
        // reference a standard blaze-bin/_solib_[arch] via $ORIGIN/../../../_solib[arch],
        // and the second could use $ORIGIN/../_solib_[arch]. But since this is a shared
        // artifact, both are symlinks to the same place, so
        // there's no *one* RPATH setting that fits all targets involved in the sharing.
        rpathRoot = ccToolchainProvider.getSolibDirectory() + "/";
    } else {
        rpathRoot = Strings.repeat("../", outputArtifact.getRootRelativePath().segmentCount() - 1)
                + ccToolchainProvider.getSolibDirectory() + "/";
    }

    ltoMap = generateLtoMap();
}

From source file:net.joala.bdd.watcher.JUnitScenarioWatcher.java

/**
 * Add some padding to the type to be logged (scenario/story).
 *
 * @param type scenario or story//from   w ww .  j  av  a  2 s  .  c om
 * @return padded story/scenario name
 */
private static String typePadding(final CharSequence type) {
    return Strings.repeat(".", max(MIN_DOTS, MAX_TYPE_PADDING - type.length()));
}