PasteUtils { public static String[] split(Object input) { if (input == null) { return null; } String temp = input.toString(); StringBuilder b = new StringBuilder(); for (int i = 0; i < temp.length(); i++) { String s = new String(new char[] { temp.charAt(i) }); if (StringUtils.isWhitespace(s)) { if (i == 0) { b.append("#"); } else { String t = new String(new char[] { temp.charAt(i - 1) }); if (StringUtils.isWhitespace(t)) { b.append("#"); } } } b.append(temp.charAt(i)); } String[] result = b.toString().replaceAll("\\s+", " ").split(" "); for (int i = 0; i < result.length; i++) { result[i] = result[i].replace('#', ' ').trim(); } return result; } private  PasteUtils(); static String[] split(Object input); static Integer toInt(String input); static String translateSeparators(String input, Locale locale); static String stripSeparators(String input);  }
@Test public void testSplit() { assertNull(PasteUtils.split(null)); String[] result = PasteUtils.split("3"); assertEquals("3", result[0]); result = PasteUtils.split("3 4 5"); assertEquals("3", result[0]); assertEquals("4", result[1]); assertEquals("5", result[2]); result = PasteUtils.split("3\t4\n5"); assertEquals("3", result[0]); assertEquals("4", result[1]); assertEquals("5", result[2]); assertTrue(StringUtils.isWhitespace("\t")); }
@Test public void testSplitComplex() { String[] result = PasteUtils.split("\t\t3"); assertEquals("", result[0]); assertEquals("", result[1]); assertEquals("3", result[2]); result = PasteUtils.split("\t\t\t3\t\t\t4"); assertEquals("", result[0]); assertEquals("", result[1]); assertEquals("", result[2]); assertEquals("3", result[3]); assertEquals("", result[4]); assertEquals("", result[5]); assertEquals("4", result[6]); result = PasteUtils.split(" 3 4"); assertEquals("", result[0]); assertEquals("", result[1]); assertEquals("", result[2]); assertEquals("3", result[3]); assertEquals("", result[4]); assertEquals("", result[5]); assertEquals("4", result[6]); }