Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gsmbiz.gsncoupon.util;
- import org.apache.commons.lang3.StringUtils;
- /**
- * @author jason, Moon (jason.moon.kr@gmail.com)
- * @since 2018-05-11
- */
- public class MaskingUtils {
- /**
- * @since 2018-05-11
- * @author jason, Moon (jason.moon.kr@gmail.com)
- * @param source : 마스킹할 문자열
- * @return 마스킹된 문자열
- * <pre>
- * input: 홍길동, output: 홍*동
- * input: 최영, output: 최*
- * input: 반딧불이, output: 반**이
- * </pre>
- */
- public static String maskingName(String source) {
- StringBuilder destination = new StringBuilder();
- if (source.length() == 2) {
- destination.append(source, 0, 1);
- destination.append("*");
- } else {
- destination.append(source, 0, 1);
- destination.append(StringUtils.repeat("*", source.length()-2));
- destination.append(source, source.length() - 1, source.length());
- }
- return destination.toString();
- }
- /**
- * @since 2018-05-11
- * @author jason, Moon (jason.moon.kr@gmail.com)
- * @param source : 마스킹할 문자열
- * @return 마스킹된 문자열
- * <pre>
- * input: 010-1234-1234, output: 010-****-1234
- * input: 1234-1234, output: 1234-****
- * input: 1234-1234-1234-1234, output: 1234-****-****-1234
- * </pre>
- */
- public static String maskingPhoneNumber(String source) {
- String[] sourceArr = source.split("-", -1);
- String[] destination = new String[sourceArr.length];
- if (sourceArr.length == 2) {
- destination[0] = sourceArr[0];
- destination[1] = "*";
- } else {
- for (int i = 0; i < destination.length; i++) {
- if (i == 0) {
- destination[i] = sourceArr[i];
- } else if (i == destination.length - 1) {
- destination[i] = sourceArr[i];
- } else {
- destination[i] = StringUtils.repeat("*", sourceArr[i].length());
- }
- }
- }
- return StringUtils.join(destination, "-");
- }
- }
Add Comment
Please, Sign In to add comment