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.apache.drill.exec.util.FileSystemUtilTestBase.java

private static void createDefaultStructure(FileSystem fs, Path base, String name, int nesting)
        throws IOException {
    Path newBase = base;//  w w  w  . j  a v  a2s.c  o m
    for (int i = 1; i <= nesting; i++) {
        Path path = new Path(newBase, Strings.repeat(name, i));
        fs.mkdirs(path);
        for (String fileName : Arrays.asList("f.txt", ".f.txt", "_f.txt")) {
            fs.createNewFile(new Path(path, fileName));
        }
        newBase = path;
    }
}

From source file:org.sonatype.nexus.internal.log.LogMarkerImpl.java

@Override
public void markLog(final String message) {
    // ensure that level for marking logger is enabled
    LoggerLevel loggerLevel = logManager.getLoggerEffectiveLevel(log.getName());
    if (LoggerLevel.INFO.compareTo(loggerLevel) < 0 || LoggerLevel.OFF.equals(loggerLevel)) {
        logManager.setLoggerLevel(log.getName(), LoggerLevel.INFO);
    }//from   ww w  .  j a v  a2  s. co m

    String asterixes = Strings.repeat("*", message.length() + 4);
    log.info("\n{}\n* {} *\n{}", asterixes, message, asterixes);

    eventBus.post(new LogMarkInsertedEvent(message));
}

From source file:org.opendaylight.mdsal.binding.javav2.generator.impl.util.YangTextTemplate.java

/**
 * Used in #yangtemplateformodule.scala.txt for formating revision description
 *
 * @param text Content of tag description
 * @param nextLineIndent Number of spaces from left side default is 12
 * @return formatted description//from   ww  w  . ja  v  a2 s .  c  om
 */
public static String formatToParagraph(final String text, final int nextLineIndent) {
    if (Strings.isNullOrEmpty(text)) {
        return "";
    }
    boolean isFirstElementOnNewLineEmptyChar = false;
    final StringBuilder sb = new StringBuilder();
    final StringBuilder lineBuilder = new StringBuilder();
    final String lineIndent = Strings.repeat(" ", nextLineIndent);
    final String textToFormat = NEWLINE_OR_TAB.removeFrom(text);
    final String formattedText = textToFormat.replaceAll(" +", " ");
    final StringTokenizer tokenizer = new StringTokenizer(formattedText, " ", true);

    while (tokenizer.hasMoreElements()) {
        final String nextElement = tokenizer.nextElement().toString();

        if (lineBuilder.length() + nextElement.length() > 80) {
            // Trim trailing whitespace
            for (int i = lineBuilder.length() - 1; i >= 0 && lineBuilder.charAt(i) != ' '; --i) {
                lineBuilder.setLength(i);
            }
            // Trim leading whitespace
            while (lineBuilder.charAt(0) == ' ') {
                lineBuilder.deleteCharAt(0);
            }
            sb.append(lineBuilder).append('\n');
            lineBuilder.setLength(0);

            if (nextLineIndent > 0) {
                sb.append(lineIndent);
            }

            if (" ".equals(nextElement)) {
                isFirstElementOnNewLineEmptyChar = true;
            }
        }
        if (isFirstElementOnNewLineEmptyChar) {
            isFirstElementOnNewLineEmptyChar = false;
        } else {
            lineBuilder.append(nextElement);
        }
    }
    return sb.append(lineBuilder).append('\n').toString();
}

From source file:org.syncany.cli.util.CarriageReturnPrinter.java

private void clearLastLine() {
    if (lastWasWithCarriageReturn) {
        String spacesStr = "\r" + Strings.repeat(" ", lineLength) + "\r";
        underlyingPrintStream.print(spacesStr);

        lastWasWithCarriageReturn = false;
    }/*from   ww  w  . jav a2s.  c om*/
}

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

/**
 * Shows the unstructured content on the text-based terminal.
 *//*from   w w w .  ja  v a 2 s  .  co m*/
@Override
public void show(final UnstructuredContent content) {
    if (content == null) {
        return;
    }

    /*
     * The total length of the output content. If it length less than 30
     * characters the total value set to 30. If it length greater than 80
     * characters the total value set to 80. This trimming ensures the same
     * output style for structured and unstructured contends.
     */
    int total = content.getText().length();
    total = (total < 30) ? 30 : total;
    total = (total > 80) ? 80 : total;

    /*
     * Prints the top line. The top line of the unstructured 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("-", 11) + Strings.repeat("-", total - (time.length() + 16)) + "[%1$s]---", time));

    /*
     * Prints the content body.
     */
    this.terminal.println(content.getText());
}

