Skip to content

Commit 8ee878b

Browse files
CODEC-299 - Improve control flow (#83)
1 parent 8549903 commit 8ee878b

3 files changed

Lines changed: 7 additions & 17 deletions

File tree

src/main/java/org/apache/commons/codec/language/DaitchMokotoffSoundex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public String[] getReplacements(final String context, final boolean atStart) {
182182
}
183183

184184
final int nextIndex = getPatternLength();
185-
final boolean nextCharIsVowel = nextIndex < context.length() ? isVowel(context.charAt(nextIndex)) : false;
185+
final boolean nextCharIsVowel = nextIndex < context.length() && isVowel(context.charAt(nextIndex));
186186
if (nextCharIsVowel) {
187187
return replacementBeforeVowel;
188188
}

src/main/java/org/apache/commons/codec/language/DoubleMetaphone.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -802,10 +802,7 @@ private boolean conditionCH0(final String value, final int index) {
802802
!contains(value, index + 1, 3, "HOR", "HYM", "HIA", "HEM")) {
803803
return false;
804804
}
805-
if (contains(value, 0, 5, "CHORE")) {
806-
return false;
807-
}
808-
return true;
805+
return !contains(value, 0, 5, "CHORE");
809806
}
810807

811808
/**
@@ -827,12 +824,9 @@ private boolean conditionL0(final String value, final int index) {
827824
contains(value, index - 1, 4, "ILLO", "ILLA", "ALLE")) {
828825
return true;
829826
}
830-
if ((contains(value, value.length() - 2, 2, "AS", "OS") ||
831-
contains(value, value.length() - 1, 1, "A", "O")) &&
832-
contains(value, index - 1, 4, "ALLE")) {
833-
return true;
834-
}
835-
return false;
827+
return (contains(value, value.length() - 2, 2, "AS", "OS") ||
828+
contains(value, value.length() - 1, 1, "A", "O")) &&
829+
contains(value, index - 1, 4, "ALLE");
836830
}
837831

838832
/**

src/main/java/org/apache/commons/codec/language/Metaphone.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,8 @@ public String metaphone(final String txt) {
224224
regionMatch(local, n, "GNED") ) ) {
225225
break; // silent G
226226
}
227-
if (isPreviousChar(local, n, 'G')) {
228-
// NOTE: Given that duplicated chars are removed, I don't see how this can ever be true
229-
hard = true;
230-
} else {
231-
hard = false;
232-
}
227+
// NOTE: Given that duplicated chars are removed, I don't see how this can ever be true
228+
hard = isPreviousChar(local, n, 'G');
233229
if (!isLastChar(wdsz, n) &&
234230
FRONTV.indexOf(local.charAt(n + 1)) >= 0 &&
235231
!hard) {

0 commit comments

Comments
 (0)