Skip to content

Commit 0a4b0c6

Browse files
committed
Use a switch instead of a cascading if-else.
1 parent c4e813f commit 0a4b0c6

2 files changed

Lines changed: 28 additions & 18 deletions

File tree

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,24 @@ public String colognePhonetic(final String text) {
368368
}
369369
} else if (arrayContains(DTX, chr)) {
370370
output.put('8');
371-
} else if (chr == 'R') {
372-
output.put('7');
373-
} else if (chr == 'L') {
374-
output.put('5');
375-
} else if (chr == 'M' || chr == 'N') {
376-
output.put('6');
377-
} else if (chr == 'H') {
378-
output.put(CHAR_IGNORE); // needed by put
379-
} else {
380-
// ignored; should not happen
381-
}
371+
} else
372+
switch (chr) {
373+
case 'R':
374+
output.put('7');
375+
break;
376+
case 'L':
377+
output.put('5');
378+
break;
379+
case 'M':
380+
case 'N':
381+
output.put('6');
382+
break;
383+
case 'H':
384+
output.put(CHAR_IGNORE); // needed by put
385+
break;
386+
default:
387+
break;
388+
}
382389

383390
lastChar = chr;
384391
}

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,23 @@ private static char[] transcodeRemaining(final char prev, final char curr, final
126126
}
127127

128128
// 2. Q -> G, Z -> S, M -> N
129-
if (curr == 'Q') {
129+
130+
131+
// 3. KN -> NN else K -> C
132+
switch (curr) {
133+
case 'Q':
130134
return CHARS_G;
131-
} else if (curr == 'Z') {
135+
case 'Z':
132136
return CHARS_S;
133-
} else if (curr == 'M') {
137+
case 'M':
134138
return CHARS_N;
135-
}
136-
137-
// 3. KN -> NN else K -> C
138-
if (curr == 'K') {
139+
case 'K':
139140
if (next == 'N') {
140141
return CHARS_NN;
141142
}
142143
return CHARS_C;
144+
default:
145+
break;
143146
}
144147

145148
// 4. SCH -> SSS

0 commit comments

Comments
 (0)