Consider Regex
###Consider Regex
YourYour WordChecker
class has numerous helper methods that all bubble up to just pattern matching. This is exactly why Regex exists, Java has Pattern
and Matcher
classes in java.util.regex
that can help you do this fairly succinctly. For example, to check for only vowels or only consonants you can have this:
public class WordChecker {
private static final Pattern VOWEL_PATTERN = Pattern.compile("^[aeiouy]+$");
private static final Pattern CONSONANT_PATTERN = Pattern.compile("^[bcdfghjklmnpqrstvwxz]+$");
private static boolean onlyVowels(String input) {
return VOWEL_PATTERN.matcher(input).matches();
}
private static boolean onlyConsonants(String input) {
return CONSONANT_PATTERN.matcher(input).matches();
}
}
Do note, however, that I make these methods static, so call them with WordChecker.onlyVowels("...");
As it stands all the content consists of helper functions independent of any particular implementation so being static fits well.
For further reference look at the documentation here.
Use meaningful names; avoid deceptive names.
###Use meaningful names; avoid deceptive names. Naming things can be surprisingly difficult especially when striving to keep it short and indicate full meaning, yet only returning 0 or 1 seems completely unexpected from a method that is meant to return the similarity between two things (similarity implies a multitude of outputs on a range, the way you apply it here essentially turn it into a boolean).
Leverage the API
##Leverage the API
OneOne of the premier merits of using any language in particular is the available libraries. Unless this was done as an exercise the majority of the Dictionary
class can be eliminated by using a HashMap.
###Consider Regex
Your WordChecker
class has numerous helper methods that all bubble up to just pattern matching. This is exactly why Regex exists, Java has Pattern
and Matcher
classes in java.util.regex
that can help you do this fairly succinctly. For example, to check for only vowels or only consonants you can have this:
public class WordChecker {
private static final Pattern VOWEL_PATTERN = Pattern.compile("^[aeiouy]+$");
private static final Pattern CONSONANT_PATTERN = Pattern.compile("^[bcdfghjklmnpqrstvwxz]+$");
private static boolean onlyVowels(String input) {
return VOWEL_PATTERN.matcher(input).matches();
}
private static boolean onlyConsonants(String input) {
return CONSONANT_PATTERN.matcher(input).matches();
}
}
Do note, however, that I make these methods static, so call them with WordChecker.onlyVowels("...");
As it stands all the content consists of helper functions independent of any particular implementation so being static fits well.
For further reference look at the documentation here.
###Use meaningful names; avoid deceptive names. Naming things can be surprisingly difficult especially when striving to keep it short and indicate full meaning, yet only returning 0 or 1 seems completely unexpected from a method that is meant to return the similarity between two things (similarity implies a multitude of outputs on a range, the way you apply it here essentially turn it into a boolean).
##Leverage the API
One of the premier merits of using any language in particular is the available libraries. Unless this was done as an exercise the majority of the Dictionary
class can be eliminated by using a HashMap.
Consider Regex
Your WordChecker
class has numerous helper methods that all bubble up to just pattern matching. This is exactly why Regex exists, Java has Pattern
and Matcher
classes in java.util.regex
that can help you do this fairly succinctly. For example, to check for only vowels or only consonants you can have this:
public class WordChecker {
private static final Pattern VOWEL_PATTERN = Pattern.compile("^[aeiouy]+$");
private static final Pattern CONSONANT_PATTERN = Pattern.compile("^[bcdfghjklmnpqrstvwxz]+$");
private static boolean onlyVowels(String input) {
return VOWEL_PATTERN.matcher(input).matches();
}
private static boolean onlyConsonants(String input) {
return CONSONANT_PATTERN.matcher(input).matches();
}
}
Do note, however, that I make these methods static, so call them with WordChecker.onlyVowels("...");
As it stands all the content consists of helper functions independent of any particular implementation so being static fits well.
For further reference look at the documentation here.
Use meaningful names; avoid deceptive names.
Naming things can be surprisingly difficult especially when striving to keep it short and indicate full meaning, yet only returning 0 or 1 seems completely unexpected from a method that is meant to return the similarity between two things (similarity implies a multitude of outputs on a range, the way you apply it here essentially turn it into a boolean).
Leverage the API
One of the premier merits of using any language in particular is the available libraries. Unless this was done as an exercise the majority of the Dictionary
class can be eliminated by using a HashMap.
###Consider Regex
Your WordChecker
class has numerous helper methods that all bubble up to just pattern matching. This is exactly why Regex exists, Java has Pattern
and Matcher
classes in java.util.regex
that can help you do this fairly succinctly. For example, to check for only vowels or only consonants you can have this:
public class WordChecker {
private static final Pattern VOWEL_PATTERN = Pattern.compile("^[aeiouy]+$");
private static final Pattern CONSONANT_PATTERN = Pattern.compile("^[bcdfghjklmnpqrstvwxz]+$");
private static boolean onlyVowels(String input) {
return VOWEL_PATTERN.matcher(input).matches();
}
private static boolean onlyConsonants(String input) {
return CONSONANT_PATTERN.matcher(input).matches();
}
}
Do note, however, that I make these methods static, so call them with WordChecker.onlyVowels("...");
As it stands all the content consists of helper functions independent of any particular implementation so being static fits well.
For further reference look at the documentation here.
###Use meaningful names; avoid deceptive names. Naming things can be surprisingly difficult especially when striving to keep it short and indicate full meaning, yet only returning 0 or 1 seems completely unexpected from a method that is meant to return the similarity between two things (similarity implies a multitude of outputs on a range, the way you apply it here essentially turn it into a boolean).
##Leverage the API
One of the premier merits of using any language in particular is the available libraries. Unless this was done as an exercise the majority of the Dictionary
class can be eliminated by using a HashMap .
###Consider Regex
Your WordChecker
class has numerous helper methods that all bubble up to just pattern matching. This is exactly why Regex exists, Java has Pattern
and Matcher
classes in java.util.regex
that can help you do this fairly succinctly. For example, to check for only vowels or only consonants you can have this:
public class WordChecker {
private static final Pattern VOWEL_PATTERN = Pattern.compile("^[aeiouy]+$");
private static final Pattern CONSONANT_PATTERN = Pattern.compile("^[bcdfghjklmnpqrstvwxz]+$");
private static boolean onlyVowels(String input) {
return VOWEL_PATTERN.matcher(input).matches();
}
private static boolean onlyConsonants(String input) {
return CONSONANT_PATTERN.matcher(input).matches();
}
}
Do note, however, that I make these methods static, so call them with WordChecker.onlyVowels("...");
As it stands all the content consists of helper functions independent of any particular implementation so being static fits well.
For further reference look at the documentation here.
###Use meaningful names; avoid deceptive names. Naming things can be surprisingly difficult especially when striving to keep it short and indicate full meaning, yet only returning 0 or 1 seems completely unexpected from a method that is meant to return the similarity between two things (similarity implies a multitude of outputs on a range, the way you apply it here essentially turn it into a boolean).
###Consider Regex
Your WordChecker
class has numerous helper methods that all bubble up to just pattern matching. This is exactly why Regex exists, Java has Pattern
and Matcher
classes in java.util.regex
that can help you do this fairly succinctly. For example, to check for only vowels or only consonants you can have this:
public class WordChecker {
private static final Pattern VOWEL_PATTERN = Pattern.compile("^[aeiouy]+$");
private static final Pattern CONSONANT_PATTERN = Pattern.compile("^[bcdfghjklmnpqrstvwxz]+$");
private static boolean onlyVowels(String input) {
return VOWEL_PATTERN.matcher(input).matches();
}
private static boolean onlyConsonants(String input) {
return CONSONANT_PATTERN.matcher(input).matches();
}
}
Do note, however, that I make these methods static, so call them with WordChecker.onlyVowels("...");
As it stands all the content consists of helper functions independent of any particular implementation so being static fits well.
For further reference look at the documentation here.
###Use meaningful names; avoid deceptive names. Naming things can be surprisingly difficult especially when striving to keep it short and indicate full meaning, yet only returning 0 or 1 seems completely unexpected from a method that is meant to return the similarity between two things (similarity implies a multitude of outputs on a range, the way you apply it here essentially turn it into a boolean).
##Leverage the API
One of the premier merits of using any language in particular is the available libraries. Unless this was done as an exercise the majority of the Dictionary
class can be eliminated by using a HashMap .
###Consider Regex
Your WordChecker
class has numerous helper methods that all bubble up to just pattern matching. This is exactly why Regex exists, Java has Pattern
and Matcher
classes in java.util.regex
that can help you do this fairly succinctly. For example, to check for only vowels or only consonants you can have this:
public class WordChecker {
private static final Pattern VOWEL_PATTERN = Pattern.compile("^[aeiouy]+$");
private static final Pattern CONSONANT_PATTERN = Pattern.compile("^[bcdfghjklmnpqrstvwxz]+$");
private static boolean onlyVowels(String input) {
return VOWEL_PATTERN.matcher(input).matches();
}
private static boolean onlyConsonants(String input) {
return CONSONANT_PATTERN.matcher(input).matches();
}
}
Do note, however, that I make these methods static, so call them with WordChecker.onlyVowels("...");
As it stands all the content consists of helper functions independent of any particular implementation so being static fits well.
For further reference look at the documentation here.
###Use meaningful names; avoid deceptive names. Naming things can be surprisingly difficult especially when striving to keep it short and indicate full meaning, yet only returning 0 or 1 seems completely unexpected from a method that is meant to return the similarity between two things (similarity implies a multitude of outputs on a range, the way you apply it here essentially turn it into a boolean).
###Consider Regex
Your WordChecker
class has numerous helper methods that all bubble up to just pattern matching. This is exactly why Regex exists, Java has Pattern
and Matcher
classes in java.util.regex
that can help you do this fairly succinctly. For example, to check for only vowels or only consonants you can have this:
public class WordChecker {
private static final Pattern VOWEL_PATTERN = Pattern.compile("^[aeiouy]+$");
private static final Pattern CONSONANT_PATTERN = Pattern.compile("^[bcdfghjklmnpqrstvwxz]+$");
private static boolean onlyVowels(String input) {
return VOWEL_PATTERN.matcher(input).matches();
}
private static boolean onlyConsonants(String input) {
return CONSONANT_PATTERN.matcher(input).matches();
}
}
Do note, however, that I make these methods static, so call them with WordChecker.onlyVowels("...");
As it stands all the content consists of helper functions independent of any particular implementation so being static fits well.
For further reference look at the documentation here.
###Consider Regex
Your WordChecker
class has numerous helper methods that all bubble up to just pattern matching. This is exactly why Regex exists, Java has Pattern
and Matcher
classes in java.util.regex
that can help you do this fairly succinctly. For example, to check for only vowels or only consonants you can have this:
public class WordChecker {
private static final Pattern VOWEL_PATTERN = Pattern.compile("^[aeiouy]+$");
private static final Pattern CONSONANT_PATTERN = Pattern.compile("^[bcdfghjklmnpqrstvwxz]+$");
private static boolean onlyVowels(String input) {
return VOWEL_PATTERN.matcher(input).matches();
}
private static boolean onlyConsonants(String input) {
return CONSONANT_PATTERN.matcher(input).matches();
}
}
Do note, however, that I make these methods static, so call them with WordChecker.onlyVowels("...");
As it stands all the content consists of helper functions independent of any particular implementation so being static fits well.
For further reference look at the documentation here.
###Use meaningful names; avoid deceptive names. Naming things can be surprisingly difficult especially when striving to keep it short and indicate full meaning, yet only returning 0 or 1 seems completely unexpected from a method that is meant to return the similarity between two things (similarity implies a multitude of outputs on a range, the way you apply it here essentially turn it into a boolean).