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:com.ibm.cics.ca1y.Emit.java

/**
 * Return an text document containing a table of properties and containers that match the provided regular
 * expressions./*from ww w  .ja  v  a  2s.  co m*/
 * 
 * @param props
 *            - properties to use
 * @param propertiesExpression
 *            - regex of properties to include
 * @param containersExpression
 *            - regex of containers to include
 * @param summary
 * @return character table
 */
private static String getTextTable(EmitProperties props, String propertiesExpression,
        String containersExpression, String summary) {

    if ((propertiesExpression == null) && (containersExpression == null)) {
        // if neither properties or containers expression are provided, default both
        propertiesExpression = "";
        containersExpression = "";
    }

    StringBuilder sb = new StringBuilder();

    if (propertiesExpression != null) {
        if (propertiesExpression.length() == 0) {
            // Default to all CICS containers
            propertiesExpression = ".*";
        }

        Enumeration<?> e = props.propertyNamesOrdered();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();

            try {
                if (!key.matches(propertiesExpression)) {
                    continue;
                }
            } catch (Exception e2) {
                // ignore problems with regular expression
            }

            String title = "Property:" + key;
            sb.append(title).append("\n").append(StringUtils.repeat("=", title.length())).append("\n");

            sb.append("Value:");
            if ((props.getPropertyPrivacy(key) == false) && (props.getProperty(key) != null)) {
                sb.append(props.getProperty(key)).append("\n");
            } else {
                sb.append("<hidden>");
            }
            sb.append("\n");

            if (props.getPropertyMime(key) != null) {
                sb.append("Mime:").append(props.getPropertyMime(key)).append("\n");
            }

            if ((props.getPropertyPrivacy(key) == false) && (props.getPropertyAttachment(key) != null)) {
                if (summary == null) {
                    sb.append(Util.getHexDump(props.getPropertyAttachment(key), 32, "\n"));
                } else {
                    sb.append(Util.getHexSummary(props.getPropertyAttachment(key)));
                }
            }

            sb.append("\n");
        }
    }

    if (containersExpression != null) {
        if (containersExpression.length() == 0) {
            // Default to all CICS containers
            containersExpression = ".*";
        }

        Task t = Task.getTask();
        ContainerIterator ci = t.containerIterator();
        while (ci.hasNext()) {
            Container container = ci.next();
            String key = container.getName().trim();

            try {
                if (!key.matches(containersExpression)) {
                    continue;
                }

            } catch (Exception e) {
                // Ignore issues with regular expression
            }

            String title = "Container:" + key;
            sb.append(title).append("\n").append(StringUtils.repeat("=", title.length())).append("\n");

            try {
                if (summary == null) {
                    sb.append(Util.getHexDump(container.get(), 32, "\n"));

                } else {
                    sb.append(Util.getHexSummary(container.get()));
                }

            } catch (Exception e1) {
                // ignore
            }

            sb.append("\n");
        }
    }

    return sb.toString();
}

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplatePanel.java

private void printTreeTable(MutableTreeTableNode node, StringBuilder builder, int depth) {
    builder.append(StringUtils.repeat('\t', depth));
    if (node instanceof CodeTemplateLibraryTreeTableNode) {
        CodeTemplateLibraryTreeTableNode libraryNode = (CodeTemplateLibraryTreeTableNode) node;
        builder.append(libraryNode.getLibrary().getName()).append("\t\t\t\t")
                .append(libraryNode.getLibrary().getDescription().replaceAll("\r\n|\r|\n", " "));
    } else if (node instanceof CodeTemplateTreeTableNode) {
        CodeTemplateTreeTableNode codeTemplateNode = (CodeTemplateTreeTableNode) node;
        builder.append(codeTemplateNode.getCodeTemplate().getName()).append("\t\t\t\t")
                .append(StringUtils.defaultString(codeTemplateNode.getCodeTemplate().getDescription())
                        .replaceAll("\r\n|\r|\n", " "));
    }/*from  ww  w .j a v  a 2  s .  c o m*/
    builder.append('\n');

    for (Enumeration<? extends MutableTreeTableNode> children = node.children(); children.hasMoreElements();) {
        printTreeTable(children.nextElement(), builder, depth + 1);
    }
}

From source file:com.cloudera.impala.analysis.AnalyzeDDLTest.java

/**
 * Generates a string with the following pattern:
 * <prefix>*<middle><suffix>*
 * with exactly depth-1 repetitions of prefix and suffix
 *//*from   w w w  . j a v  a2  s  .com*/
private String genTypeSql(int depth, String prefix, String middle, String suffix) {
    return StringUtils.repeat(prefix, depth - 1) + middle + StringUtils.repeat(suffix, depth - 1);
}

From source file:com.xpn.xwiki.doc.XWikiDocument.java

