AlgoBox { public static String first_N_Char(String sInput, int nb) { if (sInput == null || "".equals(sInput)) { return ""; } if (nb < 0) { return sInput; } int sInputCPCount = sInput.codePointCount(0, sInput.length()); if (sInputCPCount < nb) { nb = sInputCPCount; } return sInput.substring(0, sInput.offsetByCodePoints(0, nb)); }  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 testFirst_N_Char() { assertEquals(BLANK_STR, AlgoBox.first_N_Char(null, 1)); assertEquals(TEST_STR, AlgoBox.first_N_Char(TEST_STR, 4)); assertEquals(TEST_STR, AlgoBox.first_N_Char(TEST_STR, 5)); assertEquals(TEST_STR, AlgoBox.first_N_Char(TEST_STR, -1)); assertEquals(BLANK_STR, AlgoBox.first_N_Char(BLANK_STR, 1)); assertEquals("n", AlgoBox.first_N_Char(NULL_STR, 1)); assertEquals(QUO_STR, AlgoBox.first_N_Char(QUO_STR, 1)); assertEquals(" ", AlgoBox.first_N_Char(" abc", 3)); assertEquals(MIXTD_SURROGATEPAIR, AlgoBox.first_N_Char(MIXTD_SURROGATEPAIR, 10)); assertEquals("𠀀𠀐", AlgoBox.first_N_Char(MIXTD_SURROGATEPAIR, 2)); assertEquals("𠀀𠀐我𠀑a", AlgoBox.first_N_Char(MIXTD_SURROGATEPAIR, 5)); assertEquals("リ", AlgoBox.first_N_Char(JAPANESE1_STR, 1)); assertEquals("リン", AlgoBox.first_N_Char(JAPANESE2_STR, 2)); assertEquals("リンゴ を", AlgoBox.first_N_Char(JAPANESE3_STR, 5)); }