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.spongepowered.api.command.args.ArgumentParseException.java

/**
 * Return a string pointing to the position of the arguments when this exception occurs.
 *
 * @return The appropriate position string
 *///from  www .  j  a v  a  2  s . c om
public String getAnnotatedPosition() {
    String source = this.source;
    int position = this.position;
    if (source.length() > 80) {
        if (position >= 37) {
            int startPos = position - 37;
            int endPos = Math.min(source.length(), position + 37);
            if (endPos < source.length()) {
                source = "..." + source.substring(startPos, endPos) + "...";
            } else {
                source = "..." + source.substring(startPos, endPos);
            }
            position -= 40;
        } else {
            source = source.substring(0, 77) + "...";
        }
    }
    return source + "\n" + Strings.repeat(" ", position) + "^";
}

From source file:de.huberlin.german.korpling.laudatioteitool.TEIValidator.java

public static String formatParserExceptions(Errors errors) {
    if (errors.isEmpty()) {
        return "";
    }/* w w w  . j ava2s  .  c  o m*/

    StringBuilder sb = new StringBuilder();

    for (Map.Entry<File, List<SAXParseException>> entry : errors.entrySet()) {
        List<String> linesRaw = new LinkedList<String>();
        try {
            // split lines so we can reuse them later
            linesRaw = Files.readLines(entry.getKey(), Charsets.UTF_8);
        } catch (IOException ex) {
            log.error("UTF-8 is an unknown encoding on this computer", entry.getKey());
        }
        String[] lines = linesRaw.toArray(new String[linesRaw.size()]);

        String header = entry.getKey().getPath() + " has " + entry.getValue().size()
                + (entry.getValue().size() > 1 ? " errors" : " error");
        sb.append(header).append("\n");

        sb.append(Strings.repeat("=", header.length())).append("\n");

        ListIterator<SAXParseException> it = entry.getValue().listIterator();
        while (it.hasNext()) {
            SAXParseException ex = it.next();

            int columnNr = ex.getColumnNumber();
            int lineNr = ex.getLineNumber();

            sb.append("[line ").append(lineNr).append("/column ").append(columnNr).append("]").append("\n");
            String caption = ex.getLocalizedMessage();

            sb.append(caption).append("\n");

            // output complete affected line 
            String line = lines[lineNr - 1];
            sb.append(line).append("\n");

            // output a marker for the columns
            sb.append(Strings.padStart("^", columnNr, ' ')).append("\n");

            sb.append(Strings.repeat("-", Math.min(80, Math.max(caption.length(), line.length()))))
                    .append("\n");
        }
    }

    return sb.toString();
}

From source file:org.geogit.metrics.CallStack.java

private void dump(PrintStream out, final CallStack stackElement, final int indentLevel,
        final double durationFactor, final String unitName, final long totalNanos) {
    if (indentLevel > 0) {
        out.print(Strings.repeat("    ", indentLevel));
    }//w  w w  .j a  v  a  2 s. com
    out.println(stackElement.toString(durationFactor, unitName, totalNanos));
    if (stackElement.children != null) {
        for (CallStack childElem : stackElement.children) {
            dump(out, childElem, indentLevel + 1, durationFactor, unitName, totalNanos);
        }
    }
}

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

