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.sdfl.compiler.sql.statement.ConditionGroupSQLCodeGenerator.java

private void addRelationKeywordIfNecessary(int pIndentLevel, Condition lCurCondition) {
    if (lCurCondition.getRelation() != null) {
        this.builder.append(StringUtils.repeat("    ", pIndentLevel));

        String lStringOfRelation = null;
        switch (lCurCondition.getRelation()) {
        case AND:
            lStringOfRelation = "AND";
            break;

        case OR:/*w  w w .  j  a  v a  2  s. c  o m*/
            lStringOfRelation = "OR";
            break;
        }

        this.builder.append(lStringOfRelation + " ");
    }
}

From source file:com.joyent.manta.client.MantaObjectDepthComparatorTest.java

private static List<MantaObject> dirObjects(final int depth) {
    List<MantaObject> objects = new ArrayList<>();

    StringBuilder path = new StringBuilder(SEPARATOR);
    path.append("user").append(SEPARATOR);
    path.append("stor");

    for (int i = 3; i <= depth; i++) {
        final int segmentChar = (depth + i) % 26;
        path.append(SEPARATOR).append(StringUtils.repeat(((char) (97 + segmentChar)), 3));
        MantaObject object = mockDirectory(path);
        objects.add(object);/*from  w  w  w  . j  a  v  a 2 s .c  o m*/
    }

    return objects;
}

From source file:com.nortal.petit.core.util.SqlUtil.java

private static StringBuilder addFullBlocks(String columnName, int maxExpressions, int fullBlocksCount,
        String operator, String logicalOp) {
    StringBuilder fullBlocks = new StringBuilder();
    if (fullBlocksCount > 0) {
        for (int i = 0; i < fullBlocksCount; i++) {
            fullBlocks.append(columnName).append(' ').append(operator).append(" (?");
            fullBlocks.append(StringUtils.repeat(",?", maxExpressions - 1)).append(')');
            if (i < (fullBlocksCount - 1)) {
                fullBlocks.append(' ').append(logicalOp).append(' ');
            }// www . j av a 2s  .co m
        }
    }
    return fullBlocks;
}

From source file:info.mikaelsvensson.devtools.analysis.shared.reportprinter.PlainTextReportPrinter.java

private void printHeader(String text, boolean marginTop, PrintStream printStream) {
    if (marginTop) {
        printStream.println();//from ww  w .  j a va 2s .  c  o m
    }
    printStream.println(text);
    printStream.println(StringUtils.repeat('-', text.length()));
}

From source file:br.msf.commons.text.HexUtils.java

/**
 * Puts a separator between groups of <tt>groupLen</tt> nibbles.
 * <p/>//w w w  . ja  va  2  s  .c o  m
 * Also, puts leading zeroes when necessary.
 *
 * @param hexString The hex string to be formatted.
 * @param groupLen  The length of the groups of nibbles.
 * @return The formatted hex string.
 */
public static String format(final String hexString, final int groupLen) {
    final String unformatted = unformat(hexString);
    ArgumentUtils.rejectIfDontMatches(unformatted, HEX_PATTERN);
    final StringBuilder buffer = new StringBuilder();
    final StringBuilder formatted = new StringBuilder();
    for (int i = CharSequenceUtils.indexOfLastChar(unformatted); i >= 0; i--) {
        buffer.insert(0, unformatted.charAt(i));
        if (buffer.length() == groupLen) {
            /* When the buffer reaches 'groupLen' size, its contents is passed to 'formatted'. */
            if (i > 0) {
                /*
                 * If unprocessed chars remains on the original string, them we put the separator on the buffer
                 * start.
                 */
                buffer.insert(0, GROUP_SEPARATOR);
            }
            /* we pass the buffer value to the 'formatted' accumulator */
            formatted.insert(0, buffer);
            /* empty the buffer */
            buffer.replace(0, buffer.length(), "");
        }
    }
    /* If unprocessed chars remains on the buffer, it means that we need to fill it up with trailing zeroes. */
    if (buffer.length() > 0) {
        buffer.insert(0, StringUtils.repeat("0", groupLen - buffer.length()));
        /* we pass the buffer value to the 'formatted' accumulator */
        formatted.insert(0, buffer);
    }
    return formatted.toString();
}

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

protected void sectionTitleLevel(Markup markup, int level, String title) {
    Validate.notBlank(title, "title must not be blank");
    Validate.inclusiveBetween(1, MAX_TITLE_LEVEL, level);
    documentBuilder.append(newLine);/*from w  w  w.  j  av a2s  . c  o m*/
    documentBuilder.append(StringUtils.repeat(markup.toString(), level + 1)).append(" ")
            .append(replaceNewLinesWithWhiteSpace(title)).append(newLine);
}

From source file:com.quinsoft.zeidon.standardoe.ObjectInstanceComparer.java

/**
 * Create an HTML file that somewhat compares two OIs side-by-side.
 * Shamelessly copied from Ryoji Kodakari at http://tsrtesttest.appspot.com/wiki/diff-util
 * /*from  w  ww  .  j  a va 2 s  .c  om*/
 * @param task
 */
