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:com.b2international.snowowl.server.console.UserSessionCommandProvider.java

public synchronized void showLocks(final CommandInterpreter interpreter) {

    final IDatastoreOperationLockManager lockManager = ApplicationContext.getInstance()
            .getService(IDatastoreOperationLockManager.class);
    final List<OperationLockInfo<DatastoreLockContext>> locks = ((DatastoreOperationLockManager) lockManager)
            .getLocks();/*from  www .  ja v a 2 s .  c  o m*/

    if (locks.isEmpty()) {
        interpreter.println("No locks are currently granted on this server.");
        return;
    }

    interpreter.println();
    interpreter
            .println(String.format(COLUMN_FORMAT, "Id", "Lvl", "Created on", "Locked area", "Owner context"));
    interpreter.println(Strings.repeat("-", 135));

    for (final OperationLockInfo<DatastoreLockContext> lockEntry : locks) {
        interpreter.println(String.format(COLUMN_FORMAT, lockEntry.getId(), lockEntry.getLevel(),
                Dates.formatByHostTimeZone(lockEntry.getCreationDate(), DateFormats.MEDIUM),
                StringUtils.truncate(StringUtils.capitalizeFirstLetter(lockEntry.getTarget().toString()), 50),
                StringUtils.truncate("Lock owner: " + lockEntry.getContext().getUserId(), 50)));

        interpreter.println(String.format(COLUMN_FORMAT, "", "", "", "", StringUtils
                .truncate(StringUtils.capitalizeFirstLetter(lockEntry.getContext().getDescription()), 50)));

        interpreter.println(Strings.repeat("-", 135));
    }

}

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

private void printStageTree(StageStats stage, String indent, AtomicInteger stageNumberCounter) {
    Duration elapsedTime = nanosSince(start);

    // STAGE  S    ROWS  ROWS/s  BYTES  BYTES/s  QUEUED    RUN   DONE
    // 0......Q     26M   9077M  9993G    9077M   9077M  9077M  9077M
    //   2....R     17K    627M   673M     627M    627M   627M   627M
    //     3..C     999    627M   673M     627M    627M   627M   627M
    //   4....R     26M    627M   673T     627M    627M   627M   627M
    //     5..F     29T    627M   673M     627M    627M   627M   627M

    String id = String.valueOf(stageNumberCounter.getAndIncrement());
    String name = indent + id;/*from  w  w  w . j a  va  2 s.  c  o m*/
    name += Strings.repeat(".", max(0, 10 - name.length()));

    String bytesPerSecond;
    String rowsPerSecond;
    if (stage.isDone()) {
        bytesPerSecond = formatDataRate(new DataSize(0, BYTE), new Duration(0, SECONDS), false);
        rowsPerSecond = formatCountRate(0, new Duration(0, SECONDS), false);
    } else {
        bytesPerSecond = formatDataRate(bytes(stage.getProcessedBytes()), elapsedTime, false);
        rowsPerSecond = formatCountRate(stage.getProcessedRows(), elapsedTime, false);
    }

    String stageSummary = String.format("%10s%1s  %5s  %6s  %5s  %7s  %6s  %5s  %5s", name,
            stageStateCharacter(stage.getState()),

            formatCount(stage.getProcessedRows()), rowsPerSecond,

            formatDataSize(bytes(stage.getProcessedBytes()), false), bytesPerSecond,

            stage.getQueuedSplits(), stage.getRunningSplits(), stage.getCompletedSplits());
    reprintLine(stageSummary);

    for (StageStats subStage : stage.getSubStages()) {
        printStageTree(subStage, indent + "  ", stageNumberCounter);
    }
}

From source file:de.cau.cs.kieler.klay.layered.JsonDebugUtil.java

/**
 * Writes the nodes edges as JSON formatted string to the given
 * ConsoleWriter./*  w ww  . j av  a 2s. c  o m*/
 *
 * @param ConsoleWriter
 *            the ConsoleWriter to write to.
 * @param nodes
 *            the nodes to write.
 * @param indentation
 *            the indentation level to use.
 * @param layerNumber
 *            the layer number. {@code -1} for layerless nodes.
 * @throws IOException
 *             if anything goes wrong with the ConsoleWriter.
 */
