Example usage for org.apache.commons.lang3 StringUtils repeat

List of usage examples for org.apache.commons.lang3 StringUtils repeat

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils repeat.

Prototype

public static String repeat(final char ch, final int repeat) 

Source Link

Document

<p>Returns padding using the specified delimiter repeated to a given length.</p> <pre> StringUtils.repeat('e', 0) = "" StringUtils.repeat('e', 3) = "eee" StringUtils.repeat('e', -2) = "" </pre> <p>Note: this method doesn't not support padding with <a href="http://www.unicode.org/glossary/#supplementary_character">Unicode Supplementary Characters</a> as they require a pair of char s to be represented.

Usage

From source file:io.github.swagger2markup.markup.builder.internal.markdown.MarkdownBuilder.java

@Override
public MarkupDocBuilder tableWithColumnSpecs(List<MarkupTableColumn> columnSpecs, List<List<String>> cells) {
    Validate.notEmpty(cells, "cells must not be null");
    newLine();//www  .jav  a2 s  . c o  m
    if (columnSpecs != null && !columnSpecs.isEmpty()) {
        Collection<String> headerList = columnSpecs.stream()
                .map(header -> formatTableCell(defaultString(header.header))).collect(Collectors.toList());
        documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER)
                .append(join(headerList, Markdown.TABLE_COLUMN_DELIMITER.toString()))
                .append(Markdown.TABLE_COLUMN_DELIMITER).append(newLine);

        documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER);
        columnSpecs.forEach(col -> {
            documentBuilder.append(StringUtils.repeat(Markdown.TABLE_ROW.toString(), 3));
            documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER);
        });
        documentBuilder.append(newLine);
    }

    for (List<String> row : cells) {
        Collection<String> cellList = row.stream().map(cell -> formatTableCell(defaultString(cell)))
                .collect(Collectors.toList());
        documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER)
                .append(join(cellList, Markdown.TABLE_COLUMN_DELIMITER.toString()))
                .append(Markdown.TABLE_COLUMN_DELIMITER).append(newLine);
    }
    newLine();

    return this;
}

From source file:de.vandermeer.asciilist.AbstractAsciiList.java

/**
 * Wraps a rendered list item for the width given in the list.
 * @param renderedItem the rendered item to wrap
 * @return a string with the wrapped item (lines separated by "\n")
 *//*from   w  w w.  j a va  2 s  . co m*/
protected String wrapItem(String renderedItem) {
    String ret = "";
    if (renderedItem.contains(IMPLICIT_NEWLINE)) {
        //for descriptions with multi lines
        String[] split = StringUtils.split(renderedItem, IMPLICIT_NEWLINE);
        String rest = StringUtils.repeat(" ", this.maxItemIndent) + split[1];
        if (this.width > 0 && rest.length() < this.width) {
            return split[0] + "\n" + rest;
        } else if (this.width < 0) {
            return split[0] + "\n" + rest;
        }
    }

    if (this.width > 0 && renderedItem.length() > this.width) {
        String[] wrap = StringUtils.split(WordUtils.wrap(renderedItem,
                (this.width - this.preLabelIndent - this.preLabelStr.length()), IMPLICIT_NEWLINE, true),
                IMPLICIT_NEWLINE);
        ret += StringUtils.repeat(" ", this.preLabelIndent) + StringUtils.repeat(" ", this.preLabelStr.length())
                + wrap[0];
        if (wrap.length > 1) {
            ret += "\n" + this.wrapItemNextLine(StringUtils.repeat(" ", this.maxItemIndent)
                    + StringUtils.join(ArrayUtils.remove(wrap, 0), " "));
        }
        return ret;
    }
    return renderedItem;
}

From source file:com.epam.dlab.module.ParserCsv.java

/** Construct the exception.
 * @param message the error message.//from   w ww. j av a  2  s .  c  o  m
 * @param pos the position in the parsed line.
 * @param sourceLine the parsed line.
 * @return ParseException
 */
private ParseException getParseException(String message, int pos, String sourceLine) {
    String s = String.format("%s at pos %d in line: ", message, pos);
    LOGGER.error(s + sourceLine);
    LOGGER.error(StringUtils.repeat(' ', s.length() + pos - 1) + '^');
    return new ParseException(s + sourceLine);
}

From source file:br.usp.poli.lta.cereda.spa2run.Utils.java

public static void printException(Exception exception) {
    System.out.println(StringUtils.repeat("-", 70));
    System.out.println(StringUtils.center("An exception was thrown".toUpperCase(), 70));
    System.out.println(StringUtils.repeat("-", 70));
    System.out.println(WordUtils.wrap(exception.getMessage(), 70, "\n", true));
    System.out.println(StringUtils.repeat("-", 70));
    System.exit(0);//from   www .  j  a v  a 2s .  c  o m
}

From source file:edu.illinois.cs.cogcomp.transliteration.WikiTransliteration.java

/**
 * Given a word, ngramProbs, and an ngramSize, this predicts the probability of the word with respect to this language model.
 *
 * Compare this against:/*  w  w w.j av a  2s .co  m*/
 *
 * @param word
 * @param ngramProbs
 * @param ngramSize
 * @return
 */
