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.eclipse.elk.layered.JsonDebugUtil.java

/**
 * Writes the given edges as JSON formatted string to the given writer.
 * //from   www.  j a va  2 s .  c om
 * @param writer
 *            the writer to write to.
 * @param edges
 *            the edges to write.
 * @param indentation
 *            the indentation level to use.
 * @param offset
 *            the combined offset of the containing LGraph.
 * @throws IOException
 *             if anything goes wrong with the writer.
 */
private static void writeEdges(final Writer writer, final List<LEdge> edges, final int indentation,
        final KVector offset) throws IOException {

    String indent0 = Strings.repeat(INDENT, indentation);
    String indent1 = Strings.repeat(INDENT, indentation + 1);
    String indent2 = Strings.repeat(INDENT, indentation + 2);
    writer.write(indent0 + "\"edges\": [");
    Iterator<LEdge> edgesIterator = edges.iterator();
    while (edgesIterator.hasNext()) {
        LEdge edge = edgesIterator.next();
        final KVector source = new KVector(edge.getSource().getAbsoluteAnchor()).add(offset);
        final KVector target = new KVector(edge.getTarget().getAbsoluteAnchor()).add(offset);
        if (edge.getProperty(InternalProperties.TARGET_OFFSET) != null) {
            target.add(edge.getProperty(InternalProperties.TARGET_OFFSET));
        }
        writer.write("\n" + indent1 + "{\n" + indent2 + "\"id\": \"e" + edge.hashCode() + "\",\n" + indent2
                + "\"source\": \"n" + edge.getSource().getNode().hashCode() + "\",\n" + indent2
                + "\"target\": \"n" + edge.getTarget().getNode().hashCode() + "\",\n" + indent2
                + "\"sourcePort\": \"p" + edge.getSource().hashCode() + "\",\n" + indent2
                + "\"targetPort\": \"p" + edge.getTarget().hashCode() + "\",\n" + indent2
                + "\"sourcePoint\": { \"x\": " + source.x + ", \"y\": " + source.y + " },\n" + indent2
                + "\"targetPoint\": { \"x\": " + target.x + ", \"y\": " + target.y + " },\n");
        writeBendPoints(writer, edge.getBendPoints(), indentation + 2, offset);
        writer.write(",\n");
        writeProperties(writer, edge.getAllProperties(), indentation + 2);
        writer.write("\n" + indent1 + "}");
        if (edgesIterator.hasNext()) {
            writer.write(",");
        }
    }
    writer.write("\n" + indent0 + "]");
}

From source file:com.google.api.server.spi.tools.EndpointsToolAction.java

@VisibleForTesting
static List<String> wrap(String source, int maxWidth, int indent) {
    Iterable<String> words = Splitter.on(" ").split(source);
    ImmutableList.Builder<String> wrappedLines = ImmutableList.builder();
    StringBuffer line = new StringBuffer(Strings.repeat(" ", indent));
    int lineLength = indent;
    for (String word : words) {
        if ((lineLength + word.length()) >= maxWidth) {
            wrappedLines.add(line.toString());
            line = new StringBuffer(Strings.repeat(" ", indent));
            lineLength = indent;/*from  w  w w.  j a v  a2 s  .c om*/
        }
        // If lineLength == maxWidth, then we'll definitely wrap the next word. No trailing space
        // is required.
        if (lineLength > indent && lineLength < maxWidth) {
            line.append(" ");
            lineLength++;
        }
        line.append(word);
        lineLength += (word.length());
    }
    wrappedLines.add(line.toString());
    return wrappedLines.build();
}

From source file:org.fabrician.enabler.DockerContainer.java

private void injectDockerHelperProcesses() throws Exception {
    getEngineLogger()//from   ww  w . j av  a 2s .  c om
            .info(Strings.repeat("-", 10) + "injecting post-activation helper processes into docker container ["
                    + dockerContainerId + "]" + Strings.repeat("-", 10));
    boolean inject = resolveToBoolean(EXEC_CMD_ENABLED_VAR);
    if (inject) {
        File cmdFile = resolveToFile(EXEC_CMD_FILE_VAR);
        Validate.isTrue(cmdFile.exists(), "The command file for 'docker exec' use does not exist at path ["
                + cmdFile.getCanonicalPath() + "]");
        int delay = resolveToInteger(EXEC_CMD_DELAY_VAR);
        ExecCmdProcessInjector.exec(this, cmdFile.toURI().toURL(), delay);
    } else {
        getEngineLogger().info("Skipping 'docker exec' since " + EXEC_CMD_ENABLED_VAR + " is disabled.");
    }
}

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

