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.bellman.bible.service.format.osistohtml.taghandler.LHandler.java

@Override
public void start(Attributes attrs) {
    // Refer to Gen 3:14 in ESV for example use of type=x-indent
    String type = attrs.getValue(OSISUtil.OSIS_ATTR_TYPE);
    int level = TagHandlerHelper.getAttribute(OSISUtil.OSIS_ATTR_LEVEL, attrs, 1);
    // make numIndents default to zero
    int numIndents = Math.max(0, level - 1);

    LType ltype = LType.IGNORE;//w  w w. j av a  2  s .  c  o  m
    if (TagHandlerHelper.isAttr(OSISUtil.OSIS_ATTR_EID, attrs)) {
        // e.g. Isaiah 40:12
        writer.write(HTML.BR);
        ltype = LType.BR;
    } else if (StringUtils.isNotEmpty(type)) {
        if (type.contains("indent")) {
            // this tag is specifically for indenting so ensure there is an indent
            numIndents = numIndents + 1;
            writer.write(StringUtils.repeat(indent_html, numIndents));
            ltype = LType.INDENT;
        } else if (type.contains("br")) {
            writer.write(HTML.BR);
            ltype = LType.BR;
        } else {
            ltype = LType.IGNORE;
            log.debug("Unknown <l> tag type:" + type);
        }
    } else if (TagHandlerHelper.isAttr(OSISUtil.OSIS_ATTR_SID, attrs)) {
        writer.write(StringUtils.repeat(indent_html, numIndents));
        ltype = LType.IGNORE;
    } else {
        //simple <l>
        writer.write(StringUtils.repeat(indent_html, numIndents));
        ltype = LType.END_BR;
    }
    stack.push(ltype);
}

From source file:com.trenako.web.controllers.form.ReviewForm.java

private static Map<Integer, String> ratingsList() {
    Map<Integer, String> ratings = new HashMap<Integer, String>();
    for (int r = 1; r <= 5; r++) {
        ratings.put(r, StringUtils.repeat("*", r));
    }/*ww  w.  ja  v a  2 s  . c om*/
    return ratings;
}

From source file:edu.umich.flowfence.common.QMDescriptor.java

private static List<String> toNames(Class<?>... classes) {
    if (!ParceledPayload.canParcelTypes(classes)) {
        throw new ParcelFormatException("Can't parcel arguments");
    }//from ww w . j  a v  a2s  .c o  m
    // ClassUtils.classesTaClassNames doesn't work here, because it emits arrays
    // in their JNI form ([Ljava.lang.String;). Handle array type conversion manually.
    List<String> classNames = new ArrayList<>(classes.length);
    for (Class<?> clazz : classes) {
        int arrayDepth = 0;
        while (clazz.isArray()) {
            arrayDepth++;
            clazz = clazz.getComponentType();
        }
        classNames.add(clazz.getName() + StringUtils.repeat("[]", arrayDepth));
    }
    return classNames;
}

From source file:io.github.seleniumquery.by.common.preparser.NotEqualsAttributeSelectorFix.java

String removeStrings(String input) {
    Pattern p = Pattern.compile("\"([^\"\\\\]|\\\\.)*\"|'([^'\\\\]|\\\\.)*'");
    Matcher m = p.matcher(input);
    StringBuilder sb = new StringBuilder(input);
    while (m.find()) {
        sb.replace(m.start(), m.end(), StringUtils.repeat('_', m.end() - m.start()));
    }//w  ww  .j  a va2  s  . co  m
    return sb.toString();
}

From source file:de.uni.bremen.monty.moco.codegeneration.context.Context.java

/** Adds an LLVM-Instruction as a Leaf to the Tree.
 * /*  w ww  .  j a  v a  2s. c om*/
 * @param data */
public void append(String data) {
    data = StringUtils.repeat(" ", indentation * 4) + data;
    data = commentAppender.addComment(data);
    innerContexts.add(new StringData(data + "\n"));
}

From source file:com.code972.hebmorph.TokenizerTest.java

private void assertTokenizesTo(String text, String[] tokens, int[] tokenTypes) throws IOException {
    assert tokenTypes == null || tokens.length == tokenTypes.length;

    for (int j = 4096 - text.length() - 3; j < 4096 + text.length() + 2; j++) {
        tokenizer.reset(new StringReader(StringUtils.repeat(" ", j) + text));
        int i = 0, tokenType;
        Reference<String> test = new Reference<String>("");
        while ((tokenType = tokenizer.nextToken(test)) > 0) {
            assertEquals("[Added space " + j + "]", tokens[i], test.ref);
            if (tokenTypes != null)
                assertEquals(tokenTypes[i], tokenType);
            i++;/*from   w w  w .jav a  2  s . c o  m*/
        }
        assertEquals("[Added space " + j + "]", tokens.length, i);
    }
}

From source file:com.qcadoo.model.internal.types.DecimalTypeTest.java

@Test
public final void shouldFormatDecimalTrimTrailingZeroes() {
    // given//from   w w w  .j  av a  2  s.c  o m
    final String decimalAsString = "1234567." + StringUtils.repeat("9", 3);
    BigDecimal value = new BigDecimal(decimalAsString + "00000");

    // when
    String result = decimalType.toString(value, locale);

    // then
    assertFormattedEquals(value, result);
}

From source file:monasca.api.app.validation.DimensionsTest.java

@Test(expectedExceptions = WebApplicationException.class)
public void shouldErrorOnValidateValueWithLongValue() {
    String value = StringUtils.repeat("A", 256);
    DimensionValidation.validateValue(value, "valid_name");
}

From source file:com.gmarciani.gmparser.commons.TestDeterministicFunction.java

@Test
public void createCompleteAndRemoveAllX() {
    System.out.println("#createCompleteAndRemoveAllX");
    GSet<Character> domainX = new GSet<Character>();
    domainX.add('a');
    domainX.add('b');
    domainX.add('c');
    GSet<Integer> domainY = new GSet<Integer>();
    domainY.add(1);/*from  ww  w.java2 s  . co  m*/
    domainY.add(2);
    domainY.add(3);
    GSet<String> domainZ = new GSet<String>();

    for (Character c : domainX)
        for (Integer n : domainY)
            domainZ.add(StringUtils.repeat(c, n));

    Function<Character, Integer, String> function = new DeterministicFunction<Character, Integer, String>(
            domainX, domainY, domainZ);

    for (Character c : domainX)
        for (Integer n : domainY)
            function.add(c, n, StringUtils.repeat(c, n));

    function.removeAllForX('b');

    System.out.println(function);
    System.out.println(function.toFormattedFunction());
}

From source file:fi.hsl.parkandride.core.service.AuthenticationServiceTest.java

@Test
public void requires_a_long_enough_shared_secret() {
    String tooShortSecret = StringUtils.repeat('x', AuthenticationService.SECRET_MIN_LENGTH - 1);

    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("secret must be at least 32 characters long, but it was only 31");
    new AuthenticationService(userRepository, passwordEncryptor, tooShortSecret, expires, passwordExpires,
            passwordReminder);//from  ww  w . j  av a2 s. c  o  m
}