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:edu.mit.streamjit.util.bytecode.Module.java

public Klass getArrayKlass(Klass componentType, int dimensions) {
    checkNotNull(componentType);/*ww w  .  ja  v a  2 s.c  o m*/
    checkArgument(dimensions >= 1);
    if (componentType.getBackingClass() != null)
        return getKlass(Array.newInstance(componentType.getBackingClass(), new int[dimensions]).getClass());
    StringBuilder nameBuilder = new StringBuilder(Strings.repeat("[", dimensions));
    //Always a reference type; if not already an array, add L and ;.
    nameBuilder.append(componentType.isArray() ? componentType.getName() : "L" + componentType.getName() + ";");
    String name = nameBuilder.toString();
    Klass alreadyExists = getKlass(name);
    if (alreadyExists != null)
        return alreadyExists;
    return new Klass(componentType, dimensions, this);
}

From source file:com.github.ferstl.maven.pomenforcers.ErrorReport.java

private String formatTitle() {
    if (this.useLargeTitle) {
        String border = Strings.repeat("#", this.title.length() + 4);
        return LINE_JOINER.join("", border, "# " + this.title + " #", border, "");
    }/*ww  w . j av  a2s  .  c om*/
    return LINE_JOINER.join("" + this.title, Strings.repeat("=", this.title.length()), "");
}

From source file:org.robotframework.ide.eclipse.main.plugin.project.build.fix.CreateKeywordFixer.java

@Override
public Optional<ICompletionProposal> asContentProposal(final IMarker marker, final IDocument document,
        final RobotSuiteFile suiteModel) {
    if (keywordName == null) {
        return Optional.empty();
    }/*  w ww .j a v a2s.  co  m*/

    final String lineDelimiter = DocumentUtilities.getDelimiter(document);

    final boolean isTsvFile = suiteModel.getFileExtension().equals("tsv");
    final String separator = RedPlugin.getDefault().getPreferences().getSeparatorToUse(isTsvFile);

    final String toInsert;
    final int offset;
    final int cursorShift;

    final Optional<RobotKeywordsSection> section = suiteModel.findSection(RobotKeywordsSection.class);
    if (section.isPresent()) {
        try {
            toInsert = lineDelimiter + keywordName + lineDelimiter + separator + lineDelimiter;

            final int line = section.get().getHeaderLine();
            final IRegion lineInformation = document.getLineInformation(line - 1);
            offset = lineInformation.getOffset() + lineInformation.getLength();
            cursorShift = lineDelimiter.length();
        } catch (final BadLocationException e) {
            return Optional.empty();
        }

    } else {
        toInsert = Strings.repeat(lineDelimiter, 2) + "*** Keywords ***" + lineDelimiter + keywordName
                + lineDelimiter + separator;
        offset = document.getLength();
        cursorShift = 0;
    }

    final IRegion regionOfChange = new Region(offset, 0);
    final String info = Snippets.createSnippetInfo(document, regionOfChange, toInsert);
    final RedCompletionProposal proposal = RedCompletionBuilder.newProposal().willPut(toInsert)
            .byInsertingAt(regionOfChange.getOffset()).secondaryPopupShouldBeDisplayedUsingHtml(info)
            .thenCursorWillStopBeforeEnd(cursorShift).displayedLabelShouldBe(getLabel())
            .proposalsShouldHaveIcon(ImagesManager.getImage(RedImages.getUserKeywordImage())).create();
    return Optional.<ICompletionProposal>of(proposal);
}

From source file:com.chiorichan.util.ServerFunc.java

public static String hexDump(ByteBuf buf, int highlightIndex) {
    if (buf == null)
        return "Buffer: null!";

    if (buf.capacity() < 1)
        return "Buffer: 0B!";

    StringBuilder dump = new StringBuilder();

    final int startIndex = 0;
    final int endIndex = buf.capacity();
    final int length = endIndex - startIndex;
    final int fullRows = length >>> 4;
    final int remainder = length & 0xF;

    int highlightRow = -1;

    dump.append(NEWLINE + "         +-------------------------------------------------+" + NEWLINE
            + "         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |" + NEWLINE
            + "+--------+-------------------------------------------------+----------------+");

    if (highlightIndex > 0) {
        highlightRow = highlightIndex >>> 4;
        highlightIndex = highlightIndex - 16 * highlightRow - 1;

        dump.append(NEWLINE + "|        |" + Strings.repeat("   ", highlightIndex) + " $$"
                + Strings.repeat("   ", 15 - highlightIndex));
        dump.append(" |" + Strings.repeat(" ", highlightIndex) + "$" + Strings.repeat(" ", 15 - highlightIndex)
                + "|");
    }//from   ww  w  .j  a v a 2  s.  co m

    // Dump the rows which have 16 bytes.
    for (int row = 0; row < fullRows; row++) {
        int rowStartIndex = row << 4;

        // Per-row prefix.
        appendHexDumpRowPrefix(dump, row, rowStartIndex);

        // Hex dump
        int rowEndIndex = rowStartIndex + 16;
        for (int j = rowStartIndex; j < rowEndIndex; j++)
            dump.append(BYTE2HEX[buf.getUnsignedByte(j)]);
        dump.append(" |");

        // ASCII dump
        for (int j = rowStartIndex; j < rowEndIndex; j++)
            dump.append(BYTE2CHAR[buf.getUnsignedByte(j)]);
        dump.append('|');

        if (highlightIndex > 0 && highlightRow == row + 1)
            dump.append(" <--");
    }

    // Dump the last row which has less than 16 bytes.
    if (remainder != 0) {
        int rowStartIndex = fullRows << 4;
        appendHexDumpRowPrefix(dump, fullRows, rowStartIndex);

        // Hex dump
        int rowEndIndex = rowStartIndex + remainder;
        for (int j = rowStartIndex; j < rowEndIndex; j++)
            dump.append(BYTE2HEX[buf.getUnsignedByte(j)]);
        dump.append(HEXPADDING[remainder]);
        dump.append(" |");

        // Ascii dump
        for (int j = rowStartIndex; j < rowEndIndex; j++)
            dump.append(BYTE2CHAR[buf.getUnsignedByte(j)]);
        dump.append(BYTEPADDING[remainder]);
        dump.append('|');

        if (highlightIndex > 0 && highlightRow > fullRows + 1)
            dump.append(" <--");
    }

    dump.append(NEWLINE + "+--------+-------------------------------------------------+----------------+");

    return dump.toString();
}