/**
 * Writes the given bendpoints as JSON formatted string to the given
 * ConsoleWriter.//from   www.j a v  a 2  s. c om
 *
 * @param ConsoleWriter
 *            the ConsoleWriter to write to.
 * @param bendPoints
 *            the bendpoints to write.
 * @param indentation
 *            the indentation level to use.
 * @throws IOException
 *             if anything goes wrong with the ConsoleWriter.
 */
private static void writeBendPoints(final ConsoleWriter ConsoleWriter, final KVectorChain bendPoints,
        final int indentation) throws IOException {

    final String indent0 = Strings.repeat(INDENT, indentation);
    final String indent1 = Strings.repeat(INDENT, indentation + 1);
    ConsoleWriter.write(indent0 + "\"bendPoints\": [");
    final Iterator<KVector> pointsIterator = bendPoints.iterator();
    while (pointsIterator.hasNext()) {
        final KVector point = pointsIterator.next();
        ConsoleWriter.write("\n" + indent1 + "{ \"x\": " + point.x + ", \"y\": " + point.y + "}");
        if (pointsIterator.hasNext()) {
            ConsoleWriter.write(",");
        }
    }
    ConsoleWriter.write("\n" + indent0 + "]");
}

From source file:org.eclipse.xtext.generator.trace.AbstractTraceRegionToString.java

protected String title(final SourceRelativeURI uri, final int width) {
    String _xifexpression = null;
    if ((uri == null)) {
        _xifexpression = this.getLocalTitle();
    } else {/*from w ww .  j a va2s . com*/
        _xifexpression = this.getRemoteTitle(uri);
    }
    String _plus = (" " + _xifexpression);
    final String s = (_plus + " ");
    int _length = s.length();
    int _minus = (width - _length);
    int _divide = (_minus / 2);
    final String left = Strings.repeat("-", _divide);
    int _length_1 = s.length();
    int _length_2 = left.length();
    int _plus_1 = (_length_1 + _length_2);
    int _minus_1 = (width - _plus_1);
    final String right = Strings.repeat("-", _minus_1);
    return ((left + s) + right);
}

From source file:net.sourceforge.ganttproject.document.webdav.GanttURLChooser.java

private Component createUsernamePasswordPanel() {
    JPanel grid = new JPanel(new GridLayout(3, 2));
    grid.add(new JLabel(language.getText("userName")));
    final JLabel username = new JLabel(myUsername.getValue());
    myUsername.addChangeValueListener(new ChangeValueListener() {
        @Override/*  w  ww.jav  a2s  .com*/
        public void changeValue(ChangeValueEvent event) {
            username.setText(myUsername.getValue() == null ? "" : myUsername.getValue());
        }
    });
    grid.add(username);
    grid.add(new JLabel(language.getText("password")));
    myPasswordLabel = new JLabel(
            myPassword.getValue() == null ? "" : Strings.repeat("*", myPassword.getValue().length()));
    myPassword.addChangeValueListener(new ChangeValueListener() {
        @Override
        public void changeValue(ChangeValueEvent event) {
            UIUtil.clearErrorLabel(myPasswordLabel);
            myPasswordLabel.setText(
                    myPassword.getValue() == null ? "" : Strings.repeat("*", myPassword.getValue().length()));
        }
    });
    grid.add(myPasswordLabel);
    grid.add(new JXHyperlink(new GPAction("webdav.configure") {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            WebDavOptionPageProvider optionPage = new WebDavOptionPageProvider();
            optionPage.init(myProject, myUiFacade);
            myUiFacade.createDialog(optionPage.buildPageComponent(), new Action[] { CancelAction.CLOSE }, "")
                    .show();
            updateUsernameAndPassword();
            myReloadAction.actionPerformed(null);
        }
    }));
    UIUtil.walkComponentTree(grid, new Predicate<JComponent>() {
        @Override
        public boolean apply(JComponent input) {
            input.setFont(input.getFont().deriveFont(input.getFont().getSize() * 0.82f));
            return true;
        }
    });

    Box result = Box.createHorizontalBox();
    result.add(grid);
    result.add(Box.createHorizontalGlue());
    return grid;
}

