@Test public void testSplit2() { Map<String, String[]> casesMap = new LinkedHashMap<String, String[]>(); casesMap.put("A;B", new String[]{"A", "B"}); casesMap.put("AA;BB", new String[]{"AA", "BB"}); casesMap.put(";B", new String[]{"", "B"}); casesMap.put(";BB", new String[]{"", "BB"}); casesMap.put("A;", new String[]{"A", ""}); casesMap.put("AA;", new String[]{"AA", ""}); casesMap.put(";", new String[]{"", ""}); casesMap.put("", new String[]{"", ""}); for (Map.Entry<String, String[]> e : casesMap.entrySet()) { String str = e.getKey(); String[] expected = e.getValue(); String[] result = EngineUtil.split2(str, ';'); assertEquals(2, result.length); assertEquals(expected[0], result[0]); assertEquals(expected[1], result[1]); } String[] tokens = EngineUtil.split2(null, ';'); assertEquals("", tokens[0]); assertEquals("", tokens[1]); }
public static String[] split2(final String str, final char delim) { String[] result = {"", ""}; if (str != null) { int ix = str.indexOf(delim); if (ix >= 0) { result[0] = str.substring(0, ix); result[1] = str.substring(ix + 1); } else { result[0] = str; } } return result; }
EngineUtil { public static String[] split2(final String str, final char delim) { String[] result = {"", ""}; if (str != null) { int ix = str.indexOf(delim); if (ix >= 0) { result[0] = str.substring(0, ix); result[1] = str.substring(ix + 1); } else { result[0] = str; } } return result; } }
EngineUtil { public static String[] split2(final String str, final char delim) { String[] result = {"", ""}; if (str != null) { int ix = str.indexOf(delim); if (ix >= 0) { result[0] = str.substring(0, ix); result[1] = str.substring(ix + 1); } else { result[0] = str; } } return result; } private  EngineUtil(); }
EngineUtil { public static String[] split2(final String str, final char delim) { String[] result = {"", ""}; if (str != null) { int ix = str.indexOf(delim); if (ix >= 0) { result[0] = str.substring(0, ix); result[1] = str.substring(ix + 1); } else { result[0] = str; } } return result; } private  EngineUtil(); static boolean hasText(String text); static String[] split(final String str, final char delim, final int maxTokens); static String[] split(final String str, final char delim); static String[] split2(final String str, final char delim); static String trimAllWhitespace(final String str); }
EngineUtil { public static String[] split2(final String str, final char delim) { String[] result = {"", ""}; if (str != null) { int ix = str.indexOf(delim); if (ix >= 0) { result[0] = str.substring(0, ix); result[1] = str.substring(ix + 1); } else { result[0] = str; } } return result; } private  EngineUtil(); static boolean hasText(String text); static String[] split(final String str, final char delim, final int maxTokens); static String[] split(final String str, final char delim); static String[] split2(final String str, final char delim); static String trimAllWhitespace(final String str);  }