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.audit4j.core.annotation.DeIdentifyUtil.java

/**
 * Deidentify from right./*from   ww  w.  j  a v  a 2  s .  c  o m*/
 *
 * @param str the str
 * @param size the size
 * @return the string
 * 
 * @since 2.0.0
 */
public static String deidentifyFromRight(String str, int size) {
    int end = str.length();
    int repeat;
    if (size > str.length()) {
        repeat = str.length();
    } else {
        repeat = end - size;
    }
    return StringUtils.overlay(str, StringUtils.repeat('*', repeat), 0, end - size);
}

From source file:org.audit4j.core.annotation.DeIdentifyUtil.java

/**
 * Deidentify middle./*from w  w  w. ja v a 2  s .  co  m*/
 *
 * @param str the str
 * @param start the start
 * @param end the end
 * @return the string
 * 
 * @since 2.0.0
 */
public static String deidentifyMiddle(String str, int start, int end) {

    int repeat;
    if (end - start > str.length()) {
        repeat = str.length();
    } else {
        repeat = (str.length() - end) - start;
    }
    return StringUtils.overlay(str, StringUtils.repeat('*', repeat), start, str.length() - end);
}

From source file:org.audit4j.core.annotation.DeIdentifyUtil.java

/**
 * Deidentify./*w w  w . j a v  a2  s. c  o  m*/
 *
 * @param text the text
 * @param left the left
 * @param right the right
 * @param fromLeft the from left
 * @param fromRight the from right
 * @return the string
 * 
 * @since 2.0.0
 */
public static String deidentify(String text, int left, int right, int fromLeft, int fromRight) {
    if (left == 0 && right == 0 && fromLeft == 0 && fromRight == 0) {
        return StringUtils.repeat('*', text.length());
    } else if (left > 0 && right == 0 && fromLeft == 0 && fromRight == 0) {
        return deidentifyLeft(text, left);
    } else if (left == 0 && right > 0 && fromLeft == 0 && fromRight == 0) {
        return deidentifyRight(text, right);
    } else if (left > 0 && right > 0 && fromLeft == 0 && fromRight == 0) {
        return deidentifyEdge(text, left, right);
    } else if (left == 0 && right == 0 && fromLeft > 0 && fromRight == 0) {
        return deidentifyFromLeft(text, fromLeft);
    } else if (left == 0 && right == 0 && fromLeft == 0 && fromRight > 0) {
        return deidentifyFromRight(text, fromRight);
    } else if (left == 0 && right == 0 && fromLeft > 0 && fromRight > 0) {
        return deidentifyMiddle(text, fromLeft, fromRight);
    }

    return text;
}

From source file:org.audit4j.core.DeIndentifyUtil.java

/**
 * Deidentify left./*from www  .j  a va 2s .c  om*/
 *
 * @param str the str
 * @param size the size
 * @return the string
 * 
 * @since 2.0.0
 */
public static String deidentifyLeft(String str, int size) {
    int repeat = 0;
    if (size > str.length()) {
        repeat = str.length();
    } else {
        repeat = size;
    }
    return StringUtils.overlay(str, StringUtils.repeat('*', repeat), 0, size);
}

From source file:org.audit4j.core.DeIndentifyUtil.java

/**
 * Deidentify right.//from  w  w  w. j a  v a2  s  .  co  m
 *
 * @param str the str
 * @param size the size
 * @return the string
 * 
 * @since 2.0.0
 */
public static String deidentifyRight(String str, int size) {
    int end = str.length();
    int repeat = 0;
    if (size > str.length()) {
        repeat = str.length();
    } else {
        repeat = size;
    }
    return StringUtils.overlay(str, StringUtils.repeat('*', repeat), end - size, end);
}

From source file:org.audit4j.core.DeIndentifyUtil.java

/**
 * Deidentify from left./*from   w  ww  . j  av  a2s .c  om*/
 *
 * @param str the str
 * @param size the size
 * @return the string
 * 
 * @since 2.0.0
 */
public static String deidentifyFromLeft(String str, int size) {
    int end = str.length();
    int repeat = 0;
    if (size > str.length()) {
        repeat = 0;
    } else {
        repeat = str.length() - size;
    }
    return StringUtils.overlay(str, StringUtils.repeat('*', repeat), size, end);
}

From source file:org.audit4j.core.DeIndentifyUtil.java

/**
 * Deidentify from right./* w w w  .j  a v a  2 s .  c om*/
 *
 * @param str the str
 * @param size the size
 * @return the string
 * 
 * @since 2.0.0
 */
public static String deidentifyFromRight(String str, int size) {
    int end = str.length();
    int repeat = 0;
    if (size > str.length()) {
        repeat = str.length();
    } else {
        repeat = end - size;
    }
    return StringUtils.overlay(str, StringUtils.repeat('*', repeat), 0, end - size);
}

From source file:org.audit4j.core.DeIndentifyUtil.java

/**
 * Deidentify middle.//w ww . jav a 2 s. c om
 *
 * @param str the str
 * @param start the start
 * @param end the end
 * @return the string
 * 
 * @since 2.0.0
 */
public static String deidentifyMiddle(String str, int start, int end) {

    int repeat = 0;
    if (end - start > str.length()) {
        repeat = str.length();
    } else {
        repeat = (str.length() - end) - start;
    }
    return StringUtils.overlay(str, StringUtils.repeat('*', repeat), start, str.length() - end);
}

From source file:org.auraframework.util.javascript.MultiStreamReaderTest.java

public void testReadMultipleStreamsWithFirstBeingLonger() throws Exception {
    assertReadingMultipleStreams(1, StringUtils.repeat("a", 100), "b", "c");
}

From source file:org.auraframework.util.javascript.MultiStreamReaderTest.java

public void testReadMultipleStreamsInChunksWithFirstBeingLonger() throws Exception {
    assertReadingMultipleStreams(3, StringUtils.repeat("a", 100), "b", "c");
}