@SuppressWarnings("fallthrough")
private void runConsole(QueryRunner queryRunner, ClientSession session) {
    try (TableNameCompleter tableNameCompleter = new TableNameCompleter(clientOptions.toClientSession(),
            queryRunner); LineReader reader = new LineReader(getHistory(), tableNameCompleter)) {
        tableNameCompleter.populateCache(session.getSchema());
        StringBuilder buffer = new StringBuilder();
        while (true) {
            // read a line of input from user
            String prompt = PROMPT_NAME + ":" + session.getSchema();
            if (buffer.length() > 0) {
                prompt = Strings.repeat(" ", prompt.length() - 1) + "-";
            }/*from www .ja  v a2  s.  co m*/
            String line = reader.readLine(prompt + "> ");

            // 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) {
                return;
            }

            // check for special commands if this is the first line
            if (buffer.length() == 0) {
                String command = line.trim();
                if (command.endsWith(";")) {
                    command = command.substring(0, command.length() - 1).trim();
                }
                switch (command.toLowerCase()) {
                case "exit":
                case "quit":
                    return;
                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()) {
                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:org.apache.jackrabbit.oak.plugins.tika.BinaryStats.java

private String getSummary(List<MimeTypeStats> stats) {
    int maxWidth = 0;
    for (MimeTypeStats s : stats) {
        maxWidth = Math.max(maxWidth, s.getName().length());
    }//from   w w  w  .j  a va  2  s.c o  m

    maxWidth += 5;

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    pw.println("MimeType Stats");
    pw.printf("\tTotal size          : %s%n", humanReadableByteCount(totalSize));
    pw.printf("\tTotal indexed size  : %s%n", humanReadableByteCount(indexedSize));
    pw.printf("\tTotal count         : %d%n", totalCount);
    pw.printf("\tTotal indexed count : %d%n", indexedCount);
    pw.println();

    String header = center("Type", maxWidth) + " " + center("Indexed", 10) + " " + center("Supported", 10) + " "
            + center("Count", 10) + " " + center("Size", 10);

    pw.println(header);
    pw.println(Strings.repeat("_", header.length() + 5));

    for (MimeTypeStats s : stats) {
        pw.printf("%-" + maxWidth + "s|%10s|%10s|  %-8d|%10s%n", s.getName(), s.isIndexed(), s.isSupported(),
                s.getCount(), humanReadableByteCount(s.getTotalSize()));
    }
    return sw.toString();
}

From source file:suneido.compiler.AstNode.java

private String toString(int indent) {
    boolean multiline = multiline();
    String sep = multiline ? "\n" : " ";
    int childIndent = multiline ? indent + 3 : 0;

    StringBuilder sb = new StringBuilder();
    sb.append(Strings.repeat(" ", indent));
    sb.append('(').append(token);
    if (value != null)
        sb.append('=').append(token == Token.VALUE ? Ops.display(value) : value);
    if (children != null)
        for (AstNode x : children)
            sb.append(sep)/*from   w  w  w .  j ava  2  s.  co m*/
                    .append(x == null ? Strings.repeat(" ", childIndent) + "null" : x.toString(childIndent));
    sb.append(')');
    return sb.toString();
}

From source file:com.google.cloud.tools.gradle.appengine.core.ShowConfigurationTask.java

private static String spaces(int depth) {
    return Strings.repeat(" ", depth * 2);
}

From source file:org.onosproject.cli.net.AllocationsCommand.java

private void printAllocation(DeviceId did, int level) {
    print("%s%s", Strings.repeat(" ", level), did);
    StreamSupport.stream(deviceService.getPorts(did).spliterator(), false).map(Port::number)
            .forEach(num -> printAllocation(did, num, level + 1));
}

From source file:org.shaf.shell.action.ActionContext.java

/**
 * Shows the output content with title./*  w  w w  .j  a  v a  2  s  .c o  m*/
 * 
 * @param title
 *            the title to show.
 * @param content
 *            the content to show.
 */
public void show(final String title, final boolean underscore, final Object content) {
    if (!Strings.isNullOrEmpty(title)) {
        /*
         * It the title is not null or empty, it should be printed to the
         * console before the returned content of executed command. The
         * title always separated with one "empty" line, and can be
         * underscored with '=' is according flag is set.
         */
        this.terminal.println("");
        this.terminal.println(title);

        if (underscore) {
            this.terminal.println(Strings.repeat("=", title.length()));
        }
    }

    /*
     * The return content can have s different type and as a result requires
     * its own visualization style. The next block of conditions try to
     * select an appropriate view for the returned content type and show its
     * data.
     */
    if (content instanceof ProgressContent) {
        new ProgressView(terminal).show((ProgressContent) content);
    } else if (content instanceof StructuredContent) {
        new StructuredView(terminal).show((StructuredContent) content);
    } else if (content instanceof UnstructuredContent) {
        new UnstructuredView(terminal).show((UnstructuredContent) content);
    } else if (ClassUtils.inherits(content, Configuration.class)) {
        new ConfigurationView(terminal).show((Configuration) content);
    } else if (ClassUtils.inherits(content, Map.class)) {
        new MapView(terminal).show((Map<?, ?>) content);
    } else if (ClassUtils.inherits(content, Collection.class)) {
        new CollectionView(terminal).show((Collection<?>) content);
    } else {
        this.terminal.print(content.toString());
    }
}

From source file:net.freifunk.autodeploy.ui.pi.peripherals.GroveSerialLCDDriverImpl.java

private String ensureLength(final String str, final int expectedLength) {
    final int actualLength = str.length();
    if (actualLength < expectedLength) {
        return str + Strings.repeat(" ", expectedLength - actualLength);
    }//from w w  w . j  a  v a  2  s.  co m
    if (actualLength > expectedLength) {
        return str.substring(0, expectedLength);
    }
    return str;
}