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.robotframework.ide.eclipse.main.plugin.validation.ReportWithCheckstyleFormat.java

void writeEntries(final Map<IPath, Collection<RobotProblemWithPosition>> problems) throws IOException {
    for (final IPath path : problems.keySet()) {
        writer.append(/*from w  w w.jav a2 s. c  o m*/
                Strings.repeat(" ", 2) + "<file name=\"" + xmlAttrEscaper.escape(path.toString()) + "\">\n");
        writeProblems(problems.get(path));
        writer.append(Strings.repeat(" ", 2) + "</file>\n");
    }
}

From source file:com.spotify.helios.system.LoggingTestWatcher.java

/**
 * Logs a line full of the = character as a separator.
 */
private void logLine() {
    log.info(Strings.repeat("=", 80));
}

From source file:com.google.errorprone.ErrorProneError.java

private static String formatMessage(String checkName, JavaFileObject file, DiagnosticPosition pos,
        Throwable cause) {/*w  w w .j av a  2 s  .c om*/
    DiagnosticSource source = new DiagnosticSource(file, /*log=*/ null);
    int column = source.getColumnNumber(pos.getStartPosition(), /*expandTabs=*/ true);
    int line = source.getLineNumber(pos.getStartPosition());
    String snippet = source.getLine(pos.getStartPosition());
    StringBuilder sb = new StringBuilder();
    sb.append(String.format("\n%s:%d: %s: An exception was thrown by Error Prone: %s\n",
            source.getFile().getName(), line, checkName, cause.getMessage()));
    sb.append(snippet).append('\n');
    if (column > 0) {
        sb.append(Strings.repeat(" ", column - 1));
    }
    sb.append("^\n");
    return sb.toString();
}

From source file:com.google.template.soy.jssrc.dsl.FormattingContext.java

/** @param startingIndent The number of columns to consider the "baseline" indentation level. */
FormattingContext(int startingIndent) {
    curIndent = Strings.repeat(" ", startingIndent);
    buf = new StringBuilder(curIndent);
    initialSize = curIndent.length();// w w w.j  a v a 2s  .  co  m
}

From source file:org.jeo.cli.ConsoleProgress.java

public void redraw() {
    PrintStream out = System.out;

    //number of digits in total to padd count
    int n = (int) (Math.log10(total) + 1);

    StringBuilder sb = new StringBuilder();

    // first encode count/total
    sb.append("[").append(String.format("%" + n + "d", count)).append("/").append(total).append("]");

    // second is percent
    sb.append(" ").append(String.format("%3.0f", (count / (float) total * 100))).append("% ");

    //last is progress bar
    int left = console.getTerminal().getWidth() - sb.length() - 2;
    int progress = count * left / total;

    sb.append("[").append(Strings.repeat("=", progress)).append(Strings.repeat(" ", left - progress))
            .append("]");

    out.print(sb.toString() + "\r");
    //        console.getCursorBuffer().clear();
    //        console.getCursorBuffer().write("\r");
    //        console.getCursorBuffer().write(sb.toString());
    //        try {
    //            console.setCursorPosition(sb.length());
    //            console.redrawLine();
    //            console.flush();
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        }/*from   www.  j av a  2 s .c om*/
}

From source file:org.eclipse.xtext.ide.serializer.debug.TextDocumentChangeToString.java

private 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);// www.  j  av a  2  s .  c om
    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.n52.iceland.statistics.generator.formats.MdFormat.java

private String formatLine(AbstractEsParameter parameter, int indent) {
    String line = Strings.repeat(TAB, indent);

    // Fieldname//from w  w w .  j a v  a2 s .c  o m
    line += LINE_TEMPLATE.replace("<fieldname>", parameter.getName());

    // Description
    if (parameter.getDescription() != null) {
        if (parameter.getDescription().getDesc() != null) {
            line = line.replace(DESCRIPTION_PLACEHOLDER, parameter.getDescription().getDesc());
        } else {
            line = line.replace(DESCRIPTION_PLACEHOLDER, NO_DESCRIPTION);
        }

        // Type
        if (parameter.getType() != null) {
            line += TYPE_TEMPLATE.replace("<type>", parameter.getType().humanReadableType());
        }
    } else {
        line = line.replace(DESCRIPTION_PLACEHOLDER, NO_DESCRIPTION);
    }

    line += NEW_LINE;
    return line;
}

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