void displayDiff(Task task) {
    String filename = "/tmp/diff.html";
    PrintWriter stream = null;
    try {
        stream = new PrintWriter(filename);

        StringBuilder tl = new StringBuilder();
        StringBuilder tr = new StringBuilder();
        List<Delta> deltas = patch.getDeltas();
        int last = 0;
        for (Delta delta : deltas) {
            if (last + 1 < delta.getOriginal().getPosition()) {
                tl.append("<pre>");
                tr.append("<pre>");
                for (int i = last + 1; i < delta.getOriginal().getPosition(); i++) {
                    tl.append(list1.get(i) + "\n");
                    tr.append(list1.get(i) + "\n");
                }
                tl.append("</pre>\n");
                tr.append("</pre>\n");
            }
            TYPE type = delta.getType();
            List<?> or = delta.getOriginal().getLines();
            tl.append("<pre style='background-color:" + COLORS.get(type) // <---
                    + ";'>\n" + StringUtils.join(or, "\n") + "\n</pre>");
            List<?> re = delta.getRevised().getLines();
            tr.append(
                    "<pre style='background-color:" + COLORS.get(type) + ";'>\n" + StringUtils.join(re, "\n"));
            if (or.size() > re.size()) {
                int diff = or.size() - re.size() - 1;
                tr.append(StringUtils.repeat('\n', diff));
            }
            tr.append("\n</pre>");
            last = delta.getOriginal().last();
        }

        if (last + 1 < list1.size()) { // last is not delta
            tl.append("<pre>\n");
            tr.append("<pre>\n");
            for (int i = last + 1; i < list1.size(); i++) {
                tl.append(list1.get(i) + "\n");
                tr.append(list1.get(i) + "\n");
            }
            tl.append("</pre>\n");
            tr.append("</pre>\n");
        }

        stream.println("<html><table><tr><td style='vertical-align:top;'>" + tl.toString()
                + "</td><td style='vertical-align:top;'>" + tr.toString() + "</td></tr></table></html>");
    } catch (Exception e) {
        throw ZeidonException.wrapException(e).prependFilename(filename);
    } finally {
        if (stream != null)
            stream.close();
    }
}

From source file:com.thoughtworks.go.server.util.EncryptionHelperTest.java

@Test
void shouldEncryptAndDecryptChunkUsingAESandRSA() throws Exception {
    String chunk = StringUtils.repeat("Encryption is awesome!", 150);

    File privateKeyFile = new File(
            getClass().getClassLoader().getResource("rsa/subordinate-private.pem").getFile());
    File publicKeyFile = new File(
            getClass().getClassLoader().getResource("rsa/subordinate-public.pem").getFile());

    SecretKey secretKey = EncryptionHelper.generateAESKey();

    String aesEncryptedData = EncryptionHelper.encryptUsingAES(secretKey, chunk);
    String rsaEncryptedAESKey = EncryptionHelper.encryptUsingRSA(
            Base64.getEncoder().encodeToString(secretKey.getEncoded()),
            FileUtils.readFileToString(publicKeyFile, "utf8"));

    String secretKeyContent = EncryptionHelper.decryptUsingRSA(rsaEncryptedAESKey,
            FileUtils.readFileToString(privateKeyFile, "utf8"));
    byte[] decryptedKey = Base64.getDecoder().decode(secretKeyContent);
    secretKey = new SecretKeySpec(decryptedKey, 0, decryptedKey.length, "AES");

    String decryptedData = EncryptionHelper.decryptUsingAES(secretKey, aesEncryptedData);

    assertThat(chunk, is(decryptedData));
}

From source file:at.tuwien.mnsa.smssender.SMSPDUConverterTest.java

@Test
public void testSpecialCharsConcatenation() {
    SMS s = new SMS("436604678660", StringUtils.repeat("", 100));
    List<SMS.SMSRepresentation> singleSms = s.getMultiMessage();

    assertEquals(singleSms.size(), 2);/*www.jav a 2  s . c o  m*/
}

From source file:net.dragberry.cloudstore.controller.Greeter.java

public void search(String searchRequest, String title, String description, String fullDescription,
        String minCost, String maxCost) {
    categoryService.buildCategoryTree();
    ProductListQuery p = new ProductListQuery();
    p.setPageSize(3);/*from  w  w  w.j  a  va2  s .c  o  m*/
    p.setPageNumber(1);
    p.setSearchRequest(searchRequest);
    p.setTitle(title);
    p.setDescription(description);
    p.setFullDescription(fullDescription);
    List<Long> ids = new ArrayList<Long>();
    for (String id : selectedCategoryIds) {
        ids.add(Long.valueOf(id));
    }
    p.setCategoryIdList(ids);
    p.setMinCost(StringUtils.isBlank(minCost) ? null : new BigDecimal(minCost));
    p.setMaxCost(StringUtils.isBlank(maxCost) ? null : new BigDecimal(maxCost));
    productList = productService.fetchProducts(p).getList();

    for (Product product : productList) {
        LOGGER.info(product.getTitle());
        product.getCategoryTree().walkTree(new TreeNodeCallback<Category>() {

            @Override
            public int handleTreeNode(TreeNode<Category> node) {
                LOGGER.info(StringUtils.repeat("\t", node.getLevel()) + node.getReference().getTitle());
                return 0;
            }
        });
    }
}