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:org.cerberus.util.SqlUtil.java

/**
 * Generates an IN (?, ?) clause. The IN clause uses the ? wildcard to represent each parameter included in the IN's set.
 * @param field/* w w w .  j  av  a2  s  .co m*/
 * @param list
 * @return 
 */
public static String generateInClause(String field, List<String> list) {
    StringBuilder clause = new StringBuilder();
    if (list != null && !list.isEmpty()) {
        clause.append(field).append(" in (");
        clause.append(StringUtils.repeat("?, ", list.size()));
        clause.append(") ");
    }

    return clause.toString().replace("?, )", "?)");
}

From source file:org.cloudsimplus.builders.tables.TextTableBuilder.java

/**
 * Gets a given string and returns a formatted version of it
 * that is centralized in the table width.
 * @param str The string to be centralized
 * @return The centralized version of the string
 *//*from   w ww. j a  v a  2 s  .  c om*/
private String getCentralizedString(final String str) {
    final int identationLength = (getLengthOfColumnHeadersRow() - str.length()) / 2;
    return String.format("\n%s%s\n", StringUtils.repeat(" ", identationLength), str);
}

From source file:org.codice.ddf.commands.catalog.TransformersCommand.java

private void printTransformers(Class transformerClass, String type) throws InvalidSyntaxException {

    Collection<ServiceReference> sref = bundleContext.getServiceReferences(transformerClass, FILTER);

    List<TransformerProperties> transformersProperties = sref.stream().map(TransformerProperties::new)
            .collect(Collectors.toList());

    int activeTransformers = transformersProperties.size();

    if (activeTransformers == 0) {
        console.printf("There are no active %s transformers%n%n", type);
        return;//w  ww.jav a  2 s . co m
    }

    console.printf("%n%n%n%nActive %s Transformers: %d%n%s%n%n", type, activeTransformers, LINE);

    Iterator<TransformerProperties> tpIterator = transformersProperties.iterator();
    TransformerProperties tp;

    while (tpIterator.hasNext()) {
        tp = tpIterator.next();

        if (allOption) {
            console.printf("%s", tp.printAllProperties());
        } else {
            console.printf("%s", tp.printDefaultProperties());
        }

        if (tpIterator.hasNext()) {
            console.printf("%n%s%n", StringUtils.repeat(LINE, 3));
        }
        console.printf("%n");
    }
}

From source file:org.codice.util.tlmatcher.TimeLimitedMatcherTest.java

@Test(expected = TimeoutException.class)
public void questionableMatchFails() throws Exception {
    TimeLimitedMatcher.create(Pattern.compile("(a+)+"), StringUtils.repeat("a", 1000) + "!");
}

From source file:org.coursera.courier.lang.PoorMansCStyleSourceFormatter.java

public PoorMansCStyleSourceFormatter(int indentSpaces, DocCommentStyle docCommentStyle) {
    this.indent = StringUtils.repeat(" ", indentSpaces);
    this.docCommentStyle = docCommentStyle;
}

From source file:org.coursera.courier.lang.PoorMansCStyleSourceFormatter.java

