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 a debug graph for the given list of hypernodes.
 * /*  w  ww .j a v  a  2  s  .co m*/
 * @param layeredGraph
 *            the layered graph
 * @param layerIndex
 *            the currently processed layer's index
 * @param hypernodes
 *            a list of hypernodes
 * @param debugPrefix
 *            prefix of debug output files
 * @param label
 *            a label to append to the output files
 */
public static void writeDebugGraph(final LGraph layeredGraph, final int layerIndex,
        final List<HyperNode> hypernodes, final String debugPrefix, final String label) {

    try {
        Writer writer = createWriter(layeredGraph, layerIndex, debugPrefix, label);
        beginGraph(writer, layeredGraph);
        beginChildNodeList(writer, 1);

        String indent1 = Strings.repeat(INDENT, 2);
        String indent2 = Strings.repeat(INDENT, 3); // SUPPRESS CHECKSTYLE MagicNumber
        int edgeId = 0;

        Iterator<HyperNode> hypernodeIterator = hypernodes.iterator();

        StringBuffer edges = new StringBuffer();

        while (hypernodeIterator.hasNext()) {
            HyperNode hypernode = hypernodeIterator.next();
            writer.write("\n" + indent1 + "{\n" + indent2 + "\"id\": \"n" + System.identityHashCode(hypernode)
                    + "\",\n" + indent2 + "\"labels\": [ { \"text\": \"" + hypernode.toString() + "\" } ],\n"
                    + indent2 + "\"width\": 50,\n" + indent2 + "\"height\": 25\n" + indent1 + "}");
            if (hypernodeIterator.hasNext()) {
                writer.write(",");
            }

            Iterator<Dependency> dependencyIterator = hypernode.getOutgoing().iterator();

            while (dependencyIterator.hasNext()) {
                Dependency dependency = dependencyIterator.next();
                edges.append("\n" + indent1 + "{\n" + indent2 + "\"id\": \"e" + edgeId++ + "\",\n" + indent2
                        + "\"source\": \"n" + System.identityHashCode(hypernode) + "\",\n" + indent2
                        + "\"target\": \"n" + System.identityHashCode(dependency.getTarget()) + "\"\n" + indent1
                        + "},");
            }
        }

        endChildNodeList(writer, 1);

        if (edges.length() > 0) {
            edges.deleteCharAt(edges.length() - 1);
        }
        writer.write(INDENT + "\"edges\": [" + edges + "\n" + INDENT + "]");

        endGraph(writer);
        writer.close();
    } catch (Exception exception) {
        exception.printStackTrace();
    }
}

From source file:com.zimbra.cs.index.query.TextQuery.java

@Override
public void sanitizedDump(StringBuilder out) {
    out.append(field);/* ww w.  j  av  a  2  s  .co m*/
    out.append(':');
    out.append(Strings.repeat("$TEXT,", tokens.size()));
    if (out.charAt(out.length() - 1) == ',') {
        out.deleteCharAt(out.length() - 1);
    }
    if (quick || text.endsWith("*")) {
        out.append("[*]");
    }
}

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

private static void showDetails(PrettyPrintWriter out, GroupType type, int depth, MessageType container,
        List<String> cpath) {
    String name = Strings.repeat(".", depth) + type.getName();
    Repetition rep = type.getRepetition();
    int fcount = type.getFieldCount();
    out.format("%s: %s F:%d%n", name, rep, fcount);

    cpath.add(type.getName());/* w  ww  .  j  a  v  a  2s .c o m*/
    for (Type ftype : type.getFields()) {
        showDetails(out, ftype, depth + 1, container, cpath);
    }
    cpath.remove(cpath.size() - 1);
}

From source file:org.openhab.binding.max.internal.command.UdpCubeCommand.java

private void receiveUdpCommandResponse() {

    DatagramSocket bcReceipt = null;

    try {//from w  w w.j a va 2  s.  c  om
        commandRunning = true;
        bcReceipt = new DatagramSocket(23272);
        bcReceipt.setReuseAddress(true);
        bcReceipt.setSoTimeout(5000);

        while (commandRunning) {
            // Wait for a response
            byte[] recvBuf = new byte[1500];
            DatagramPacket receivePacket = new DatagramPacket(recvBuf, recvBuf.length);
            bcReceipt.receive(receivePacket);

            // We have a response
            String message = new String(receivePacket.getData(), receivePacket.getOffset(),
                    receivePacket.getLength());
            logger.trace("Broadcast response from {} : {} '{}'", receivePacket.getAddress(), message.length(),
                    message);

            // Check if the message is correct
            if (message.startsWith("eQ3Max") && !message.equals(MAXCUBE_COMMAND_STRING)) {

                commandResponse.put("maxCubeIP", receivePacket.getAddress().getHostAddress().toString());
                commandResponse.put("maxCubeState", message.substring(0, 8));
                commandResponse.put("serialNumber", message.substring(8, 18));
                commandResponse.put("msgValidid", message.substring(18, 19));
                String requestType = message.substring(19, 20);
                commandResponse.put("requestType", requestType);

                if (requestType.equals("I")) {
                    commandResponse.put("rfAddress",
                            Utils.getHex(message.substring(21, 24).getBytes()).replace(" ", "").toLowerCase());
                    commandResponse.put("firmwareVersion",
                            Utils.getHex(message.substring(24, 26).getBytes()).replace(" ", "."));
                } else {
                    // TODO: Further parsing of the other message types
                    commandResponse.put("messageResponse", Utils.getHex(message.substring(24).getBytes()));
                }

                commandRunning = false;
                logger.debug("MAX! UDP response");
                for (String key : commandResponse.keySet()) {
                    logger.debug("{}:{}{}", key, Strings.repeat(" ", 25 - key.length()),
                            commandResponse.get(key));
                }
            }
        }
    } catch (SocketTimeoutException e) {
        logger.trace("No further response");
        commandRunning = false;
    } catch (IOException e) {
        logger.debug("IO error during MAX! Cube response: {}", e.getMessage());
        commandRunning = false;
    } finally {
        // Close the port!
        try {
            if (bcReceipt != null) {
                bcReceipt.close();
            }
        } catch (Exception e) {
            logger.debug("{}", e.getMessage());
        }
    }
}

