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:at.ac.tuwien.big.moea.print.SolutionWriter.java

protected SolutionWriter<S> setIndent(final int spaces) {
    return setIndent(StringUtils.repeat(' ', spaces));
}

From source file:monasca.api.app.command.CreateNotificationMethodTest.java

public void testValidationForMaxNameAddress() {
    String name = StringUtils.repeat("A", 250);
    assertEquals(name.length(), 250);//from w  ww.j a v  a 2s  .  c om
    String address = "http://" + StringUtils.repeat("A", 502) + ".io";
    assertEquals(address.length(), 512);
    CreateNotificationMethodCommand newNotificationMethod = new CreateNotificationMethodCommand(name,
            NOTIFICATION_METHOD_WEBHOOK, address, "0");
    Set<ConstraintViolation<CreateNotificationMethodCommand>> constraintViolations = validator
            .validate(newNotificationMethod);

    assertEquals(constraintViolations.size(), 0);
}

From source file:cn.lambdalib.cgui.gui.component.TextBox.java

private String processedContent() {
    String ret = content;//  ww  w.  j  a  v a 2 s.  c  o m
    if (shouldLocalize()) {
        ret = StatCollector.translateToLocal(ret);
    }
    if (doesEcho) {
        ret = StringUtils.repeat(echoChar, ret.length());
    }

    return ret;
}

From source file:com.norconex.jef4.status.JobSuiteStatusSnapshot.java

private void toString(StringBuilder b, String jobId, int depth) {
    IJobStatus status = getJobStatus(jobId);
    b.append(StringUtils.repeat(' ', depth * TO_STRING_INDENT));
    b.append(StringUtils.leftPad(new PercentFormatter().format(status.getProgress()), TO_STRING_INDENT));
    b.append("  ").append(status.getJobId());
    b.append(System.lineSeparator());
    for (IJobStatus child : getChildren(jobId)) {
        toString(b, child.getJobId(), depth + 1);
    }/*from   www.ja v  a 2 s .  c  o m*/
}

From source file:monasca.api.app.command.CreateNotificationMethodTest.java

public void testValidationExceptionForExceededNameLength() {
    String name = StringUtils.repeat("A", 251);
    assertEquals(name.length(), 251);/*from  w  w w  .j  a  v a  2 s . com*/
    CreateNotificationMethodCommand newNotificationMethod = new CreateNotificationMethodCommand(name,
            NOTIFICATION_METHOD_WEBHOOK, "http://somedomain.com", "0");
    Set<ConstraintViolation<CreateNotificationMethodCommand>> constraintViolations = validator
            .validate(newNotificationMethod);

    assertEquals(constraintViolations.size(), 1);
    assertEquals(constraintViolations.iterator().next().getMessage(), "size must be between 1 and 250");
}

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

public static String vm2srcQualifiedType(final ICoReTypeName type) {
    if (type.isPrimitiveType()) {
        return CoReNames.vm2srcSimpleTypeName(type);
    }/* w  ww  . ja  v  a 2  s .co  m*/
    if (type.isArrayType()) {
        return vm2srcQualifiedType(type.getArrayBaseType())
                + StringUtils.repeat("[]", type.getArrayDimensions());
    }
    String s = type.getIdentifier();
    s = s.replace('/', '.');
    return s.substring(1);
}

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