From source file:com.google.api.explorer.client.history.JsonPrettifier.java

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

From source file:com.cloudbees.clickstack.util.Files2.java

private static void dump(@Nonnull Path path, int depth) throws RuntimeIOException {
    try {//from  w  ww  .  j  a v a 2 s  .co  m
        depth++;
        String icon = Files.isDirectory(path) ? " + " : " |- ";
        System.out.println(Strings.repeat(" ", depth) + icon + path.getFileName() + "\t"
                + PosixFilePermissions.toString(Files.getPosixFilePermissions(path)));

        if (Files.isDirectory(path)) {
            DirectoryStream<Path> children = Files.newDirectoryStream(path);
            for (Path child : children) {
                dump(child, depth);
            }
        }
    } catch (IOException e) {
        throw new RuntimeIOException("Exception dumping " + path, e);
    }
}

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

/**
 * Writes the given ports as JSON formatted string to the given
 * ConsoleWriter.//from  w  ww .java 2s  .  co  m
 *
 * @param ConsoleWriter
 *            the ConsoleWriter to write to.
 * @param ports
 *            the ports to write.
 * @param indentation
 *            the indentation level to use.
 * @throws IOException
 *             if anything goes wrong with the ConsoleWriter.
 */
private static void writePorts(final ConsoleWriter ConsoleWriter, final List<LPort> ports,
        final int indentation) throws IOException {

    final String indent0 = Strings.repeat(INDENT, indentation);
    final String indent1 = Strings.repeat(INDENT, indentation + 1);
    final String indent2 = Strings.repeat(INDENT, indentation + 2);
    ConsoleWriter.write(indent0 + "\"ports\": [");
    final Iterator<LPort> portsIterator = ports.iterator();
    while (portsIterator.hasNext()) {
        final LPort port = portsIterator.next();
        ConsoleWriter.write("\n" + indent1 + "{\n" + indent2 + "\"id\": \"p" + port.hashCode() + "\",\n"
                + indent2 + "\"width\": " + port.getSize().x + ",\n" + indent2 + "\"height\": "
                + port.getSize().y + ",\n" + indent2 + "\"x\": " + port.getPosition().x + ",\n" + indent2
                + "\"y\": " + port.getPosition().y + ",\n");
        writeProperties(ConsoleWriter, port.getAllProperties(), indentation + 2);
        ConsoleWriter.write("\n" + indent1 + "}");
        if (portsIterator.hasNext()) {
            ConsoleWriter.write(",");
        }
    }
    ConsoleWriter.write("\n" + indent0 + "]");
}

From source file:org.eclipse.elk.layered.JsonDebugUtil.java

/**
 * Writes the given bendpoints as JSON formatted string to the given writer.
 * //from  ww  w.  ja va2 s  .co m
 * @param writer
 *            the writer to write to.
 * @param bendPoints
 *            the bendpoints to write.
 * @param indentation
 *            the indentation level to use.
 * @param offset
 *            the combined offset of the containing LGraph.
 * @throws IOException
 *             if anything goes wrong with the writer.
 */
private static void writeBendPoints(final Writer writer, final KVectorChain bendPoints, final int indentation,
        final KVector offset) throws IOException {

    String indent0 = Strings.repeat(INDENT, indentation);
    String indent1 = Strings.repeat(INDENT, indentation + 1);
    writer.write(indent0 + "\"bendPoints\": [");
    Iterator<KVector> pointsIterator = bendPoints.iterator();
    while (pointsIterator.hasNext()) {
        KVector point = new KVector(pointsIterator.next()).add(offset);
        writer.write("\n" + indent1 + "{ \"x\": " + point.x + ", \"y\": " + point.y + "}");
        if (pointsIterator.hasNext()) {
            writer.write(",");
        }
    }
    writer.write("\n" + indent0 + "]");
}