StringUtils { public static String[] splitByWholeSeparator(String str, String separator) { return splitByWholeSeparatorWorker(str, separator, -1, false); }  static String[] split(String str); static String[] split(String str, String separatorChars); static String[] split(String str, char separatorChar); static String[] split(String str, String separatorChars, int max); static String[] splitByWholeSeparator(String str, String separator); static String[] splitByWholeSeparator(String str, String separator, int max); static boolean hasText(String str); static boolean hasText(CharSequence str); static boolean hasLength(CharSequence str); static boolean hasLength(String str); static String replace(String s, Map<String, Object> map); static String replace(String s, Object... objs); static String replaceStr(String s, String sub, String with); static String escapeXML(String str); static String unicodeToString(String s); static String getFilenameExtension(String path); static String getFilename(String path); static byte[] getUtf8Bytes(String string); static byte[] getBytes(String string); static int toInt(String string, int from); static void append(StringBuilder buf, byte b, int base); static void append2digits(StringBuilder buf, int i); static String asciiToLowerCase(String s); static String normalizeCharset(String s); static String normalizeCharset(String s, int offset, int length); static boolean isHex(String str, int offset, int length); static String truncate(String str, int maxSize); static final String EMPTY; static final String[] EMPTY_STRING_ARRAY; }
@Test void testSplitByWholeString_StringStringBoolean() { assertArrayEquals(null, StringUtils.splitByWholeSeparator(null, ".")); assertEquals(0, StringUtils.splitByWholeSeparator("", ".").length); final String stringToSplitOnNulls = "ab de fg"; final String[] splitOnNullExpectedResults = {"ab", "de", "fg"}; final String[] splitOnNullResults = StringUtils.splitByWholeSeparator(stringToSplitOnNulls, null); assertEquals(splitOnNullExpectedResults.length, splitOnNullResults.length); for (int i = 0; i < splitOnNullExpectedResults.length; i += 1) { assertEquals(splitOnNullExpectedResults[i], splitOnNullResults[i]); } final String stringToSplitOnCharactersAndString = "abstemiouslyaeiouyabstemiously"; final String[] splitOnStringExpectedResults = {"abstemiously", "abstemiously"}; final String[] splitOnStringResults = StringUtils.splitByWholeSeparator(stringToSplitOnCharactersAndString, "aeiouy"); assertEquals(splitOnStringExpectedResults.length, splitOnStringResults.length); for (int i = 0; i < splitOnStringExpectedResults.length; i += 1) { assertEquals(splitOnStringExpectedResults[i], splitOnStringResults[i]); } final String[] splitWithMultipleSeparatorExpectedResults = {"ab", "cd", "ef"}; final String[] splitWithMultipleSeparator = StringUtils.splitByWholeSeparator("ab:cd::ef", ":"); assertEquals(splitWithMultipleSeparatorExpectedResults.length, splitWithMultipleSeparator.length); for (int i = 0; i < splitWithMultipleSeparatorExpectedResults.length; i++) { assertEquals(splitWithMultipleSeparatorExpectedResults[i], splitWithMultipleSeparator[i]); } }
@Test void testSplitByWholeString_StringStringBooleanInt() { assertArrayEquals(null, StringUtils.splitByWholeSeparator(null, ".", 3)); assertEquals(0, StringUtils.splitByWholeSeparator("", ".", 3).length); final String stringToSplitOnNulls = "ab de fg"; final String[] splitOnNullExpectedResults = {"ab", "de fg"}; final String[] splitOnNullResults = StringUtils.splitByWholeSeparator(stringToSplitOnNulls, null, 2); assertEquals(splitOnNullExpectedResults.length, splitOnNullResults.length); for (int i = 0; i < splitOnNullExpectedResults.length; i += 1) { assertEquals(splitOnNullExpectedResults[i], splitOnNullResults[i]); } final String stringToSplitOnCharactersAndString = "abstemiouslyaeiouyabstemiouslyaeiouyabstemiously"; final String[] splitOnStringExpectedResults = {"abstemiously", "abstemiouslyaeiouyabstemiously"}; final String[] splitOnStringResults = StringUtils.splitByWholeSeparator(stringToSplitOnCharactersAndString, "aeiouy", 2); assertEquals(splitOnStringExpectedResults.length, splitOnStringResults.length); for (int i = 0; i < splitOnStringExpectedResults.length; i++) { assertEquals(splitOnStringExpectedResults[i], splitOnStringResults[i]); } }