/**
 * Get the top sections contained in the document.
 * <p>/*from   w  ww  . j  a v a  2s.  c o  m*/
 * The section are filtered by xwiki.section.depth property on the maximum depth of the sections to return. This
 * method is usually used to get "editable" sections.
 * 
 * @return the sections in the current document
 */
public List<DocumentSection> getSections() throws XWikiException {
    if (is10Syntax()) {
        return getSections10();
    } else {
        List<DocumentSection> splitSections = new ArrayList<DocumentSection>();
        List<HeaderBlock> headers = getFilteredHeaders();

        int sectionNumber = 1;
        for (HeaderBlock header : headers) {
            // put -1 as index since there is no way to get the position of the header in the source
            int documentSectionIndex = -1;

            // Need to do the same thing than 1.0 content here
            String documentSectionLevel = StringUtils.repeat("1.", header.getLevel().getAsInt() - 1) + "1";

            DocumentSection docSection = new DocumentSection(sectionNumber++, documentSectionIndex,
                    documentSectionLevel, renderXDOM(new XDOM(header.getChildren()), getSyntax()));
            splitSections.add(docSection);
        }

        return splitSections;
    }
}

From source file:net.sourceforge.pmd.docs.RuleDocGenerator.java

private static String stripIndentation(String description) {
    if (description == null || description.isEmpty()) {
        return "";
    }// w  w w.  j  a va 2  s . c o  m

    String stripped = StringUtils.stripStart(description, "\n\r");
    stripped = StringUtils.stripEnd(stripped, "\n\r ");

    int indentation = 0;
    int strLen = stripped.length();
    while (Character.isWhitespace(stripped.charAt(indentation)) && indentation < strLen) {
        indentation++;
    }

    String[] lines = stripped.split("\\n");
    String prefix = StringUtils.repeat(' ', indentation);
    StringBuilder result = new StringBuilder(stripped.length());

    if (StringUtils.isNotEmpty(prefix)) {
        for (int i = 0; i < lines.length; i++) {
            String line = lines[i];
            if (i > 0) {
                result.append(StringUtils.LF);
            }
            result.append(StringUtils.removeStart(line, prefix));
        }
    } else {
        result.append(stripped);
    }
    return result.toString();
}

From source file:net.team2xh.crt.language.compiler.Compiler.java

@Override
public Object visitMultiplication(MultiplicationContext ctx) {
    Object left = resolve(ctx.expression(0));
    Object right = resolve(ctx.expression(1));
    String operator = ctx.getChild(1).getText();

    Class l = left.getClass();// w ww.j a  va  2  s . c  om
    Class r = right.getClass();
    Class d = Double.class;
    Class i = Integer.class;
    Class s = String.class;

    // Integer multiplication
    if (l == i && r == i) {
        Integer x = (Integer) left, y = (Integer) right;
        switch (operator) {
        case "*":
            return x * y;
        case "/":
            return x / y;
        case "%":
            return x % y;
        }
    }

    // Double multiplication
    if ((l == i || l == d) && (r == i || r == d)) {
        Double x = (l == i) ? ((Integer) left).doubleValue() : (Double) left;
        Double y = (r == i) ? ((Integer) right).doubleValue() : (Double) right;
        switch (operator) {
        case "*":
            return x * y;
        case "/":
            return x / y;
        case "%":
            return x % y;
        }
    }

    // String repetition
    if (l == s && r == i || l == i && r == s) {
        if (operator.equals("*")) {
            if (l == s)
                return StringUtils.repeat((String) left, (Integer) right);

            return StringUtils.repeat((String) right, (Integer) left);
        }
    }

    throw new CompilerException(ctx, code, "Unsupported types for binary operator '" + operator + "': "
            + l.getSimpleName() + ", " + r.getSimpleName());
}

From source file:nl.knaw.huygens.alexandria.exporter.LaTeXExporter.java

