@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)); }
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 { 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 { 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); }
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); }
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; }