From source file:com.facebook.buck.cxx.ArchiveScrubberStep.java

private void putIntAsDecimalString(ByteBuffer buffer, int len, int value) {
    String val = String.format("%d", value);
    Preconditions.checkState(val.length() <= len);
    val = Strings.repeat(" ", len - val.length()) + val;
    buffer.put(val.getBytes(Charsets.US_ASCII));
}

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

@Override
public String toString() {
    int offsetDigits = 0;
    int lengthDigits = 0;
    for (Item item : items) {
        if (item.region != null) {
            int lengthD = String.valueOf(item.region.getLength()).length();
            if (lengthDigits < lengthD)
                lengthDigits = lengthD;//from   www  . j a v a 2  s. com
            int lengthO = String.valueOf(item.region.getOffset()).length();
            if (offsetDigits < lengthO)
                offsetDigits = lengthO;
        }
    }
    List<String> result = Lists.newArrayListWithExpectedSize(items.size());
    String prefix = Strings.repeat(" ", offsetDigits + lengthDigits + 2);
    for (Item item : items) {
        String[] lines = item.text.split("\n");
        if (item.region != null) {
            String offset = Strings.padStart(String.valueOf(item.region.getOffset()), offsetDigits, ' ');
            String length = Strings.padStart(String.valueOf(item.region.getLength()), lengthDigits, ' ');
            if (lines.length == 1) {
                result.add(offset + " " + length + " " + lines[0]);
            } else {
                String offsetSpace = Strings.repeat(" ", offsetDigits);
                String lengthSpace = Strings.repeat(" ", lengthDigits);
                for (int i = 0; i < lines.length; i++) {
                    String first = i == 0 ? offset : offsetSpace;
                    String second = i == lines.length - 1 ? length : lengthSpace;
                    result.add(first + " " + second + " " + lines[i]);
                }
            }
        } else if (item.indented) {
            for (int i = 0; i < lines.length; i++)
                result.add(prefix + lines[i]);
        } else {
            for (int i = 0; i < lines.length; i++)
                result.add(lines[i]);
        }
    }
    return Joiner.on("\n").join(result);
}

From source file:io.viewserver.adapters.common.sql.SimpleSqlDataQueryProvider.java

@JsonIgnore
@Override/*  w  ww  . j a  v  a  2  s . c  om*/
public String getInsertQuery() {
    if (insertQuery == null) {
        String placeholders = "";
        if (schema.getWidth() > 1) {
            placeholders = Strings.repeat(",?", schema.getWidth() - 1);
        }

        String columnNames = "";
        boolean first = true;
        List<ColumnHolder> columnHolders = schema.getColumnHolders();
        int count = columnHolders.size();
        for (int i = 0; i < count; i++) {
            ColumnHolder columnHolder = columnHolders.get(i);
            if (columnHolder == null) {
                continue;
            }
            if (!first) {
                columnNames += ",";
            }
            columnNames += columnHolder.getName();
            first = false;
        }

        insertQuery = "insert into " + tableName + " (" + columnNames + ") values (?" + placeholders + ")";
    }
    return insertQuery;
}

From source file:org.robotframework.ide.eclipse.main.plugin.validation.ReportWithCheckstyleFormat.java

private void writeProblems(final Collection<RobotProblemWithPosition> problems) throws IOException {
    for (final RobotProblemWithPosition problemEntry : problems) {
        final ProblemPosition position = problemEntry.getPosition();
        final RobotProblem problem = problemEntry.getProblem();
        final Severity severity = problem.getSeverity();
        writer.append(Strings.repeat(" ", 4) + "<error line=\"" + position.getLine() + "\" message=\""
                + xmlAttrEscaper.escape(problem.getMessage()) + "\" severity=\""
                + severity.getName().toLowerCase() + "\"" + "/>\n");
    }//ww  w  . j  a va  2 s  .  c  o  m
}

From source file:nanoverse.compiler.pipeline.interpret.nodes.ASTNode.java

public void astReport(StringBuilder builder, int indentLevel) {
    builder.append(Strings.repeat(" ", indentLevel));
    builder.append("container: " + identifier + "(" + size() + ")\n");
    if (children == null) {
        throw new IllegalStateException("Container " + identifier + " has null child list");
    }//from   w  w  w  .  j  a v  a2  s.  c om
    children.stream().forEach(child -> {
        if (child == null) {
            throw new IllegalStateException("Container " + identifier + " has a null child");
        }
        child.astReport(builder, indentLevel + 1);
    });
}