private String exportMatrix(List<TAGTextNode> allTextNodes, List<TAGMarkup> allMarkups,
        List<IndexPoint> indexPoints, Set<Integer> longMarkupIndexes) {
    List<String> rangeLabels = allMarkups.stream().map(TAGMarkup::getTag).collect(toList());
    List<String> rangeIndex = new ArrayList<>();
    rangeIndex.add("");
    for (int i = 0; i < rangeLabels.size(); i++) {
        rangeIndex.add(String.valueOf(i));
    }// www  . j a  v a 2 s .  co  m
    rangeLabels.add(0, "");
    rangeLabels.add("");
    String tabularContent = StringUtils.repeat("l|", rangeLabels.size() - 1) + "l";
    StringBuilder latexBuilder = new StringBuilder()//
            .append("\\begin{tabular}{").append(tabularContent).append("}\n")//
            .append(rangeIndex.stream().map(c -> "$" + c + "$").collect(Collectors.joining(" & ")))
            .append("\\\\\n")//
            .append("\\hline\n")//
    ;

    Iterator<IndexPoint> pointIterator = indexPoints.iterator();
    if (pointIterator.hasNext()) {
        IndexPoint indexPoint = pointIterator.next();
        for (int i = 0; i < allTextNodes.size(); i++) {
            List<String> row = new ArrayList<>();
            row.add(String.valueOf(i));
            for (int j = 0; j < allMarkups.size(); j++) {
                if (i == indexPoint.getTextNodeIndex() && j == indexPoint.getMarkupIndex()) {
                    String cell = longMarkupIndexes.contains(j) ? "\\underline{X}" : "X";
                    row.add(cell);
                    if (pointIterator.hasNext()) {
                        indexPoint = pointIterator.next();
                    }

                } else {
                    row.add(" ");
                }
            }
            String content = escapedContent(allTextNodes.get(i));
            row.add(content);
            latexBuilder.append(String.join(" & ", row)).append("\\\\ \\hline\n");
        }
    }

    latexBuilder.append(rangeLabels.stream()//
            .map(c -> "\\rot{$" + c + "$}")//
            .collect(Collectors.joining(" & ")))//
            .append("\\\\\n")//
            .append("\\end{tabular}\n");
    return latexBuilder.toString();
}

From source file:nl.knaw.huygens.alexandria.exporter.LaTeXExporterInMemory.java

private String exportMatrix(List<TextNode> allTextNodes, List<Markup> allMarkups, List<IndexPoint> indexPoints,
        Set<Integer> longMarkupIndexes) {
    List<String> rangeLabels = allMarkups.stream().map(Markup::getTag).collect(Collectors.toList());
    List<String> rangeIndex = new ArrayList<>();
    rangeIndex.add("");
    for (int i = 0; i < rangeLabels.size(); i++) {
        rangeIndex.add(String.valueOf(i));
    }/*  w  ww  . ja  v a  2  s.co m*/
    rangeLabels.add(0, "");
    rangeLabels.add("");
    String tabularContent = StringUtils.repeat("l|", rangeLabels.size() - 1) + "l";
    StringBuilder latexBuilder = new StringBuilder()//
            .append("\\begin{tabular}{").append(tabularContent).append("}\n")//
            .append(rangeIndex.stream().map(c -> "$" + c + "$").collect(Collectors.joining(" & ")))
            .append("\\\\\n")//
            .append("\\hline\n")//
    ;

    Iterator<IndexPoint> pointIterator = indexPoints.iterator();
    IndexPoint indexPoint = pointIterator.next();
    for (int i = 0; i < allTextNodes.size(); i++) {
        List<String> row = new ArrayList<>();
        row.add(String.valueOf(i));
        for (int j = 0; j < allMarkups.size(); j++) {
            if (i == indexPoint.getTextNodeIndex() && j == indexPoint.getMarkupIndex()) {
                String cell = longMarkupIndexes.contains(j) ? "\\underline{X}" : "X";
                row.add(cell);
                if (pointIterator.hasNext()) {
                    indexPoint = pointIterator.next();
                }

            } else {
                row.add(" ");
            }
        }
        String content = escapedContent(allTextNodes.get(i));
        row.add(content);
        latexBuilder.append(String.join(" & ", row)).append("\\\\ \\hline\n");
    }

    latexBuilder.append(rangeLabels.stream()//
            .map(c -> "\\rot{$" + c + "$}")//
            .collect(Collectors.joining(" & ")))//
            .append("\\\\\n")//
            .append("\\end{tabular}\n");
    return latexBuilder.toString();
}

From source file:nl.mawoo.wcmscript.cli.Application.java

public static void main(String[] args) throws IOException, ScriptException {
    UUID instanceId = UUID.randomUUID();
    WCMScript wcmScript = new WCMScript(instanceId);

    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

    int indentation = 0;
    StringBuilder code = new StringBuilder();
    while (true) {
        try {/*from   w ww.j a  v  a2 s. c  o  m*/
            System.out.print("> " + StringUtils.repeat("  ", indentation));
            String line = bf.readLine();
            indentation += StringUtils.countMatches(line, '{');
            indentation -= StringUtils.countMatches(line, '}');
            code.append(line).append('\n');

            if (indentation == 0) {
                eval(wcmScript, code);
            }
        } catch (IOException e) {
            LOGGER.error("IO exception: " + e.getMessage(), e);
        }
    }
}

From source file:nl.opengeogroep.filesetsync.client.SyncJobStatePersistence.java

public static void setCurrentFileset(Fileset fs) {
    int l = SyncConfig.getInstance().getMaxFilesetNameLength();
    if (fs == null) {
        MDC.put("fileset", StringUtils.repeat(' ', l));
    } else {//w  ww  .ja  va 2s. c  o m
        MDC.put("fileset", StringUtils.repeat(' ', l - fs.getName().length()) + fs.getName());
    }
}