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:google.registry.tools.CommandUtilities.java

static String addHeader(String header, String body) {
    return String.format("%s:\n%s\n%s", header, Strings.repeat("-", header.length() + 1), body);
}

From source file:org.seedstack.seed.core.internal.configuration.tool.DetailPrinter.java

void printDetail(PrintStream stream) {
    Ansi ansi = Ansi.ansi();/*w ww . ja  v  a  2 s. c o  m*/

    String title = "Details of " + propertyInfo.getName();
    ansi.a(title).newline().a(Strings.repeat("-", title.length())).newline().newline();

    printSummary(propertyInfo, ansi);
    printDeclaration(propertyInfo, ansi);
    printLongDescription(propertyInfo, ansi);
    printAdditionalInfo(propertyInfo, ansi);
    ansi.newline();

    stream.print(ansi.toString());
}

From source file:ru.org.linux.util.formatter.ToLorCodeTexFormatter.java

public static String quote(String text, String newLine) {
    StringBuilder buf = new StringBuilder();
    String[] lines = NL_REGEXP.split(text);
    int globalNestingLevel = 0;
    int currentLine = 0;

    boolean isCode = false;

    for (String line : lines) {
        currentLine += 1;/*from  w  ww  . j  a  va 2 s  . c om*/

        if (line.isEmpty()) {
            if (globalNestingLevel > 0) {
                buf.append(Strings.repeat("[/quote]", globalNestingLevel));
                globalNestingLevel = 0;
            } else {
                if (isCode) {
                    buf.append('\n');
                } else {
                    buf.append(newLine);
                }
            }
            continue;
        }

        Matcher m = QUOTE_PATTERN.matcher(line);
        if (!isCode && m.find()) {
            int nestingLevel = m.group(1).length();
            if (globalNestingLevel == 0) {
                buf.append(Strings.repeat("[quote]", nestingLevel));
                globalNestingLevel = nestingLevel;
            } else if (nestingLevel < globalNestingLevel) {
                buf.append(Strings.repeat("[/quote]", globalNestingLevel - nestingLevel));
                globalNestingLevel = nestingLevel;
            } else if (nestingLevel > globalNestingLevel) {
                buf.append(Strings.repeat("[quote]", nestingLevel - globalNestingLevel));
                globalNestingLevel = nestingLevel;
            }
            buf.append(escapeCode(line.substring(nestingLevel)));
            if (currentLine < lines.length) {
                buf.append("[br]");
            }
        } else {
            if (globalNestingLevel > 0) {
                buf.append(Strings.repeat("[/quote]", globalNestingLevel));
                globalNestingLevel = 0;
            }

            Matcher codeMatcher = CODE_PATTERN.matcher(line);

            if (codeMatcher.find()) {
                isCode = true;
            }

            Matcher codeEndMatcher = CODE_END_PATTERN.matcher(line);
            if (codeEndMatcher.find()) {
                if (globalNestingLevel > 0) {
                    line = escapeCode(line);
                } else {
                    isCode = false;
                }
            }

            buf.append(line);

            if (currentLine < lines.length) {
                if (isCode) {
                    buf.append('\n');
                } else {
                    buf.append(newLine);
                }
            }
        }
    }

    if (globalNestingLevel > 0) {
        buf.append(Strings.repeat("[/quote]", globalNestingLevel));
    }

    return buf.toString();
}

From source file:jetbrains.jetpad.model.composite.dump.StringBuilderDumpContext.java

@Override
public void println(String text) {
    myResult.append(Strings.repeat("  ", myIndent)).append(text).append("\n");
}

From source file:io.proleap.cobol.preprocessor.sub.util.CobolSourceFormatUtils.java

public static String getBlankSequenceArea(final CobolSourceFormatEnum format) {
    final String result;

    if (format == null) {
        result = null;//w  ww  .j  a v a 2s .c o m
    } else if (CobolSourceFormatEnum.TANDEM.equals(format)) {
        result = "";
    } else {
        result = Strings.repeat(CobolPreprocessor.WS, 6);
    }

    return result;
}

From source file:com.github.jcustenborder.kafka.connect.utils.templates.IntentedWriter.java

@Override
public void write(String s) {
    int count = indent * 4;

    if (count > 0) {
        super.write(Strings.repeat(" ", count));
    }/*from   w ww  .  j  av  a  2s . co m*/

    super.write(s);
}

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

static String formatToParagraph(final String text, final int nextLineIndent) {
    if (Strings.isNullOrEmpty(text)) {
        return "";
    }// w w w.j a  v  a  2s.c o m

    final StringBuilder sb = new StringBuilder();
    final StringBuilder lineBuilder = new StringBuilder();
    boolean isFirstElementOnNewLineEmptyChar = false;
    final String lineIndent = Strings.repeat(" ", nextLineIndent);

    String formattedText = NEWLINE_OR_TAB.removeFrom(text);
    formattedText = formattedText.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:uk.ac.ed.inf.ace.cli.OutStream.java

private void undoInput() {
    if (proxyEnabled) {
        proxyEnabled = false;
        realOut.print(Strings.repeat("\b", prompt.length()));
    }
}

From source file:ninja.leaping.configurate.json.ConfiguratePrettyPrinter.java

public ConfiguratePrettyPrinter(int indent, FieldValueSeparatorStyle style) {
    this._objectIndenter = indent == 0 ? NopIndenter.instance
            : DefaultIndenter.SYSTEM_LINEFEED_INSTANCE.withIndent(Strings.repeat(" ", indent));
    this.style = style;
}

From source file:org.nest.nestml._ast.ASTDerivative.java

@Override
public String toString() {

    return name + Strings.repeat("'", getDifferentialOrder().size());
}