Skip to content

Commit 1078329

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. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/codec/trunk@130213 13f79535-47bb-0310-9956-ffa450edef68
1 parent 3652eb6 commit 1078329

4 files changed

Lines changed: 38 additions & 95 deletions

File tree

src/java/org/apache/commons/codec/binary/Base64.java

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
7676
* @author Tim O'Brien
7777
* @since 1.0-dev
78-
* @version $Id: Base64.java,v 1.10 2003/10/05 21:45:49 tobrien Exp $
78+
* @version $Id: Base64.java,v 1.11 2003/10/12 19:48:15 tobrien Exp $
7979
*/
8080
public class Base64 implements BinaryEncoder, BinaryDecoder {
8181

@@ -245,10 +245,7 @@ public Object decode(Object pObject) throws DecoderException {
245245
Object result;
246246

247247
if (!(pObject instanceof byte[])) {
248-
throw new DecoderException(
249-
"Parameter supplied to "
250-
+ "Base64 "
251-
+ "decode is not a byte[]");
248+
throw new DecoderException("Parameter supplied to Base64 decode is not a byte[]");
252249
} else {
253250
result = decode((byte[]) pObject);
254251
}
@@ -302,9 +299,7 @@ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked) {
302299
if (isChunked) {
303300

304301
nbrChunks =
305-
(CHUNK_SEPARATOR.length == 0
306-
? 0
307-
: (int) Math.ceil((float) encodedDataLength / CHUNK_SIZE));
302+
(CHUNK_SEPARATOR.length == 0 ? 0 : (int) Math.ceil((float) encodedDataLength / CHUNK_SIZE));
308303
encodedDataLength += nbrChunks * CHUNK_SEPARATOR.length;
309304
}
310305

@@ -331,17 +326,11 @@ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked) {
331326
k = (byte) (b1 & 0x03);
332327

333328
byte val1 =
334-
((b1 & SIGN) == 0)
335-
? (byte) (b1 >> 2)
336-
: (byte) ((b1) >> 2 ^ 0xc0);
329+
((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
337330
byte val2 =
338-
((b2 & SIGN) == 0)
339-
? (byte) (b2 >> 4)
340-
: (byte) ((b2) >> 4 ^ 0xf0);
331+
((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
341332
byte val3 =
342-
((b3 & SIGN) == 0)
343-
? (byte) (b3 >> 6)
344-
: (byte) ((b3) >> 6 ^ 0xfc);
333+
((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc);
345334

346335
encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
347336
//log.debug( "val2 = " + val2 );
@@ -367,8 +356,8 @@ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked) {
367356
CHUNK_SEPARATOR.length);
368357
chunksSoFar++;
369358
nextSeparatorIndex =
370-
(CHUNK_SIZE * (chunksSoFar + 1))
371-
+ (chunksSoFar * CHUNK_SEPARATOR.length);
359+
(CHUNK_SIZE * (chunksSoFar + 1)) +
360+
(chunksSoFar * CHUNK_SEPARATOR.length);
372361
encodedIndex += CHUNK_SEPARATOR.length;
373362
}
374363
}
@@ -383,9 +372,7 @@ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked) {
383372
//log.debug("b1=" + b1);
384373
//log.debug("b1<<2 = " + (b1>>2) );
385374
byte val1 =
386-
((b1 & SIGN) == 0)
387-
? (byte) (b1 >> 2)
388-
: (byte) ((b1) >> 2 ^ 0xc0);
375+
((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
389376
encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
390377
encodedData[encodedIndex + 1] = lookUpBase64Alphabet[k << 4];
391378
encodedData[encodedIndex + 2] = PAD;
@@ -398,13 +385,9 @@ public static byte[] encodeBase64(byte[] binaryData, boolean isChunked) {
398385
k = (byte) (b1 & 0x03);
399386

400387
byte val1 =
401-
((b1 & SIGN) == 0)
402-
? (byte) (b1 >> 2)
403-
: (byte) ((b1) >> 2 ^ 0xc0);
388+
((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
404389
byte val2 =
405-
((b2 & SIGN) == 0)
406-
? (byte) (b2 >> 4)
407-
: (byte) ((b2) >> 4 ^ 0xf0);
390+
((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
408391

409392
encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
410393
encodedData[encodedIndex + 1] =
@@ -573,9 +556,7 @@ public Object encode(Object pObject) throws EncoderException {
573556

574557
if (!(pObject instanceof byte[])) {
575558
throw new EncoderException(
576-
"Parameter supplied to "
577-
+ "Base64 "
578-
+ "encode is not a byte[]");
559+
"Parameter supplied to Base64 encode is not a byte[]");
579560
} else {
580561
result = encode((byte[]) pObject);
581562
}

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

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
* @author wbrogden@bga.com
7272
* @author bayard@generationjava.com
7373
* @author Tim O'Brien
74-
* @version $Id: Metaphone.java,v 1.7 2003/10/05 21:45:48 tobrien Exp $
74+
* @version $Id: Metaphone.java,v 1.8 2003/10/12 19:48:14 tobrien Exp $
7575
*/
7676
public class Metaphone implements StringEncoder {
7777

@@ -115,8 +115,7 @@ public Metaphone() {
115115
public String metaphone(String txt) {
116116
int mtsz = 0 ;
117117
boolean hard = false ;
118-
if ((txt == null)
119-
|| (txt.length() == 0)) {
118+
if ((txt == null) || (txt.length() == 0)) {
120119
return "" ;
121120
}
122121
// single character is itself
@@ -170,12 +169,10 @@ public String metaphone(String txt) {
170169
int wdsz = local.length();
171170
int n = 0 ;
172171

173-
while ((mtsz < maxCodeLen) // max code size of 4 works well
174-
&& (n < wdsz)) {
172+
while ((mtsz < maxCodeLen) && (n < wdsz)) { // max code size of 4 works well
175173
char symb = local.charAt(n) ;
176174
// remove duplicate letters except C
177-
if ((symb != 'C')
178-
&& (n > 0) && (local.charAt(n - 1) == symb)) {
175+
if ((symb != 'C') && (n > 0) && (local.charAt(n - 1) == symb)) {
179176
n++ ;
180177
} else { // not dup
181178
switch(symb) {
@@ -186,9 +183,7 @@ public String metaphone(String txt) {
186183
}
187184
break ; // only use vowel if leading char
188185
case 'B' :
189-
if ((n > 0)
190-
&& !(n + 1 == wdsz) // not MB at end of word
191-
&& (local.charAt(n - 1) == 'M')) {
186+
if ((n > 0) && !(n + 1 == wdsz) && (local.charAt(n - 1) == 'M')) { // not MB at end of word
192187
code.append(symb);
193188
} else {
194189
code.append(symb);
@@ -197,32 +192,25 @@ public String metaphone(String txt) {
197192
break;
198193
case 'C' : // lots of C special cases
199194
/* discard if SCI, SCE or SCY */
200-
if ((n > 0)
201-
&& (local.charAt(n - 1) == 'S')
202-
&& (n + 1 < wdsz)
203-
&& (frontv.indexOf(local.charAt(n + 1)) >= 0)) {
195+
if ((n > 0) && (local.charAt(n - 1) == 'S') && (n + 1 < wdsz) && (frontv.indexOf(local.charAt(n + 1)) >= 0)) {
204196
break ;
205197
}
206198
tmpS = local.toString();
207199
if (tmpS.indexOf("CIA", n) == n) { // "CIA" -> X
208200
code.append('X'); mtsz++; break ;
209201
}
210-
if ((n + 1 < wdsz)
211-
&& (frontv.indexOf(local.charAt(n + 1)) >= 0)) {
202+
if ((n + 1 < wdsz) && (frontv.indexOf(local.charAt(n + 1)) >= 0)) {
212203
code.append('S');
213204
mtsz++;
214205
break ; // CI,CE,CY -> S
215206
}
216-
if ((n > 0)
217-
&& (tmpS.indexOf("SCH", n - 1) == n - 1)) { // SCH->sk
207+
if ((n > 0) && (tmpS.indexOf("SCH", n - 1) == n - 1)) { // SCH->sk
218208
code.append('K') ;
219209
mtsz++;
220210
break ;
221211
}
222212
if (tmpS.indexOf("CH", n) == n) { // detect CH
223-
if ((n == 0)
224-
&& (wdsz >= 3) // CH consonant -> K consonant
225-
&& (vowels.indexOf(local.charAt(2)) < 0)) {
213+
if ((n == 0) && (wdsz >= 3) && (vowels.indexOf(local.charAt(2)) < 0)) { // CH consonant -> K consonant
226214
code.append('K');
227215
} else {
228216
code.append('X'); // CHvowel -> X
@@ -234,40 +222,30 @@ public String metaphone(String txt) {
234222
}
235223
break ;
236224
case 'D' :
237-
if ((n + 2 < wdsz) // DGE DGI DGY -> J
238-
&& (local.charAt(n + 1) == 'G')
239-
&& (frontv.indexOf(local.charAt(n + 2)) >= 0)) {
225+
if ((n + 2 < wdsz) && (local.charAt(n + 1) == 'G') && (frontv.indexOf(local.charAt(n + 2)) >= 0)) { // DGE DGI DGY -> J
240226
code.append('J'); n += 2 ;
241227
} else {
242228
code.append('T');
243229
}
244230
mtsz++;
245231
break ;
246232
case 'G' : // GH silent at end or before consonant
247-
if ((n + 2 == wdsz)
248-
&& (local.charAt(n + 1) == 'H')) {
233+
if ((n + 2 == wdsz) && (local.charAt(n + 1) == 'H')) {
249234
break;
250235
}
251-
if ((n + 2 < wdsz)
252-
&& (local.charAt(n + 1) == 'H')
253-
&& (vowels.indexOf(local.charAt(n + 2)) < 0)) {
236+
if ((n + 2 < wdsz) && (local.charAt(n + 1) == 'H') && (vowels.indexOf(local.charAt(n + 2)) < 0)) {
254237
break;
255238
}
256239
tmpS = local.toString();
257-
if ((n > 0)
258-
&& (tmpS.indexOf("GN", n) == n)
259-
|| (tmpS.indexOf("GNED", n) == n)) {
240+
if ((n > 0) && (tmpS.indexOf("GN", n) == n) || (tmpS.indexOf("GNED", n) == n)) {
260241
break; // silent G
261242
}
262-
if ((n > 0)
263-
&& (local.charAt(n - 1) == 'G')) {
243+
if ((n > 0) && (local.charAt(n - 1) == 'G')) {
264244
hard = true ;
265245
} else {
266246
hard = false ;
267247
}
268-
if ((n + 1 < wdsz)
269-
&& (frontv.indexOf(local.charAt(n + 1)) >= 0)
270-
&& (!hard)) {
248+
if ((n + 1 < wdsz) && (frontv.indexOf(local.charAt(n + 1)) >= 0) && (!hard)) {
271249
code.append('J');
272250
} else {
273251
code.append('K');
@@ -278,8 +256,7 @@ public String metaphone(String txt) {
278256
if (n + 1 == wdsz) {
279257
break ; // terminal H
280258
}
281-
if ((n > 0)
282-
&& (varson.indexOf(local.charAt(n - 1)) >= 0)) {
259+
if ((n > 0) && (varson.indexOf(local.charAt(n - 1)) >= 0)) {
283260
break;
284261
}
285262
if (vowels.indexOf(local.charAt(n + 1)) >= 0) {
@@ -307,8 +284,7 @@ public String metaphone(String txt) {
307284
mtsz++ ;
308285
break ;
309286
case 'P' :
310-
if ((n + 1 < wdsz)
311-
&& (local.charAt(n + 1) == 'H')) {
287+
if ((n + 1 < wdsz) && (local.charAt(n + 1) == 'H')) {
312288
// PH -> F
313289
code.append('F');
314290
} else {
@@ -322,9 +298,7 @@ public String metaphone(String txt) {
322298
break;
323299
case 'S' :
324300
tmpS = local.toString();
325-
if ((tmpS.indexOf("SH", n) == n)
326-
|| (tmpS.indexOf("SIO", n) == n)
327-
|| (tmpS.indexOf("SIA", n) == n)) {
301+
if ((tmpS.indexOf("SH", n) == n) || (tmpS.indexOf("SIO", n) == n) || (tmpS.indexOf("SIA", n) == n)) {
328302
code.append('X');
329303
} else {
330304
code.append('S');
@@ -333,8 +307,7 @@ public String metaphone(String txt) {
333307
break;
334308
case 'T' :
335309
tmpS = local.toString(); // TIA TIO -> X
336-
if ((tmpS.indexOf("TIA", n) == n)
337-
|| (tmpS.indexOf("TIO", n) == n)) {
310+
if ((tmpS.indexOf("TIA", n) == n) || (tmpS.indexOf("TIO", n) == n)) {
338311
code.append('X');
339312
mtsz++;
340313
break;
@@ -353,8 +326,7 @@ public String metaphone(String txt) {
353326
case 'V' :
354327
code.append('F'); mtsz++;break ;
355328
case 'W' : case 'Y' : // silent if not followed by vowel
356-
if ((n + 1 < wdsz)
357-
&& (vowels.indexOf(local.charAt(n + 1)) >= 0)) {
329+
if ((n + 1 < wdsz) && (vowels.indexOf(local.charAt(n + 1)) >= 0)) {
358330
code.append(symb);
359331
mtsz++;
360332
}
@@ -388,9 +360,7 @@ public String metaphone(String txt) {
388360
public Object encode(Object pObject) throws EncoderException {
389361
Object result;
390362
if (!(pObject instanceof java.lang.String)) {
391-
throw new EncoderException("Parameter supplied to Metaphone "
392-
+ "encode is not of type "
393-
+ "java.lang.String");
363+
throw new EncoderException("Parameter supplied to Metaphone encode is not of type java.lang.String");
394364
} else {
395365
result = metaphone((String) pObject);
396366
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
*
6969
* @author Tim O'Brien
7070
* @author ggregory@seagullsw.com
71-
* @version $Id: RefinedSoundex.java,v 1.9 2003/10/05 21:45:48 tobrien Exp $
71+
* @version $Id: RefinedSoundex.java,v 1.10 2003/10/12 19:48:14 tobrien Exp $
7272
*/
7373
public class RefinedSoundex implements StringEncoder {
7474

@@ -176,10 +176,7 @@ public String encode(String pString) throws EncoderException {
176176
public Object encode(Object pObject) throws EncoderException {
177177
Object result;
178178
if (!(pObject instanceof java.lang.String)) {
179-
throw new EncoderException("Parameter supplied to "
180-
+ "RefinedSoundex "
181-
+ "encode is not of type "
182-
+ "java.lang.String");
179+
throw new EncoderException("Parameter supplied to RefinedSoundex encode is not of type java.lang.String");
183180
} else {
184181
result = soundex((String) pObject);
185182
}

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
* @author bayard@generationjava.com
6969
* @author Tim O'Brien
7070
* @author ggregory@seagullsw.com
71-
* @version $Id: Soundex.java,v 1.8 2003/10/05 21:45:48 tobrien Exp $
71+
* @version $Id: Soundex.java,v 1.9 2003/10/12 19:48:15 tobrien Exp $
7272
*/
7373
public class Soundex implements StringEncoder {
7474

@@ -134,9 +134,7 @@ public String soundex(String str) {
134134
int incount = 1, count = 1;
135135
out[0] = Character.toUpperCase(str.charAt(0));
136136
last = getMappingCode(str.charAt(0));
137-
while ((incount < str.length())
138-
&& (mapped = getMappingCode(str.charAt(incount++))) != 0
139-
&& (count < maxLength)) {
137+
while ((incount < str.length()) && (mapped = getMappingCode(str.charAt(incount++))) != 0 && (count < maxLength)) {
140138
if ((mapped != '0') && (mapped != last)) {
141139
out[count++] = mapped;
142140
}
@@ -162,10 +160,7 @@ public Object encode(Object pObject) throws EncoderException {
162160
Object result;
163161

164162
if (!(pObject instanceof java.lang.String)) {
165-
throw new EncoderException("Parameter supplied to "
166-
+ "Soundex "
167-
+ "encode is not of type "
168-
+ "java.lang.String");
163+
throw new EncoderException("Parameter supplied to Soundex encode is not of type java.lang.String");
169164
} else {
170165
result = soundex((String) pObject);
171166
}

0 commit comments

Comments
 (0)