From source file:org.dllearner.cli.DocumentationGenerator.java

public String getConfigDocumentationString() {
    String doc = "";
    doc += "This file contains an automatically generated files of all components and their config options.\n\n";

    Set<Class<?>> componentsDone = new HashSet<>();
    Class<?>[] nonComponentClasses = { CLI.class, GlobalDoc.class };

    // go through all types of components and write down their documentation
    List<Class> coreComps = Arrays.asList(AnnComponentManager.coreComponentClasses);
    Collections.reverse(coreComps);
    LinkedList<String> cc = new LinkedList<>();
    doc += "*************************\n" + "* Non-component classes *\n" + "*************************\n\n";
    for (Class<?> comp : nonComponentClasses) {
        if (componentsDone.contains(comp))
            continue;
        doc += getComponentConfigString(comp, Class.class);
        componentsDone.add(comp);// ww w. j  a va2  s  .  c  o  m
    }

    for (Class<?> cats : coreComps) {
        ComponentAnn ann = cats.getAnnotation(ComponentAnn.class);
        String name = cats.getSimpleName();
        if (ann != null) {
            name = ann.name();
        }
        StringBuilder sc = new StringBuilder();
        sc.append("\n" + Strings.repeat("*", name.length() + 4) + "\n" + "* " + name + " *\n"
                + Strings.repeat("*", name.length() + 4) + "\n\n");

        for (Class<? extends Component> comp : cm.getComponentsOfType(cats)) {
            if (componentsDone.contains(comp))
                continue;
            sc.append(getComponentConfigString(comp, cats));
            componentsDone.add(comp);
        }
        cc.addFirst(sc.toString());
    }
    doc += StringUtils.join(cc, "\n");
    for (Class<?> comp : cm.getComponents()) {
        StringBuilder sc = new StringBuilder();
        if (!componentsDone.contains(comp)) {
            if (componentsDone.contains(comp))
                continue;
            sc.append(getComponentConfigString(comp, Component.class));
            componentsDone.add(comp);
        }
        if (sc.length() != 0) {
            doc += "\n********************\n" + "* Other Components *\n" + "********************\n\n"
                    + sc.toString();
        }
    }

    return doc;
}

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

private String indentLineComments(List<String> lines, int column0) {
    lines = wrapLineComments(lines, column0);
    StringBuilder builder = new StringBuilder();
    builder.append(lines.get(0).trim());
    String indentString = Strings.repeat(" ", column0);
    for (int i = 1; i < lines.size(); ++i) {
        builder.append(lineSeparator).append(indentString).append(lines.get(i).trim());
    }//from w w w.j a  va2  s  .c  om
    return builder.toString();
}

From source file:org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes.java

private static void toStringTree(final StringBuilder builder, final NormalizedNode<?, ?> node,
        final int offset) {
    final String prefix = Strings.repeat(" ", offset);

    builder.append(prefix).append(toStringTree(node.getIdentifier()));
    if (node instanceof NormalizedNodeContainer<?, ?, ?>) {
        final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) node;

        builder.append(" {\n");
        for (NormalizedNode<?, ?> child : container.getValue()) {
            toStringTree(builder, child, offset + STRINGTREE_INDENT);
        }/*from w w  w .j  a  v  a2s .  c  o  m*/

        builder.append(prefix).append('}');
    } else {
        builder.append(' ').append(node.getValue());
    }
    builder.append('\n');
}

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

@Override
void sanitizedDump(StringBuilder out) {
    out.append("CONTACT:");
    out.append(Strings.repeat("$TEXT,", tokens.size()));
    if (out.charAt(out.length() - 1) == ',') {
        out.deleteCharAt(out.length() - 1);
    }//from   www. j  a v  a2s .c  o m
}

From source file:com.google.caliper.report.console.ConsoleReport.java

/**
 * Returns a string containing a bar of proportional width to the specified
 * value.//www .j ava 2  s  . com
 *
 * @param graphLength length of the textual graph element
 * @return textual graph representation
 */
private String barGraph(int graphLength) {
    graphLength = Math.max(1, graphLength);
    graphLength = Math.min(BAR_GRAPH_WIDTH, graphLength);
    return Strings.repeat("=", graphLength);
}

From source file:eu.interedition.collatex.medite.SuffixTree.java

@Override
public String toString() {
    final StringBuilder sb = new StringBuilder();
    final Deque<Node> nodes = new ArrayDeque<Node>(Collections.singleton(root));
    while (!nodes.isEmpty()) {
        final Node node = nodes.remove();
        sb.append(Strings.repeat("\t", node.depth())).append(node).append("\n");
        for (Node child : node.children) {
            nodes.addFirst(child);//  w  w w.  j av a2s.  com
        }
    }
    return sb.toString();
}