You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/11/20 20:21:06 UTC
[commons-codec] branch master updated: Use a switch instead of a
cascading if-else.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git
The following commit(s) were added to refs/heads/master by this push:
new 0a4b0c6 Use a switch instead of a cascading if-else.
0a4b0c6 is described below
commit 0a4b0c69986d28db87568689bab3a62acb2e7bf5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Nov 20 15:21:01 2020 -0500
Use a switch instead of a cascading if-else.
---
.../commons/codec/language/ColognePhonetic.java | 29 ++++++++++++++--------
.../org/apache/commons/codec/language/Nysiis.java | 17 +++++++------
2 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/src/main/java/org/apache/commons/codec/language/ColognePhonetic.java b/src/main/java/org/apache/commons/codec/language/ColognePhonetic.java
index b1ad0a6..a7b0302 100644
--- a/src/main/java/org/apache/commons/codec/language/ColognePhonetic.java
+++ b/src/main/java/org/apache/commons/codec/language/ColognePhonetic.java
@@ -368,17 +368,24 @@ public class ColognePhonetic implements StringEncoder {
}
} else if (arrayContains(DTX, chr)) {
output.put('8');
- } else if (chr == 'R') {
- output.put('7');
- } else if (chr == 'L') {
- output.put('5');
- } else if (chr == 'M' || chr == 'N') {
- output.put('6');
- } else if (chr == 'H') {
- output.put(CHAR_IGNORE); // needed by put
- } else {
- // ignored; should not happen
- }
+ } else
+ switch (chr) {
+ case 'R':
+ output.put('7');
+ break;
+ case 'L':
+ output.put('5');
+ break;
+ case 'M':
+ case 'N':
+ output.put('6');
+ break;
+ case 'H':
+ output.put(CHAR_IGNORE); // needed by put
+ break;
+ default:
+ break;
+ }
lastChar = chr;
}
diff --git a/src/main/java/org/apache/commons/codec/language/Nysiis.java b/src/main/java/org/apache/commons/codec/language/Nysiis.java
index 28ae275..6b5d2ea 100644
--- a/src/main/java/org/apache/commons/codec/language/Nysiis.java
+++ b/src/main/java/org/apache/commons/codec/language/Nysiis.java
@@ -126,20 +126,23 @@ public class Nysiis implements StringEncoder {
}
// 2. Q -> G, Z -> S, M -> N
- if (curr == 'Q') {
+
+
+ // 3. KN -> NN else K -> C
+ switch (curr) {
+ case 'Q':
return CHARS_G;
- } else if (curr == 'Z') {
+ case 'Z':
return CHARS_S;
- } else if (curr == 'M') {
+ case 'M':
return CHARS_N;
- }
-
- // 3. KN -> NN else K -> C
- if (curr == 'K') {
+ case 'K':
if (next == 'N') {
return CHARS_NN;
}
return CHARS_C;
+ default:
+ break;
}
// 4. SCH -> SSS