public String format(String code) {
    String lines[] = code.split("\\r?\\n");
    StringBuilder result = new StringBuilder();
    Stack<Scope> scope = new Stack<>();
    scope.push(Scope.ROOT);//from   w  w  w .  j  a  va 2s  .co m

    int indentLevel = 0;
    boolean isPreviousLineEmpty = true;
    boolean isPreviousLinePreamble = false;

    for (String line : lines) {
        line = line.trim();

        // skip repeated empty lines
        boolean isEmpty = (line.length() == 0);
        if (isEmpty && ((isPreviousLineEmpty || isPreviousLinePreamble) || scope.size() > 2))
            continue;

        if (scope.peek() == Scope.COMMENT && line.startsWith("*")
                && docCommentStyle == DocCommentStyle.ASTRISK_MARGIN) {
            result.append(" "); // align javadoc continuation
        }

        if ((scope.peek() == Scope.BLOCK || scope.peek() == Scope.SWITCH) && line.startsWith("}")) {
            scope.pop();
            indentLevel--;
        } else if (scope.peek() == Scope.PARAMS && line.startsWith(")")) {
            scope.pop();
            indentLevel--;
        } else if (scope.peek() == Scope.COMMENT && line.startsWith("*/")) {
            scope.pop();
            if (docCommentStyle == DocCommentStyle.NO_MARGIN)
                indentLevel--;
        }

        boolean isCaseStmt = scope.peek() == Scope.SWITCH
                && (line.startsWith("case ") || line.startsWith("default"));

        boolean isDeclContinuation = line.startsWith("extends") || line.startsWith("with")
                || line.startsWith("implements");

        result.append(
                StringUtils.repeat(indent, indentLevel - (isCaseStmt ? 1 : 0) + (isDeclContinuation ? 1 : 0)));

        result.append(line);
        result.append('\n');

        if (line.endsWith("{")) {
            indentLevel++;
            if (line.startsWith("switch ")) {
                scope.push(Scope.SWITCH);
            } else {
                scope.push(Scope.BLOCK);
            }
        } else if (line.endsWith("(")) {
            indentLevel++;
            scope.push(Scope.PARAMS);
        } else if (line.startsWith("/**")) {
            scope.push(Scope.COMMENT);
            if (docCommentStyle == DocCommentStyle.NO_MARGIN)
                indentLevel++;
        }

        isPreviousLinePreamble = (line.startsWith("@") || line.startsWith("*"));
        isPreviousLineEmpty = isEmpty;
    }
    return result.toString();
}

From source file:org.deeplearning4j.nn.graph.ComputationGraph.java

/**
 * String detailing the architecture of the computation graph.
 * Vertices are printed in a topological sort order.
 * Columns are Vertex Names with layer/vertex type, nIn, nOut, Total number of parameters and the Shapes of the parameters
 * And the inputs to the vertex//from   www . ja v a 2  s.  co m
 * Will also give information about frozen layers/vertices, if any.
 * @return Summary as a string
 */
public String summary() {
    String ret = "\n";
    ret += StringUtils.repeat("=", 140);
    ret += "\n";
    ret += String.format("%-40s%-15s%-15s%-30s %s\n", "VertexName (VertexType)", "nIn,nOut", "TotalParams",
            "ParamsShape", "Vertex Inputs");
    ret += StringUtils.repeat("=", 140);
    ret += "\n";
    int frozenParams = 0;
    for (int currVertexIdx : topologicalOrder) {
        GraphVertex current = vertices[currVertexIdx];

        String name = current.getVertexName();
        String[] classNameArr = current.getClass().toString().split("\\.");
        String className = classNameArr[classNameArr.length - 1];

        String connections = "-";
        if (!current.isInputVertex()) {
            connections = configuration.getVertexInputs().get(name).toString();
        }
        String paramCount = "-";
        String in = "-";
        String out = "-";
        String paramShape = "-";
        if (current.hasLayer()) {
            Layer currentLayer = ((LayerVertex) current).getLayer();
            classNameArr = currentLayer.getClass().getName().split("\\.");
            className = classNameArr[classNameArr.length - 1];
            paramCount = String.valueOf(currentLayer.numParams());
            if (currentLayer.numParams() > 0) {
                paramShape = "";
                in = String.valueOf(((FeedForwardLayer) currentLayer.conf().getLayer()).getNIn());
                out = String.valueOf(((FeedForwardLayer) currentLayer.conf().getLayer()).getNOut());
                Set<String> paraNames = currentLayer.conf().getLearningRateByParam().keySet();
                for (String aP : paraNames) {
                    String paramS = ArrayUtils.toString(currentLayer.paramTable().get(aP).shape());
                    paramShape += aP + ":" + paramS + ", ";
                }
                paramShape = paramShape.subSequence(0, paramShape.lastIndexOf(",")).toString();
            }
            if (currentLayer instanceof FrozenLayer) {
                frozenParams += currentLayer.numParams();
                classNameArr = ((FrozenLayer) currentLayer).getInsideLayer().getClass().getName().split("\\.");
                className = "Frozen " + classNameArr[classNameArr.length - 1];
            }
        }
        ret += String.format("%-40s%-15s%-15s%-30s %s", name + " (" + className + ")", in + "," + out,
                paramCount, paramShape, connections);
        ret += "\n";
    }
    ret += StringUtils.repeat("-", 140);
    ret += String.format("\n%30s %d", "Total Parameters: ", params().length());
    ret += String.format("\n%30s %d", "Trainable Parameters: ", params().length() - frozenParams);
    ret += String.format("\n%30s %d", "Frozen Parameters: ", frozenParams);
    ret += "\n";
    ret += StringUtils.repeat("=", 140);
    ret += "\n";

    return ret;
}

