StringUtil { public static String toLikeCondition(String condition) { if (condition == null) { return null; } final char esc = (LIKE_ESC_CHAR.toCharArray())[0]; StringBuilder result = new StringBuilder(); for (int i = 0; i < condition.length(); i++) { char c = condition.charAt(i); if (c == esc) { result.append(esc); result.append(esc); } else if (c == '%' || c == '_' || c == '＿' || c == '％') { result.append(esc); result.append(c); } else { result.append(c); } } result.append('%'); return result.toString(); }  static boolean isWhitespace(char c); static boolean isZenHankakuSpace(char c); static String rtrim(String str); static String ltrim(String str); static String trim(String str); static String rtrimZ(String str); static String ltrimZ(String str); static String trimZ(String str); static String toShortClassName(String longClassName); static String getExtension(String name); static String toHexString(byte[] byteArray, String delim); static String capitalizeInitial(String str); static String[] parseCSV(String csvString); static String[] parseCSV(String csvString, String escapeString); static String dump(Map<?, ?> map); static String getArraysStr(Object[] arrayObj); static String hankakuToZenkaku(String value); static String zenkakuToHankaku(String value); static String filter(String str); static String toLikeCondition(String condition); static int getByteLength(String value, String encoding); static final String LINE_SEP; static final String LIKE_ESC_CHAR; }
@Test public void testToLikeCondition01() throws Exception { String input = "a%"; String result = StringUtil.toLikeCondition(input); assertEquals("a~%%", result); }
@Test public void testToLikeCondition02() throws Exception { String input = "~"; String result = StringUtil.toLikeCondition(input); assertEquals("~~%", result); }
@Test public void testToLikeCondition03() throws Exception { String input = "_a%"; String result = StringUtil.toLikeCondition(input); assertEquals("~_a~%%", result); }
@Test public void testToLikeCondition04() throws Exception { String input = "aa"; String result = StringUtil.toLikeCondition(input); assertEquals("aa%", result); }
@Test public void testToLikeCondition05() throws Exception { String input = null; String result = StringUtil.toLikeCondition(input); assertNull(result); }
@Test public void testToLikeCondition06() throws Exception { String input = ""; String result = StringUtil.toLikeCondition(input); assertEquals("%", result); }
@Test public void testToLikeCondition07() throws Exception { String input = "％"; String result = StringUtil.toLikeCondition(input); assertEquals("~％%", result); }
@Test public void testToLikeCondition08() throws Exception { String input = "＿"; String result = StringUtil.toLikeCondition(input); assertEquals("~＿%", result); }