Skip to content

Commit 124b73f

Browse files
author
Timothy O'Brien
committed
Removed all checkstyle violations from Base64, and the
language encoders. Most of the checkstyle violations fixed were violations dealing with the placement of operators on a newline instead of on the end of the previous line. In addition to the checkstyle fixes, DoubleMetaphone now handles two cases C with a Cedilla and N with a tilde (ene). git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/codec/trunk@130214 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1078329 commit 124b73f

1 file changed

Lines changed: 35 additions & 82 deletions

File tree

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

Lines changed: 35 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
* </ul>
7373
*
7474
* @author <a href="mailto:ben@walstrum.com">Benjamin Walstrum</a>
75-
* @version $Id: DoubleMetaphone.java,v 1.11 2003/10/05 21:45:48 tobrien Exp $
75+
* @version $Id: DoubleMetaphone.java,v 1.12 2003/10/12 19:56:13 tobrien Exp $
7676
*/
7777
public class DoubleMetaphone implements StringEncoder {
7878

@@ -146,16 +146,13 @@ public String doubleMetaphone(String value, boolean alternate) {
146146
break;
147147
case 'B':
148148
result.append('P');
149-
index = charAt(value, index + 1) == 'B'
150-
? index + 2
151-
: index + 1;
149+
index = charAt(value, index + 1) == 'B' ? index + 2 : index + 1;
152150
break;
153-
// FIXME: Removed support for this character until
154-
// Unicode code is found.
155-
/* case 'Ç':
151+
case '\u00C7':
152+
// A C with a Cedilla
156153
result.append('S');
157154
index++;
158-
break; */
155+
break;
159156
case 'C':
160157
index = handleC(value, result, index);
161158
break;
@@ -164,9 +161,7 @@ public String doubleMetaphone(String value, boolean alternate) {
164161
break;
165162
case 'F':
166163
result.append('F');
167-
index = charAt(value, index + 1) == 'F'
168-
? index + 2
169-
: index + 1;
164+
index = charAt(value, index + 1) == 'F' ? index + 2 : index + 1;
170165
break;
171166
case 'G':
172167
index = handleG(value, result, index, slavoGermanic);
@@ -179,9 +174,7 @@ public String doubleMetaphone(String value, boolean alternate) {
179174
break;
180175
case 'K':
181176
result.append('K');
182-
index = charAt(value, index + 1) == 'K'
183-
? index + 2
184-
: index + 1;
177+
index = charAt(value, index + 1) == 'K' ? index + 2 : index + 1;
185178
break;
186179
case 'L':
187180
index = handleL(value, result, index);
@@ -192,25 +185,19 @@ public String doubleMetaphone(String value, boolean alternate) {
192185
break;
193186
case 'N':
194187
result.append('N');
195-
index = charAt(value, index + 1) == 'N'
196-
? index + 2
197-
: index + 1;
188+
index = charAt(value, index + 1) == 'N' ? index + 2 : index + 1;
198189
break;
199-
// FIXME: Removed support for this character until we
200-
// find the Unicode code
201-
/*
202-
case 'Ñ':
190+
case '\u00D1':
191+
// N with a tilde (spanish ene)
203192
result.append('N');
204193
index++;
205-
break; */
194+
break;
206195
case 'P':
207196
index = handleP(value, result, index);
208197
break;
209198
case 'Q':
210199
result.append('K');
211-
index = charAt(value, index + 1) == 'Q'
212-
? index + 2
213-
: index + 1;
200+
index = charAt(value, index + 1) == 'Q' ? index + 2 : index + 1;
214201
break;
215202
case 'R':
216203
index = handleR(value, result, index, slavoGermanic);
@@ -223,9 +210,7 @@ public String doubleMetaphone(String value, boolean alternate) {
223210
break;
224211
case 'V':
225212
result.append('F');
226-
index = charAt(value, index + 1) == 'V'
227-
? index + 2
228-
: index + 1;
213+
index = charAt(value, index + 1) == 'V' ? index + 2 : index + 1;
229214
break;
230215
case 'W':
231216
index = handleW(value, result, index);
@@ -255,9 +240,7 @@ public String doubleMetaphone(String value, boolean alternate) {
255240
public Object encode(Object obj) throws EncoderException {
256241

257242
if (!(obj instanceof String)) {
258-
throw new EncoderException("Parameter supplied to Metaphone "
259-
+ "encode is not of type "
260-
+ "java.lang.String");
243+
throw new EncoderException("Parameter supplied to Metaphone encode is not of type java.lang.String");
261244
} else {
262245
return doubleMetaphone((String) obj);
263246
}
@@ -482,17 +465,12 @@ private int handleG(String value,
482465
} else if (contains(value, index + 1, 2, "LI") && !slavoGermanic) {
483466
result.append("KL", "L");
484467
index += 2;
485-
} else if (index == 0
486-
&& (charAt(value, index + 1) == 'Y'
487-
|| contains(value,
488-
index + 1,
489-
2,
490-
ES_EP_EB_EL_EY_IB_IL_IN_IE_EI_ER))) {
468+
} else if (index == 0 && (charAt(value, index + 1) == 'Y' || contains(value, index + 1, 2, ES_EP_EB_EL_EY_IB_IL_IN_IE_EI_ER))) {
491469
//-- -ges-, -gep-, -gel-, -gie- at beginning --//
492470
result.append('K', 'J');
493471
index += 2;
494-
} else if ((contains(value, index + 1, 2, "ER")
495-
|| charAt(value, index + 1) == 'Y') &&
472+
} else if ((contains(value, index + 1, 2, "ER") ||
473+
charAt(value, index + 1) == 'Y') &&
496474
!contains(value, 0, 6, "DANGER", "RANGER", "MANGER") &&
497475
!contains(value, index - 1, 1, "E", "I") &&
498476
!contains(value, index - 1, 3, "RGY", "OGY")) {
@@ -502,9 +480,7 @@ private int handleG(String value,
502480
} else if (contains(value, index + 1, 1, "E", "I", "Y") ||
503481
contains(value, index - 1, 4, "AGGI", "OGGI")) {
504482
//-- Italian "biaggi" --//
505-
if ((contains(value, 0 ,4, "VAN ", "VON ")
506-
|| contains(value, 0, 3, "SCH")) ||
507-
contains(value, index + 1, 2, "ET")) {
483+
if ((contains(value, 0 ,4, "VAN ", "VON ") || contains(value, 0, 3, "SCH")) || contains(value, index + 1, 2, "ET")) {
508484
//-- obvious germanic --//
509485
result.append('K');
510486
} else if (contains(value, index + 1, 4, "IER")) {
@@ -539,10 +515,8 @@ private int handleGH(String value,
539515
result.append('K');
540516
}
541517
index += 2;
542-
} else if ((index > 1 && contains(value, index - 2, 1, "B", "H", "D"))
543-
||
544-
(index > 2 && contains(value, index - 3, 1, "B", "H", "D"))
545-
||
518+
} else if ((index > 1 && contains(value, index - 2, 1, "B", "H", "D")) ||
519+
(index > 2 && contains(value, index - 3, 1, "B", "H", "D")) ||
546520
(index > 3 && contains(value, index - 4, 1, "B", "H"))) {
547521
//-- Parker's rule (with some further refinements) - "hugh"
548522
index += 2;
@@ -582,8 +556,7 @@ private int handleH(String value,
582556
*/
583557
private int handleJ(String value, DoubleMetaphoneResult result, int index,
584558
boolean slavoGermanic) {
585-
if (contains(value, index, 4, "JOSE")
586-
|| contains(value, 0, 4, "SAN ")) {
559+
if (contains(value, index, 4, "JOSE") || contains(value, 0, 4, "SAN ")) {
587560
//-- obvious Spanish, "Jose", "San Jacinto" --//
588561
if ((index == 0 && (charAt(value, index + 4) == ' ') ||
589562
value.length() == 4) || contains(value, 0, 4, "SAN ")) {
@@ -595,15 +568,12 @@ private int handleJ(String value, DoubleMetaphoneResult result, int index,
595568
} else {
596569
if (index == 0 && !contains(value, index, 4, "JOSE")) {
597570
result.append('J', 'A');
598-
} else if (isVowel(charAt(value, index - 1))
599-
&& !slavoGermanic
600-
&&(charAt(value, index + 1) == 'A' ||
601-
charAt(value, index + 1) == 'O')) {
571+
} else if (isVowel(charAt(value, index - 1)) && !slavoGermanic &&
572+
(charAt(value, index + 1) == 'A' || charAt(value, index + 1) == 'O')) {
602573
result.append('J', 'H');
603574
} else if (index == value.length() - 1) {
604575
result.append('J', ' ');
605-
} else if (!contains(value, index + 1, 1, L_T_K_S_N_M_B_Z)
606-
&& !contains(value, index - 1, 1, "S", "K", "L")) {
576+
} else if (!contains(value, index + 1, 1, L_T_K_S_N_M_B_Z) && !contains(value, index - 1, 1, "S", "K", "L")) {
607577
result.append('J');
608578
}
609579

@@ -645,9 +615,7 @@ private int handleP(String value,
645615
index += 2;
646616
} else {
647617
result.append('P');
648-
index = contains(value, index + 1, 1, "P", "B")
649-
? index + 2
650-
: index + 1;
618+
index = contains(value, index + 1, 1, "P", "B") ? index + 2 : index + 1;
651619
}
652620
return index;
653621
}
@@ -692,18 +660,15 @@ private int handleS(String value,
692660
result.append('X');
693661
}
694662
index += 2;
695-
} else if (contains(value, index, 3, "SIO", "SIA")
696-
|| contains(value, index, 4, "SIAN")) {
663+
} else if (contains(value, index, 3, "SIO", "SIA") || contains(value, index, 4, "SIAN")) {
697664
//-- Italian and Armenian --//
698665
if (slavoGermanic) {
699666
result.append('S');
700667
} else {
701668
result.append('S', 'X');
702669
}
703670
index += 3;
704-
} else if ((index == 0
705-
&& contains(value, index + 1, 1, "M", "N", "L", "W"))
706-
|| contains(value, index + 1, 1, "Z")) {
671+
} else if ((index == 0 && contains(value, index + 1, 1, "M", "N", "L", "W")) || contains(value, index + 1, 1, "Z")) {
707672
//-- german & anglicisations, e.g. "smith" match "schmidt" //
708673
// "snider" match "schneider" --//
709674
//-- also, -sz- in slavic language altho in hungarian it //
@@ -720,9 +685,7 @@ && contains(value, index + 1, 1, "M", "N", "L", "W"))
720685
} else {
721686
result.append('S');
722687
}
723-
index = contains(value, index + 1, 1, "S", "Z")
724-
? index + 2
725-
: index + 1;
688+
index = contains(value, index + 1, 1, "S", "Z") ? index + 2 : index + 1;
726689
}
727690
return index;
728691
}
@@ -745,8 +708,7 @@ private int handleSC(String value,
745708
result.append("SK");
746709
}
747710
} else {
748-
if (index == 0 && !isVowel(charAt(value, 3))
749-
&& charAt(value, 3) != 'W') {
711+
if (index == 0 && !isVowel(charAt(value, 3)) && charAt(value, 3) != 'W') {
750712
result.append('X', 'S');
751713
} else {
752714
result.append('X');
@@ -785,9 +747,7 @@ private int handleT(String value,
785747
index += 2;
786748
} else {
787749
result.append('T');
788-
index = contains(value, index + 1, 1, "T", "D")
789-
? index + 2
790-
: index + 1;
750+
index = contains(value, index + 1, 1, "T", "D") ? index + 2 : index + 1;
791751
}
792752
return index;
793753
}
@@ -813,8 +773,7 @@ private int handleW(String value,
813773
result.append('A');
814774
}
815775
index++;
816-
} else if ((index == value.length() - 1
817-
&& isVowel(charAt(value, index - 1))) ||
776+
} else if ((index == value.length() - 1 && isVowel(charAt(value, index - 1))) ||
818777
contains(value, index - 1,
819778
5, "EWSKI", "EWSKY", "OWSKI", "OWSKY") ||
820779
contains(value, 0, 3, "SCH")) {
@@ -848,9 +807,7 @@ private int handleX(String value,
848807
//-- French e.g. breaux --//
849808
result.append("KS");
850809
}
851-
index = contains(value, index + 1, 1, "C", "X")
852-
? index + 2
853-
: index + 1;
810+
index = contains(value, index + 1, 1, "C", "X") ? index + 2 : index + 1;
854811
}
855812
return index;
856813
}
@@ -865,9 +822,7 @@ private int handleZ(String value, DoubleMetaphoneResult result, int index,
865822
result.append('J');
866823
index += 2;
867824
} else {
868-
if (contains(value, index + 1, 2, "ZO", "ZI", "ZA")
869-
|| (slavoGermanic
870-
&& (index > 0 && charAt(value, index - 1) != 'T'))) {
825+
if (contains(value, index + 1, 2, "ZO", "ZI", "ZA") || (slavoGermanic && (index > 0 && charAt(value, index - 1) != 'T'))) {
871826
result.append("S", "TS");
872827
} else {
873828
result.append('S');
@@ -926,10 +881,8 @@ private boolean conditionCH1(String value, int index) {
926881
3, "SCH")) ||
927882
contains(value, index - 2, 6, "ORCHES", "ARCHIT", "ORCHID") ||
928883
contains(value, index + 2, 1, "T", "S") ||
929-
((contains(value, index - 1, 1, "A", "O", "U", "E") || index ==
930-
0) &&
931-
(contains(value, index + 2, 1, L_R_N_M_B_H_F_V_W_SPACE) || index
932-
+ 1 == value.length() - 1)));
884+
((contains(value, index - 1, 1, "A", "O", "U", "E") || index == 0) &&
885+
(contains(value, index + 2, 1, L_R_N_M_B_H_F_V_W_SPACE) || index + 1 == value.length() - 1)));
933886
}
934887

935888
/**

0 commit comments

Comments
 (0)