Java Code Examples for org.apache.commons.lang3.StringUtils#right()

The following examples show how to use org.apache.commons.lang3.StringUtils#right() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Remove ticket id from the log message.
 *
 * @param msg the message
 * @return the modified message with tgt id removed
 */
private String removeTicketId(final String msg) {
    String modifiedMessage = msg;

    if (StringUtils.isNotBlank(msg)) {
        final Matcher matcher = TICKET_ID_PATTERN.matcher(msg);
        while (matcher.find()) {
            final String match = matcher.group();
            final String newId = matcher.group(1) + '-'
                    + StringUtils.repeat("*", match.length() - VISIBLE_ID_TAIL_LENGTH)
                    + StringUtils.right(match, VISIBLE_ID_TAIL_LENGTH);

            modifiedMessage = modifiedMessage.replaceAll(match, newId);
        }
    }
    return modifiedMessage;
}
 
Example 2
Source Project: phoenix   File: RulesApplier.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Add a numerically increasing counter onto the and of a random string.
 * Incremented counter should be thread safe.
 *
 * @param column {@link org.apache.phoenix.pherf.configuration.Column}
 * @return {@link org.apache.phoenix.pherf.rules.DataValue}
 */
private DataValue getSequentialVarcharDataValue(Column column) {
    DataValue data = null;
    long inc = COUNTER.getAndIncrement();
    String strInc = String.valueOf(inc);
    int paddedLength = column.getLengthExcludingPrefix();
    String strInc1 = StringUtils.leftPad(strInc, paddedLength, "0");
    String strInc2 = StringUtils.right(strInc1, column.getLengthExcludingPrefix());
    String varchar = (column.getPrefix() != null) ? column.getPrefix() + strInc2:
            strInc2;

    // Truncate string back down if it exceeds length
    varchar = StringUtils.left(varchar,column.getLength());
    data = new DataValue(column.getType(), varchar);
    return data;
}
 
Example 3
/**
 * 【身份证号】显示最后四位,其他隐藏。共计18位或者15位
 * <p>
 * DesensitizedUtil.password("140311199701017639"); = "*************7639"
 * </p>
 */
public static String idCardNum(String id) {
	if (StringUtils.isBlank(id)) {
		return "";
	}
	String num = StringUtils.right(id, 4);
	return StringUtils.leftPad(num, StringUtils.length(id), "*");
}
 
Example 4
/**
 * 【身份证号】显示最后四位,其他隐藏。共计18位或者15位
 * <p>
 * DesensitizedUtil.password("140311199701017639"); = "*************7639"
 * </p>
 */
public static String idCardNum(String id) {
	if (StringUtils.isBlank(id)) {
		return "";
	}
	String num = StringUtils.right(id, 4);
	return StringUtils.leftPad(num, StringUtils.length(id), "*");
}
 
Example 5
Source Project: halo   File: HaloUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Desensitizes the plain text.
 *
 * @param plainText plain text must not be null
 * @param leftSize  left size
 * @param rightSize right size
 * @return desensitization
 */
public static String desensitize(@NonNull String plainText, int leftSize, int rightSize) {
    Assert.hasText(plainText, "Plain text must not be blank");

    if (leftSize < 0) {
        leftSize = 0;
    }

    if (leftSize > plainText.length()) {
        leftSize = plainText.length();
    }

    if (rightSize < 0) {
        rightSize = 0;
    }

    if (rightSize > plainText.length()) {
        rightSize = plainText.length();
    }

    if (plainText.length() < leftSize + rightSize) {
        rightSize = plainText.length() - leftSize;
    }

    int remainSize = plainText.length() - rightSize - leftSize;

    String left = StringUtils.left(plainText, leftSize);
    String right = StringUtils.right(plainText, rightSize);
    return StringUtils.rightPad(left, remainSize + leftSize, '*') + right;
}
 
Example 6
public static String idCard(String id)
{
    if (StringUtils.isBlank(id))
    {
        return "";
    }
    int length = StringUtils.length(id);
    if (length < 8)
    {
        return StringUtils.left(id, 4).concat(StringUtils.leftPad(StringUtils.right(id, 4), length, "*"));
    }
    String num = StringUtils.right(id, 4);
    return StringUtils.left(id, 4).concat(StringUtils.leftPad(num, StringUtils.length(id) - 4, "*"));
}
 
Example 7
/**
 * [身份证号] 显示最后四位,其他隐藏。共计18位或者15位。<例子:*************5762>.
 *
 * @param id
 *            the id
 * @return the string
 */
public static String idCardNum(String id){
    if (StringUtils.isBlank(id)){
        return "";
    }
    String num = StringUtils.right(id, 4);
    return StringUtils.leftPad(num, StringUtils.length(id), "*");
}
 
Example 8
@Test
public void delete_last_char_apache() {

	String phrase = "TRON: Legacy";

	String rephrase = StringUtils.right(phrase, phrase.length() - 1);

	assertEquals("RON: Legacy", rephrase);
}
 
Example 9
Source Project: developerWorks   File: SqlGenerator.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Fetch the year (if present)
 * 
 * @param line
 * @return
 */
protected String fetchYear(String[] line) {
  return StringUtils.right(StringUtils.substringAfter(line[0], NetworkProperties.getDatePrologue()).trim(), 4);
}
 
Example 10
Source Project: feilong-core   File: StringUtil.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * [截取]:获取文字最后位数 <code>lastLenth</code> 的字符串.
 * 
 * <h3>示例:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * StringUtil.substringLast("jinxin.feilong", 5) = ilong
 * </pre>
 * 
 * </blockquote>
 * 
 * @param text
 *            文字
 * @param lastLenth
 *            最后的位数
 * @return 如果 <code>text</code> 是null,返回 null<br>
 *         如果 {@code lastLenth<0},返回 {@link StringUtils#EMPTY}<br>
 *         如果 {@code text.length() <= lastLenth},返回text<br>
 *         否则返回<code> text.substring(text.length() - lastLenth)</code>
 * @see org.apache.commons.lang3.StringUtils#right(String, int)
 */
public static String substringLast(final String text,int lastLenth){
    return StringUtils.right(text, lastLenth);
}