protected static List<String> shiftLeftMinTwoTabs(String tabAsSpaces, List<String> lines) {
    List<String> ret = lines;

    int minIndent = Integer.MAX_VALUE;

    for (String line : lines) {
        Matcher matcher = SPACES_ON_THE_LEFT.matcher(line);
        if (matcher.find()) {
            String spaces = matcher.group("spaces");
            spaces = spaces.replace("\t", tabAsSpaces);
            minIndent = Math.min(minIndent, spaces.length());
        }//  w w  w . j a v  a 2  s .c  om
    }

    int addInFront = 8 - minIndent;
    if (addInFront > 0) {
        String pre = Strings.repeat(" ", addInFront);
        ret = Lists.newArrayList();
        for (String line : lines) {
            ret.add(pre + line.replace("\t", tabAsSpaces));
        }
    }

    return ret;
}

From source file:com.bacoder.parser.core.DumpVisitor.java

@Override
public void visitBefore(Node node) {
    String tag = String.format("%s<%s sl=\"%d\" sc=\"%d\" el=\"%d\" ec=\"%d\">\n",
            Strings.repeat(indent, level), node.getClass().getSimpleName(), node.getStartLine(),
            node.getStartColumn(), node.getEndLine(), node.getEndColumn());
    try {//  ww w  .j a v  a 2s .c o  m
        outputStream.write(tag.getBytes());

        Class<? extends Node> clazz = node.getClass();
        if (clazz.getAnnotation(DumpTextWithToString.class) != null) {
            String property = String.format("%s<text>%s</text>\n", Strings.repeat(indent, level + 1),
                    node.toString());
            try {
                outputStream.write(property.getBytes());
            } catch (IOException e) {
                throw new RuntimeException("Unable to write \'" + property + "\'", e);
            }
        } else {
            Field[] fields = node.getClass().getDeclaredFields();
            for (Field field : fields) {
                Class<?> type = field.getType();
                if (type.isPrimitive() || type.isEnum() || String.class.isAssignableFrom(type)) {
                    String propertyName = field.getName();
                    Object value;
                    try {
                        value = PropertyUtils.getSimpleProperty(node, propertyName);
                        String property = String.format("%s<%s>%s</%s>\n", Strings.repeat(indent, level + 1),
                                propertyName,
                                value == null ? "" : StringEscapeUtils.escapeXml(value.toString()),
                                propertyName);
                        try {
                            outputStream.write(property.getBytes());
                        } catch (IOException e) {
                            throw new RuntimeException("Unable to write \'" + property + "\'", e);
                        }
                    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                        // Ignore the field.
                    }
                }
            }
        }
    } catch (IOException e) {
        throw new RuntimeException("Unable to write \'" + tag + "\'", e);
    }
    level++;
}

From source file:net.revelc.code.formatter.json.JsonFormatter.java

@Override
public void init(Map<String, String> options, ConfigurationSource cfg) {
    super.initCfg(cfg);

    int indent = Integer.parseInt(options.getOrDefault("indent", "4"));
    String lineEnding = options.getOrDefault("lineending", System.lineSeparator());
    boolean spaceBeforeSeparator = Boolean.parseBoolean(options.getOrDefault("spaceBeforeSeparator", "true"));

    formatter = new ObjectMapper();

    // Setup a pretty printer with an indenter (indenter has 4 spaces in this case)
    DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(Strings.repeat(" ", indent), lineEnding);
    DefaultPrettyPrinter printer = new DefaultPrettyPrinter() {
        private static final long serialVersionUID = 1L;

        @Override//w ww  . j a v a  2 s. c  o  m
        public DefaultPrettyPrinter withSeparators(Separators separators) {
            this._separators = separators;
            this._objectFieldValueSeparatorWithSpaces = (spaceBeforeSeparator ? " " : "")
                    + separators.getObjectFieldValueSeparator() + " ";
            return this;
        }
    };

    printer.indentObjectsWith(indenter);
    printer.indentArraysWith(indenter);
    formatter.setDefaultPrettyPrinter(printer);
    formatter.enable(SerializationFeature.INDENT_OUTPUT);
}