mirror of
https://github.com/danbulant/introductionToProgramming
synced 2026-05-19 20:38:36 +00:00
23 lines
No EOL
747 B
Java
23 lines
No EOL
747 B
Java
import java.util.Arrays;
|
|
import java.util.HashSet;
|
|
|
|
class JavaSpellchecker implements Spellchecker {
|
|
public HashSet<String> words = new HashSet<String>(Arrays.asList("I", "Java", "Factory", "Extended"));
|
|
|
|
public boolean isWord(String word) {
|
|
// we could use slices but they copy it char for char anyway
|
|
var buf = "";
|
|
for (var i = 0; i < word.length(); i++) {
|
|
var ch = word.charAt(i);
|
|
if (Character.isUpperCase(ch)) {
|
|
if (!buf.isEmpty() && !words.contains(buf))
|
|
return false;
|
|
buf = "";
|
|
}
|
|
buf += ch;
|
|
}
|
|
if (!buf.isEmpty() && !words.contains(buf))
|
|
return false;
|
|
return true;
|
|
};
|
|
} |