@Test public void testOverlay_StringStringIntInt() { assertNull(StringUtils.overlay(null, null, 2, 4)); assertNull(StringUtils.overlay(null, null, -2, -4)); assertEquals("", StringUtils.overlay("", null, 0, 0)); assertEquals("", StringUtils.overlay("", "", 0, 0)); assertEquals("zzzz", StringUtils.overlay("", "zzzz", 0, 0)); assertEquals("zzzz", StringUtils.overlay("", "zzzz", 2, 4)); assertEquals("zzzz", StringUtils.overlay("", "zzzz", -2, -4)); assertEquals("abef", StringUtils.overlay("abcdef", null, 2, 4)); assertEquals("abef", StringUtils.overlay("abcdef", null, 4, 2)); assertEquals("abef", StringUtils.overlay("abcdef", "", 2, 4)); assertEquals("abef", StringUtils.overlay("abcdef", "", 4, 2)); assertEquals("abzzzzef", StringUtils.overlay("abcdef", "zzzz", 2, 4)); assertEquals("abzzzzef", StringUtils.overlay("abcdef", "zzzz", 4, 2)); assertEquals("zzzzef", StringUtils.overlay("abcdef", "zzzz", -1, 4)); assertEquals("zzzzef", StringUtils.overlay("abcdef", "zzzz", 4, -1)); assertEquals("zzzzabcdef", StringUtils.overlay("abcdef", "zzzz", -2, -1)); assertEquals("zzzzabcdef", StringUtils.overlay("abcdef", "zzzz", -1, -2)); assertEquals("abcdzzzz", StringUtils.overlay("abcdef", "zzzz", 4, 10)); assertEquals("abcdzzzz", StringUtils.overlay("abcdef", "zzzz", 10, 4)); assertEquals("abcdefzzzz", StringUtils.overlay("abcdef", "zzzz", 8, 10)); assertEquals("abcdefzzzz", StringUtils.overlay("abcdef", "zzzz", 10, 8)); }
/** * Deidentify left. * * @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; if (size > str.length()) { repeat = str.length(); } else { repeat = size; } return StringUtils.overlay(str, StringUtils.repeat('*', repeat), 0, size); }
/** * Deidentify from left. * * @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; if (size > str.length()) { repeat = 0; } else { repeat = str.length() - size; } return StringUtils.overlay(str, StringUtils.repeat('*', repeat), size, end); }
/** * Deidentify from right. * * @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); }
/** * Deidentify right. * * @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; if (size > str.length()) { repeat = str.length(); } else { repeat = size; } return StringUtils.overlay(str, StringUtils.repeat('*', repeat), end - size, end); }
/** * Deidentify middle. * * @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); }