AlgoBox { public static String pick_Char(String sInput, String pattern) { if (sInput == null || "".equals(sInput.trim())) { return ""; } if (pattern == null || "".equals(pattern.trim())) { return ""; } String d_pattern = "^[0-9--;]*"; if (!pattern.matches(d_pattern)) { return ""; } StringBuilder sb = new StringBuilder(); String[] arr_1 = pattern.split(";"); for (String valueOf_arr_1 : arr_1) { if (!"".equals(valueOf_arr_1)) { String[] arr_2 = valueOf_arr_1.split("-"); int len_arr_2 = arr_2.length; if (len_arr_2 == 2) { if ("".equals(arr_2[0]) || "".equals(arr_2[1])) { ; } else { sb.append(subStr(sInput, arr_2[0] + ";" + arr_2[1])); } } else if (len_arr_2 == 1) { if (Integer.parseInt(arr_2[0]) < sInput.length()) { int index = Integer.parseInt(arr_2[0]); int startOffset = sInput.offsetByCodePoints(0, index); String substring = sInput.substring(startOffset, sInput.offsetByCodePoints(startOffset, 1)); sb.append(substring); } } else { ; } } } return sb.toString(); }  static void main(String[] args); static String pick_Char(String sInput, String pattern); static String first_N_Consonants(String sInput, int nb); static String first_N_Vowels(String sInput, int nb); static String subStr(String sInput, String pattern); static String first_N_Char(String sInput, int nb); static String last_N_Char(String sInput, int nb); static String first_N_Char_EW(String sInput, int nb); static String first_Char_EW(String sInput); static String soundex(String sInput); static String doublemetaphone(String sInput); static String metaphone(String sInput); static String add_Left_Char(String sInput, String position); static String add_Right_Char(String sInput, String position); static String removeDiacriticalMarks(String sInput); static String exact(String sInput); static String useDefault(String sInput, String insteadOf); static String lowerCase(String sInput); static String upperCase(String sInput); static String removeDMAndLowerCase(String sInput); static String removeDMAndUpperCase(String sInput); static String fingerPrintKey(String sInput); static String nGramKey(String sInput); static String colognePhonetic(String sInput);  }
@Test public void testPick_Char() { assertEquals(BLANK_STR, AlgoBox.pick_Char(TEST_STR, BLANK_STR)); assertEquals(BLANK_STR, AlgoBox.pick_Char(TEST_STR, null)); assertEquals(BLANK_STR, AlgoBox.pick_Char(BLANK_STR, "test")); assertEquals(BLANK_STR, AlgoBox.pick_Char(null, "test")); assertEquals(BLANK_STR, AlgoBox.pick_Char(TEST_STR, "test")); assertEquals(BLANK_STR, AlgoBox.pick_Char(TEST_STR, "tes")); assertEquals("bcdf", AlgoBox.pick_Char("abcdef", "1;2-4;5")); assertEquals("etest", AlgoBox.pick_Char(TEST_STR, "1-2;40;0-5")); assertEquals("e", AlgoBox.pick_Char("Test test", "1-2")); assertEquals(BLANK_STR, AlgoBox.pick_Char(SPACE_STR, BLANK_STR)); assertEquals(BLANK_STR, AlgoBox.pick_Char(TEST_STR, SPACE_STR)); assertEquals(BLANK_STR, AlgoBox.pick_Char(QUO_STR, "1")); assertEquals(BLANK_STR, AlgoBox.pick_Char(MIXTD_SURROGATEPAIR, BLANK_STR)); assertEquals("𠀐", AlgoBox.pick_Char(MIXTD_SURROGATEPAIR, "1")); assertEquals("我", AlgoBox.pick_Char(MIXTD_SURROGATEPAIR, "2")); assertEquals("𠀑", AlgoBox.pick_Char(MIXTD_SURROGATEPAIR, "3")); assertEquals("a", AlgoBox.pick_Char(MIXTD_SURROGATEPAIR, "4")); assertEquals("ン", AlgoBox.pick_Char(JAPANESE1_STR, "1")); assertEquals(BLANK_STR, AlgoBox.pick_Char(JAPANESE1_STR, "リ")); }