Guest User

Untitled

a guest
May 16th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. package com.gsmbiz.gsncoupon.util;
  2.  
  3. import org.apache.commons.lang3.StringUtils;
  4.  
  5. /**
  6. * @author jason, Moon (jason.moon.kr@gmail.com)
  7. * @since 2018-05-11
  8. */
  9. public class MaskingUtils {
  10. /**
  11. * @since 2018-05-11
  12. * @author jason, Moon (jason.moon.kr@gmail.com)
  13. * @param source : 마스킹할 문자열
  14. * @return 마스킹된 문자열
  15. * <pre>
  16. * input: 홍길동, output: 홍*동
  17. * input: 최영, output: 최*
  18. * input: 반딧불이, output: 반**이
  19. * </pre>
  20. */
  21. public static String maskingName(String source) {
  22. StringBuilder destination = new StringBuilder();
  23.  
  24. if (source.length() == 2) {
  25. destination.append(source, 0, 1);
  26. destination.append("*");
  27. } else {
  28. destination.append(source, 0, 1);
  29. destination.append(StringUtils.repeat("*", source.length()-2));
  30. destination.append(source, source.length() - 1, source.length());
  31. }
  32.  
  33. return destination.toString();
  34. }
  35.  
  36. /**
  37. * @since 2018-05-11
  38. * @author jason, Moon (jason.moon.kr@gmail.com)
  39. * @param source : 마스킹할 문자열
  40. * @return 마스킹된 문자열
  41. * <pre>
  42. * input: 010-1234-1234, output: 010-****-1234
  43. * input: 1234-1234, output: 1234-****
  44. * input: 1234-1234-1234-1234, output: 1234-****-****-1234
  45. * </pre>
  46. */
  47. public static String maskingPhoneNumber(String source) {
  48. String[] sourceArr = source.split("-", -1);
  49.  
  50. String[] destination = new String[sourceArr.length];
  51.  
  52. if (sourceArr.length == 2) {
  53. destination[0] = sourceArr[0];
  54. destination[1] = "*";
  55. } else {
  56. for (int i = 0; i < destination.length; i++) {
  57. if (i == 0) {
  58. destination[i] = sourceArr[i];
  59. } else if (i == destination.length - 1) {
  60. destination[i] = sourceArr[i];
  61. } else {
  62. destination[i] = StringUtils.repeat("*", sourceArr[i].length());
  63. }
  64. }
  65. }
  66.  
  67. return StringUtils.join(destination, "-");
  68. }
  69. }
Add Comment
Please, Sign In to add comment