public static double GetLanguageProbability(String word, HashMap<String, Double> ngramProbs, int ngramSize) {
    double probability = 1;
    String paddedExample = StringUtils.repeat('_', ngramSize - 1) + word
            + StringUtils.repeat('_', ngramSize - 1);
    for (int i = ngramSize - 1; i < paddedExample.length(); i++) {
        int n = ngramSize;
        //while (!ngramProbs.TryGetValue(paddedExample.substring(i - n + 1, n), out localProb)) {

        // This is a backoff procedure.
        String ss = paddedExample.substring(i - n + 1, i + 1);
        Double localProb = ngramProbs.get(ss);
        while (localProb == null) {
            n--;
            if (n == 1)
                return 0; // final backoff probability. Be careful with this... can result in names with 0 probability if the LM isn't large enough.
            ss = paddedExample.substring(i - n + 1, i + 1);
            localProb = ngramProbs.get(ss);
        }
        probability *= localProb;
    }

    return probability;
}

From source file:kenh.xscript.ScriptUtils.java

/**
 * Debug method for <code>Element</code>
 * @param element/*  w w  w .j  a  va2  s . c om*/
 * @param level
 * @param stream
 */
private static final void debug_(Element element, int level, PrintStream stream) {
    String repeatStr = "    ";

    String prefix = StringUtils.repeat(repeatStr, level);
    stream.print(prefix + "<" + element.getClass().getCanonicalName());

    // Attribute output
    Map<String, String> attributes = element.getAttributes();
    if (attributes != null && attributes.size() > 0) {
        Set<String> keys = attributes.keySet();
        for (String key : keys) {
            stream.print(" " + key + "=\"" + attributes.get(key) + "\"");
        }
    }

    Vector<Element> children = element.getChildren();
    String text = element.getText();
    if ((children == null || children.size() == 0) && StringUtils.isBlank(text)) {
        stream.println("/>");
        return;
    } else {
        stream.println(">");

        // child elements
        if (children != null && children.size() > 0) {
            for (Element child : children) {
                debug_(child, level + 1, stream);
            }
        }

        // text/context
        if (StringUtils.isNotBlank(text)) {
            stream.println(prefix + repeatStr + "<![CDATA[" + text + "]]>");
        }

        stream.println(prefix + "</" + element.getClass().getCanonicalName() + ">");
    }
}

From source file:cc.recommenders.names.CoReNames.java

public static String src2vmType(String type) {
    ensureIsNotNull(type, "type");
    //// w w  w .ja  v a 2  s.  c om
    final PrimitiveType p = PrimitiveType.fromSrc(type);
    if (p != null) {
        return String.valueOf(p.vm());
    }
    int dimensions = 0;
    if (type.endsWith("]")) {
        dimensions = StringUtils.countMatches(type, "[]");
        type = StringUtils.substringBefore(type, "[") + ";";
    }
    return StringUtils.repeat("[", dimensions) + "L" + type.replaceAll("\\.", "/");
}

From source file:gmjonker.util.Stopwatch.java

/**
 * Returns a string representation of the current elapsed time.
 *//*from  w w  w.  j  ava2s .c  om*/
@Override
public String toString() {
    if (markers.isEmpty())
        return nanosToString(elapsedNanos());

    StringBuilder s = new StringBuilder();
    String marker1 = "START";
    int maxWidth = marker1.length();
    for (String marker2 : markers.keySet()) {
        maxWidth = max(maxWidth, marker1.length() + marker2.length());
        marker1 = marker2;
    }
    maxWidth = max(maxWidth, marker1.length() + "END".length());

    marker1 = "START";
    long tick1 = this.startTick;
    for (String marker2 : markers.keySet()) {
        Long tick2 = markers.get(marker2);
        s.append(marker1).append(" - ").append(marker2)
                .append(StringUtils.repeat(" ", max(0, maxWidth - marker1.length() - marker2.length())))
                .append(": ").append(nanosToString(tick2 - tick1)).append("\n");
        tick1 = tick2;
        marker1 = marker2;
    }
    long tick2 = this.startTick + this.elapsedNanos;
    String marker2 = "END";
    s.append(marker1).append(" - ").append(marker2)
            .append(StringUtils.repeat(" ", max(0, maxWidth - marker1.length() - marker2.length())))
            .append(": ").append(nanosToString(tick2 - tick1)).append("\n");
    s.append("Total: ").append(nanosToString(elapsedNanos));
    return s.toString();
}

From source file:de.vandermeer.asciilist.AbstractAsciiList.java

/**
 * Wraps all following lines of an item/*from   w  w  w.java 2s .co  m*/
 * @param str the string to wrap
 * @return wrapped string
 */
protected String wrapItemNextLine(String str) {
    String[] wrap = StringUtils.split(
            WordUtils.wrap(str, (this.width - this.maxItemIndent), IMPLICIT_NEWLINE, true), IMPLICIT_NEWLINE);
    String ret = StringUtils.repeat(" ", this.maxItemIndent) + wrap[0];
    if (wrap.length == 1) {
        return ret;
    }
    return ret + "\n" + this.wrapItemNextLine(
            StringUtils.repeat(" ", this.maxItemIndent) + StringUtils.join(ArrayUtils.remove(wrap, 0), " "));
}

From source file:ca.uhn.fhir.util.PrettyPrintWriterWrapper.java

private String repeat(int d, String s) {
    return StringUtils.repeat(s, d * 3);
}