private static void writeNodes(final ConsoleWriter ConsoleWriter, final List<LNode> nodes,
        final int indentation, final int layerNumber) throws IOException {

    final String indent0 = Strings.repeat(INDENT, indentation);
    final String indent1 = Strings.repeat(INDENT, indentation + 1);
    int nodeNumber = -1;
    final Iterator<LNode> nodesIterator = nodes.iterator();
    while (nodesIterator.hasNext()) {
        nodeNumber++;
        final LNode node = nodesIterator.next();
        ConsoleWriter.write("\n" + indent0 + "{\n" + indent1 + "\"id\": \"n" + node.hashCode() + "\",\n"
                + indent1 + "\"labels\": [ { \"text\": \"" + getNodeName(node, layerNumber, nodeNumber)
                + "\" } ],\n" + indent1 + "\"width\": " + node.getSize().x + ",\n" + indent1 + "\"height\": "
                + node.getSize().y + ",\n" + indent1 + "\"x\": " + node.getPosition().x + ",\n" + indent1
                + "\"y\": " + node.getPosition().y + ",\n");
        writeProperties(ConsoleWriter, node.getAllProperties(), indentation + 1);
        ConsoleWriter.write(",\n");
        writePorts(ConsoleWriter, node.getPorts(), indentation + 1);
        ConsoleWriter.write("\n" + indent0 + "}");
        if (nodesIterator.hasNext()) {
            ConsoleWriter.write(",");
        }
    }
}

From source file:com.google.caliper.runner.ConsoleResultProcessor.java

/**
 * Returns a string containing a bar of proportional width to the specified
 * value./*from  w  w w.ja v a 2 s  .c o  m*/
 */
private String barGraph(double value) {
    if (this.minValue >= 0) {
        int graphLength = floor(value / maxValue * barGraphWidth);
        graphLength = Math.max(1, graphLength);
        graphLength = Math.min(barGraphWidth, graphLength);
        return Strings.repeat("=", graphLength);
    } else {
        // we want:    ========0
        //                =====0
        //                     0========
        int zeroIndex = floor((-minValue) * barGraphWidth / (maxValue - minValue));
        if (value < 0) {
            int barLength = ceil(value / minValue * zeroIndex);
            return Strings.repeat(" ", zeroIndex - barLength) + Strings.repeat("=", barLength) + "0";
        } else {
            int barLength = floor(value / maxValue * (barGraphWidth - zeroIndex));
            return Strings.repeat(" ", zeroIndex) + "0" + Strings.repeat("=", barLength);
        }
    }
}

From source file:com.facebook.buck.cli.Main.java

/** Prints the usage message to standard error. */
@VisibleForTesting/*from   w  w  w.j  av  a 2  s  . co  m*/
int usage() {
    stdErr.println("buck build tool");

    stdErr.println("usage:");
    stdErr.println("  buck [options]");
    stdErr.println("  buck command --help");
    stdErr.println("  buck command [command-options]");
    stdErr.println("available commands:");

    int lengthOfLongestCommand = 0;
    for (Command command : Command.values()) {
        String name = command.name();
        if (name.length() > lengthOfLongestCommand) {
            lengthOfLongestCommand = name.length();
        }
    }

    for (Command command : Command.values()) {
        String name = command.name().toLowerCase();
        stdErr.printf("  %s%s  %s\n", name, Strings.repeat(" ", lengthOfLongestCommand - name.length()),
                command.getShortDescription());
    }

    stdErr.println("options:");
    new GenericBuckOptions(stdOut, stdErr).printUsage();
    return 1;
}

From source file:parquet.tools.util.PrettyPrintWriter.java

public void rule(char c) {
    if (tabs.length() >= consoleWidth)
        return;/*from ww  w. j a  v  a  2 s  . co  m*/

    int width = consoleWidth;
    if (width == Integer.MAX_VALUE) {
        width = 100;
    }

    println(Strings.repeat(String.valueOf(c), width - tabs.length()));
}

From source file:eu.itesla_project.modules.topo.PossibleTopology.java

public void print(PrintStream out, int indent) {
    out.print(Strings.repeat(" ", indent) + "possibleTopo id=" + metaSubstation.getId());
    if (num != null) {
        out.print(" num=" + num);
    }/*from  w  ww .j  av a  2s .  c  o  m*/
    if (topoHash != null) {
        out.print(" topoHash=" + topoHash);
    }
    out.println(" proba=" + probability);
    metaSubstation.print(out, indent + 4);
}