public static CSPExampleCounts LearnModel(String word1, String word2, CSPModel model) {
    CSPExampleCounts result = new CSPTransliteration().new CSPExampleCounts();

    int paddingSize = Math.max(model.productionContextSize, model.segContextSize);
    String paddedWord = StringUtils.repeat('_', paddingSize) + word1 + StringUtils.repeat('_', paddingSize);
    HashMap<Triple<Double, String, String>, Pair<SparseDoubleVector<Triple<Integer, String, String>>, Double>> lastArg = new HashMap<>();

    Pair<SparseDoubleVector<Triple<Integer, String, String>>, Double> raw = LearnModel(paddingSize, paddedWord,
            word1, word2, model, lastArg);

    if (raw.getSecond() == 0)
        raw.setFirst(new SparseDoubleVector<Triple<Integer, String, String>>());
    else/*from   w ww.j a  v  a2  s  .c o m*/
        //raw.x = Program.segSums[Math.Min(39,word1.length()-1)][Math.Min(39,word2.length()-1)] * (raw.x);
        raw.setFirst(raw.getFirst().divide(raw.getSecond()));
    //raw.x = raw.y >= 1 ? raw.x : raw.x / raw.y;

    if (model.emMode == CSPModel.EMMode.MaxSourceSeg) {
        HashMap<Pair<Integer, String>, Triple<Integer, String, String>> bestProdProbs = new HashMap<>();
        SparseDoubleVector<Pair<Integer, String>> maxProdProbs = new SparseDoubleVector<>();
        for (Triple<Integer, String, String> key : raw.getFirst().keySet()) {
            Double value = raw.getFirst().get(key);

            Pair<Integer, String> keyXY = new Pair<>(key.getFirst(), key.getSecond());

            if (maxProdProbs.get(keyXY) < value) {
                bestProdProbs.put(keyXY, key);
                maxProdProbs.put(keyXY, value);
            }
        }

        raw.getFirst().Clear();
        for (Triple<Integer, String, String> triple : bestProdProbs.values())
            raw.getFirst().put(triple, 1.0);

    } else if (model.emMode == CSPModel.EMMode.BySourceSeg) {
        //Dictionary<Pair<int, String>, Triple<int, String, String>> bestProdProbs = new Dictionary<Pair<int, String>, Triple<int, String, String>>();
        SparseDoubleVector<Pair<Integer, String>> sumProdProbs = new SparseDoubleVector<>();
        for (Triple<Integer, String, String> key : raw.getFirst().keySet()) {
            Double value = raw.getFirst().get(key);
            Pair<Integer, String> keyXY = new Pair<>(key.getFirst(), key.getSecond());
            sumProdProbs.put(keyXY, sumProdProbs.get(keyXY) + value);
        }

        SparseDoubleVector<Triple<Integer, String, String>> newCounts = new SparseDoubleVector<>(
                raw.getFirst().size());
        for (Triple<Integer, String, String> key : raw.getFirst().keySet()) {
            Double value = raw.getFirst().get(key);
            Pair<Integer, String> keyXY = new Pair<>(key.getFirst(), key.getSecond());
            newCounts.put(key, value / sumProdProbs.get(keyXY));
        }
        raw.setFirst(newCounts);
    }

    result.productionCounts = new SparseDoubleVector<>(raw.getFirst().size());
    result.segCounts = new SparseDoubleVector<>(raw.getFirst().size());

    for (Triple<Integer, String, String> key : raw.getFirst().keySet()) {
        Double value = raw.getFirst().get(key);
        Pair<Triple<String, String, String>, String> pckey = new Pair<>(
                new Triple<>(
                        WikiTransliteration
                                .GetLeftContext(paddedWord, key.getFirst(), model.productionContextSize),
                        key.getSecond(),
                        WikiTransliteration.GetRightContext(paddedWord,
                                key.getFirst() + key.getSecond().length(), model.productionContextSize)),
                key.getThird());
        result.productionCounts.put(pckey, result.productionCounts.get(pckey) + value);

        Triple<String, String, String> sckey = new Triple<>(
                WikiTransliteration.GetLeftContext(paddedWord, key.getFirst(), model.segContextSize),
                key.getSecond(), WikiTransliteration.GetRightContext(paddedWord,
                        key.getFirst() + key.getSecond().length(), model.segContextSize));
        result.segCounts.put(sckey, result.segCounts.get(sckey) + value);
    }

    return result;
}

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

public static String vm2srcQualifiedType(final ICoReTypeName type) {
    if (type.isPrimitiveType()) {
        return Names.vm2srcSimpleTypeName(type);
    }//  www  . j a  v  a 2 s  .c  om
    if (type.isArrayType()) {
        return vm2srcQualifiedType(type.getArrayBaseType())
                + StringUtils.repeat("[]", type.getArrayDimensions());
    }
    String s = type.getIdentifier();
    s = s.replace('/', '.');
    return s.substring(1);
}

From source file:com.greenpepper.maven.plugin.FixtureGeneratorMojo.java

private void printSpecificationName(String specificationName) {
    System.out.println();//from  w  w  w .ja v a2 s.  c  om
    String title = format(" Generating fixture for : %s ", specificationName);
    System.out.println(title);
    System.out.println(StringUtils.repeat("-", title.length()));
    System.out.println();
}

From source file:monasca.api.app.command.CreateNotificationMethodTest.java

public void testValidationExceptionForExceededAddressLength() {
    String address = "http://" + StringUtils.repeat("A", 503) + ".io";
    assertEquals(address.length(), 513);
    CreateNotificationMethodCommand newNotificationMethod = new CreateNotificationMethodCommand("MyWebhook",
            NOTIFICATION_METHOD_WEBHOOK, address, "0");
    Set<ConstraintViolation<CreateNotificationMethodCommand>> constraintViolations = validator
            .validate(newNotificationMethod);

    assertEquals(constraintViolations.size(), 1);
    assertEquals(constraintViolations.iterator().next().getMessage(), "size must be between 1 and 512");
}