SpellChecker { public static List<String> splitMixedCaseWord(String mixedCaseWord) { List<String> parts = new ArrayList<>(); int offs = 0; int adjacentCaps = 0; for (int i = 0; i < mixedCaseWord.length(); i++) { char ch = mixedCaseWord.charAt(i); if (i == 0) { adjacentCaps = Character.isUpperCase(ch) ? 1 : 0; } else { if (Character.isUpperCase(ch)) { if (adjacentCaps == 0) { parts.add(mixedCaseWord.substring(offs, i)); offs = i; } adjacentCaps++; } else if (adjacentCaps > 1) { parts.add(mixedCaseWord.substring(offs, i - 1)); offs = i - 1; adjacentCaps = 0; } } } parts.add(mixedCaseWord.substring(offs)); return parts; } SpellChecker();  SpellChecker(SpellDictionary dictionary);  SpellChecker(SpellDictionary dictionary, int threshold); void addDictionary(SpellDictionary dictionary); void setUserDictionary(SpellDictionary dictionary); Configuration getConfiguration(); void addSpellCheckListener(SpellCheckListener listener); void removeSpellCheckListener(SpellCheckListener listener); void reset(); @Deprecated String checkString(String text); final static boolean beginsAsINETWord(String word); static final boolean isINETWord(String word); void ignoreAll(String word); boolean addToDictionary(String word); boolean isIgnored(String word); boolean isCorrect(String word); List<Word> getSuggestions(String word, int threshold); void setCache(); void setCache(int size); static List<String> splitMixedCaseWord(String mixedCaseWord); final int checkSpelling(WordTokenizer tokenizer); static final int SPELLCHECK_OK; static final int SPELLCHECK_CANCEL; }
@Test public void testSplitMixedCaseWord_happyPath_notCamelCaseWord() { List<String> actual = SpellChecker.splitMixedCaseWord("archer"); Assert.assertEquals(1, actual.size()); Assert.assertEquals("archer", actual.get(0)); }
@Test public void testSplitMixedCaseWord_happyPath_allValidWords() { List<String> actual = SpellChecker.splitMixedCaseWord("camelCaseWord"); Assert.assertEquals(3, actual.size()); Assert.assertEquals("camel", actual.get(0)); Assert.assertEquals("Case", actual.get(1)); Assert.assertEquals("Word", actual.get(2)); }
@Test public void testSplitMixedCaseWord_happyPath_oneWordWithAllCaps() { List<String> actual = SpellChecker.splitMixedCaseWord("HTMLValidator"); Assert.assertEquals("Unexpected split word count, actual = " + String.join(", ", actual), 2, actual.size()); Assert.assertEquals("HTML", actual.get(0)); Assert.assertEquals("Validator", actual.get(1)); }
@Test public void testSplitMixedCaseWord_happyPath_multipleWordsWithAllCaps() { List<String> actual = SpellChecker.splitMixedCaseWord("HTMLToXMLValidator"); Assert.assertEquals("Unexpected split word count, actual = " + String.join(", ", actual), 4, actual.size()); Assert.assertEquals("HTML", actual.get(0)); Assert.assertEquals("To", actual.get(1)); Assert.assertEquals("XML", actual.get(2)); Assert.assertEquals("Validator", actual.get(3)); }
@Test public void testSplitMixedCaseWord_happyPath_multipleWordsWithAllCaps2() { List<String> actual = SpellChecker.splitMixedCaseWord("weDONTWantTODoTHIS"); Assert.assertEquals("Unexpected split word count, actual = " + String.join(", ", actual), 6, actual.size()); Assert.assertEquals("we", actual.get(0)); Assert.assertEquals("DONT", actual.get(1)); Assert.assertEquals("Want", actual.get(2)); Assert.assertEquals("TO", actual.get(3)); Assert.assertEquals("Do", actual.get(4)); Assert.assertEquals("THIS", actual.get(5)); }