From source file:org.deeplearning4j.nn.multilayer.MultiLayerNetwork.java

/**
 * String detailing the architecture of the multilayernetwork.
 * Columns are LayerIndex with layer type, nIn, nOut, Total number of parameters and the Shapes of the parameters
 * Will also give information about frozen layers, if any.
 * @return Summary as a string//from w  ww .  j  av  a  2 s  . c  o  m
 */
public String summary() {
    String ret = "\n";
    ret += StringUtils.repeat("=", 140);
    ret += "\n";
    ret += String.format("%-40s%-15s%-15s%-30s\n", "LayerName (LayerType)", "nIn,nOut", "TotalParams",
            "ParamsShape");
    ret += StringUtils.repeat("=", 140);
    ret += "\n";
    int frozenParams = 0;
    for (Layer currentLayer : layers) {
        String name = String.valueOf(currentLayer.getIndex());
        String paramShape = "-";
        String in = "-";
        String out = "-";
        String[] classNameArr = currentLayer.getClass().getName().split("\\.");
        String className = classNameArr[classNameArr.length - 1];
        String paramCount = String.valueOf(currentLayer.numParams());
        if (currentLayer.numParams() > 0) {
            paramShape = "";
            in = String.valueOf(((FeedForwardLayer) currentLayer.conf().getLayer()).getNIn());
            out = String.valueOf(((FeedForwardLayer) currentLayer.conf().getLayer()).getNOut());
            Set<String> paraNames = currentLayer.conf().getLearningRateByParam().keySet();
            for (String aP : paraNames) {
                String paramS = ArrayUtils.toString(currentLayer.paramTable().get(aP).shape());
                paramShape += aP + ":" + paramS + ", ";
            }
            paramShape = paramShape.subSequence(0, paramShape.lastIndexOf(",")).toString();
        }
        if (currentLayer instanceof FrozenLayer) {
            frozenParams += currentLayer.numParams();
            classNameArr = ((FrozenLayer) currentLayer).getInsideLayer().getClass().getName().split("\\.");
            className = "Frozen " + classNameArr[classNameArr.length - 1];
        }
        ret += String.format("%-40s%-15s%-15s%-30s", name + " (" + className + ")", in + "," + out, paramCount,
                paramShape);
        ret += "\n";
    }
    ret += StringUtils.repeat("-", 140);
    ret += String.format("\n%30s %d", "Total Parameters: ", params().length());
    ret += String.format("\n%30s %d", "Trainable Parameters: ", params().length() - frozenParams);
    ret += String.format("\n%30s %d", "Frozen Parameters: ", frozenParams);
    ret += "\n";
    ret += StringUtils.repeat("=", 140);
    ret += "\n";
    return ret;
}

From source file:org.diorite.config.serialization.comments.CommentsWriter.java

private void updateIndent(boolean up) {
    if (up) {//from w w  w .  j  av a 2  s. c om
        this.cachedIndent = StringUtils.repeat(' ', (++this.indent) * 2);
    } else {
        this.cachedIndent = StringUtils.repeat(' ', (--this.indent) * 2);
    }
}

From source file:org.diorite.config.serialization.snakeyaml.emitter.Emitter.java

private String createRightBorder(String comment, int longest, String commentRightBorder) {
    int commentLength = comment.length() + 2;
    String rightBorder;/*w  w w .j a  va 2 s.  c o m*/
    if (commentLength < longest) {
        rightBorder = StringUtils.repeat(' ',
                DioriteMathUtils.ceil(((double) (longest - commentLength)) / commentRightBorder.length()))
                + '#';
    } else {
        rightBorder = commentRightBorder;
    }
    return "# " + comment + rightBorder;
}