@Test public void customizeHide() { Assert.assertEquals("135****4561", SensitiveUtils.customizeHide("13568794561", 3, 4, 4)); Assert.assertEquals("****4561", SensitiveUtils.customizeHide("13568794561", 0, 4, 4)); Assert.assertEquals("135****", SensitiveUtils.customizeHide("13568794561", 3, 0, 4)); Assert.assertEquals("135********", SensitiveUtils.customizeHide("13568794561", 3, 0, 8)); }
public String customizeHide(String data, int front, int tail, int hidden) { if (!Strings.hasText(data)) { return data; } String tmp = data.trim(); int length = tmp.length(); if (front < 0 || tail < 0 || hidden < 0 || front + tail > length) { return tmp; } int beginIndex = front - 1; int endIndex = length - tail; StringBuilder result = new StringBuilder(); if (beginIndex >= 0 && beginIndex < length) { result.append(tmp, 0, front); } for (int i = 0; i < hidden; i++) { result.append(Strings.ANY); } if (endIndex >= 0 && endIndex < length) { result.append(tmp.substring(endIndex)); } return result.toString(); }
SensitiveUtils { public String customizeHide(String data, int front, int tail, int hidden) { if (!Strings.hasText(data)) { return data; } String tmp = data.trim(); int length = tmp.length(); if (front < 0 || tail < 0 || hidden < 0 || front + tail > length) { return tmp; } int beginIndex = front - 1; int endIndex = length - tail; StringBuilder result = new StringBuilder(); if (beginIndex >= 0 && beginIndex < length) { result.append(tmp, 0, front); } for (int i = 0; i < hidden; i++) { result.append(Strings.ANY); } if (endIndex >= 0 && endIndex < length) { result.append(tmp.substring(endIndex)); } return result.toString(); } }
SensitiveUtils { public String customizeHide(String data, int front, int tail, int hidden) { if (!Strings.hasText(data)) { return data; } String tmp = data.trim(); int length = tmp.length(); if (front < 0 || tail < 0 || hidden < 0 || front + tail > length) { return tmp; } int beginIndex = front - 1; int endIndex = length - tail; StringBuilder result = new StringBuilder(); if (beginIndex >= 0 && beginIndex < length) { result.append(tmp, 0, front); } for (int i = 0; i < hidden; i++) { result.append(Strings.ANY); } if (endIndex >= 0 && endIndex < length) { result.append(tmp.substring(endIndex)); } return result.toString(); }  }
SensitiveUtils { public String customizeHide(String data, int front, int tail, int hidden) { if (!Strings.hasText(data)) { return data; } String tmp = data.trim(); int length = tmp.length(); if (front < 0 || tail < 0 || hidden < 0 || front + tail > length) { return tmp; } int beginIndex = front - 1; int endIndex = length - tail; StringBuilder result = new StringBuilder(); if (beginIndex >= 0 && beginIndex < length) { result.append(tmp, 0, front); } for (int i = 0; i < hidden; i++) { result.append(Strings.ANY); } if (endIndex >= 0 && endIndex < length) { result.append(tmp.substring(endIndex)); } return result.toString(); }  String nameHide(final String data); String idCardNoHide(String data); String bankCardNoHide(String data); String cellphoneHide(String data); String emailHide(String data); String defaultHide(String data); String customizeHide(String data, int front, int tail, int hidden); }
SensitiveUtils { public String customizeHide(String data, int front, int tail, int hidden) { if (!Strings.hasText(data)) { return data; } String tmp = data.trim(); int length = tmp.length(); if (front < 0 || tail < 0 || hidden < 0 || front + tail > length) { return tmp; } int beginIndex = front - 1; int endIndex = length - tail; StringBuilder result = new StringBuilder(); if (beginIndex >= 0 && beginIndex < length) { result.append(tmp, 0, front); } for (int i = 0; i < hidden; i++) { result.append(Strings.ANY); } if (endIndex >= 0 && endIndex < length) { result.append(tmp.substring(endIndex)); } return result.toString(); }  String nameHide(final String data); String idCardNoHide(String data); String bankCardNoHide(String data); String cellphoneHide(String data); String emailHide(String data); String defaultHide(String data); String customizeHide(String data, int front, int tail, int hidden);  }