From source file:org.spongepowered.common.service.pagination.PlayerPaginationCalculator.java

@Override
public Text center(Player source, Text text, String padding) {
    int length = getLength(source, text);
    if (length >= LINE_WIDTH) {
        return text;
    }/*from  w w  w.  j a v a2 s .  c om*/
    int paddingLength = getLength(source, Texts.builder(padding).style(text.getStyle()).build());
    double paddingNecessary = LINE_WIDTH - length;
    TextBuilder build = Texts.builder();
    if (length == 0) {
        build.append(Texts.of(Strings.repeat(padding, (int) Math.floor((double) LINE_WIDTH / paddingLength))));
    } else {
        paddingNecessary -= getWidth(' ', text.getStyle().contains(TextStyles.BOLD)) * 2;
        double paddingCount = Math.floor(paddingNecessary / paddingLength);
        int beforePadding = (int) Math.floor(paddingCount / 2.0);
        int afterPadding = (int) Math.ceil(paddingCount / 2.0);
        if (beforePadding > 0) {
            if (beforePadding > 1) {
                build.append(Texts.of(Strings.repeat(padding, beforePadding)));
            }
            build.append(CommandMessageFormatting.SPACE_TEXT);
        }
        build.append(text);
        if (afterPadding > 0) {
            build.append(CommandMessageFormatting.SPACE_TEXT);
            if (afterPadding > 1) {
                build.append(Texts.of(Strings.repeat(padding, afterPadding)));
            }
        }
    }

    build.color(text.getColor()).style(text.getStyle());
    return build.build();
}

From source file:es.usc.citius.composit.cli.CompositCli.java

public void separator(int size) {
    println(Strings.repeat("=", size));
}

From source file:net.minecraftforge.gradle.patcher.TaskGenSubprojects.java

private static void lines(StringBuilder out, int indentLevel, CharSequence... lines) {
    String indent = Strings.repeat(INDENT, indentLevel);

    for (CharSequence line : lines) {
        out.append(indent).append(line).append(NEWLINE);
    }/*  w  w  w  .j  a v a2 s .c o  m*/
}

From source file:me.lucko.luckperms.common.treeview.TreeView.java

private List<Map.Entry<String, String>> asTreeList() {
    String prefix = rootPosition.equals(".") ? "" : (rootPosition + ".");
    List<Map.Entry<String, String>> ret = new ArrayList<>();

    for (Map.Entry<Integer, String> s : view.getNodeEndings()) {
        if (s.getKey() > maxLevels) {
            continue;
        }/*w ww.  j av  a2 s .co  m*/

        String treeStructure = Strings.repeat("  ", s.getKey()) + " ";
        String node = prefix + s.getValue();

        ret.add(Maps.immutableEntry(treeStructure, node));
    }

    return ret;
}

From source file:com.google.googlejavaformat.java.JavaCommentsHelper.java

private String indentJavadoc(List<String> lines, int column0) {
    StringBuilder builder = new StringBuilder();
    builder.append(lines.get(0).trim());
    int indent = column0 + 1;
    String indentString = Strings.repeat(" ", indent);
    for (int i = 1; i < lines.size(); ++i) {
        builder.append(lineSeparator).append(indentString);
        String line = lines.get(i).trim();
        if (!line.startsWith("*")) {
            builder.append("* ");
        }//www  .j  av a2  s.co  m
        builder.append(line);
    }
    return builder.toString();
}

From source file:org.apache.parquet.tools.command.MetadataUtils.java

private static void showDetails(PrettyPrintWriter out, PrimitiveType type, int depth, MessageType container,
        List<String> cpath, boolean showOriginalTypes) {
    String name = Strings.repeat(".", depth) + type.getName();
    Repetition rep = type.getRepetition();
    PrimitiveTypeName ptype = type.getPrimitiveTypeName();

    out.format("%s: %s %s", name, rep, ptype);
    if (showOriginalTypes) {
        OriginalType otype;/*from  w w w  .  ja  va2s  . co m*/
        try {
            otype = type.getOriginalType();
        } catch (Exception e) {
            otype = null;
        }
        if (otype != null)
            out.format(" O:%s", otype);
    } else {
        LogicalTypeAnnotation ltype = type.getLogicalTypeAnnotation();
        if (ltype != null)
            out.format(" L:%s", ltype);
    }

    if (container != null) {
        cpath.add(type.getName());
        String[] paths = cpath.toArray(new String[cpath.size()]);
        cpath.remove(cpath.size() - 1);

        ColumnDescriptor desc = container.getColumnDescription(paths);

        int defl = desc.getMaxDefinitionLevel();
        int repl = desc.getMaxRepetitionLevel();
        out.format(" R:%d D:%d", repl, defl);
    }
    out.println();
}