From source file:org.skife.jdbi.v2.ExpandedStmtRewriter.java

String parseString(final String sql, final ParsedStatement stmt, final Binding params)
        throws IllegalArgumentException {
    StringBuilder b = new StringBuilder();
    ColonStatementLexer lexer = new ColonStatementLexer(new ANTLRStringStream(sql));
    Token t = lexer.nextToken();/*from  www . j av a  2 s .c  o  m*/
    int pos = 0;
    while (t.getType() != ColonStatementLexer.EOF) {
        switch (t.getType()) {
        case LITERAL:
            b.append(t.getText());
            break;
        case NAMED_PARAM:
            String pname = t.getText().substring(1, t.getText().length());
            stmt.addNamedParamAt(pname);
            Argument arg = params.forName(pname);
            if (arg instanceof IterableArgument) {
                // expand iterable
                int size = ((IterableArgument) arg).size();
                b.append(Strings.repeat("?, ", size));
                b.setLength(b.length() - 2);
            } else {
                b.append("?");
            }
            break;
        case QUOTED_TEXT:
            b.append(t.getText());
            break;
        case DOUBLE_QUOTED_TEXT:
            b.append(t.getText());
            break;
        case POSITIONAL_PARAM:
            Argument posarg = params.forPosition(pos);
            if (posarg instanceof IterableArgument) {
                // expand iterable
                int size = ((IterableArgument) posarg).size();
                b.append(Strings.repeat("?, ", size));
                b.setLength(b.length() - 2);
                pos += size;
            } else {
                b.append("?");
                pos += 1;
            }
            stmt.addPositionalParamAt();
            break;
        case ESCAPED_TEXT:
            b.append(t.getText().substring(1));
            break;
        default:
            break;
        }
        t = lexer.nextToken();
    }
    return b.toString();
}

From source file:com.aitorvs.autoparcel.internal.codegen.AutoParcelProcessor.java

private String generatedSubclassName(TypeElement type, int depth) {
    return generatedClassName(type, Strings.repeat("$", depth) + "AutoParcel_");
}

From source file:io.prestosql.cli.StatusPrinter.java

private void printStageTree(StageStats stage, String indent, AtomicInteger stageNumberCounter) {
    Duration elapsedTime = nanosSince(start);

    // STAGE  S    ROWS  ROWS/s  BYTES  BYTES/s  QUEUED    RUN   DONE
    // 0......Q     26M   9077M  9993G    9077M   9077M  9077M  9077M
    //   2....R     17K    627M   673M     627M    627M   627M   627M
    //     3..C     999    627M   673M     627M    627M   627M   627M
    //   4....R     26M    627M   673T     627M    627M   627M   627M
    //     5..F     29T    627M   673M     627M    627M   627M   627M

    String id = String.valueOf(stageNumberCounter.getAndIncrement());
    String name = indent + id;/* w  ww .ja va2s  .co m*/
    name += Strings.repeat(".", max(0, 10 - name.length()));

    String bytesPerSecond;
    String rowsPerSecond;
    if (stage.isDone()) {
        bytesPerSecond = formatDataRate(new DataSize(0, BYTE), new Duration(0, SECONDS), false);
        rowsPerSecond = formatCountRate(0, new Duration(0, SECONDS), false);
    } else {
        bytesPerSecond = formatDataRate(bytes(stage.getProcessedBytes()), elapsedTime, false);
        rowsPerSecond = formatCountRate(stage.getProcessedRows(), elapsedTime, false);
    }

    String stageSummary = format("%10s%1s  %5s  %6s  %5s  %7s  %6s  %5s  %5s", name,
            stageStateCharacter(stage.getState()),

            formatCount(stage.getProcessedRows()), rowsPerSecond,

            formatDataSize(bytes(stage.getProcessedBytes()), false), bytesPerSecond,

            stage.getQueuedSplits(), stage.getRunningSplits(), stage.getCompletedSplits());
    reprintLine(stageSummary);

    for (StageStats subStage : stage.getSubStages()) {
        printStageTree(subStage, indent + "  ", stageNumberCounter);
    }
}