You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by to...@apache.org on 2003/10/12 21:48:15 UTC
cvs commit: jakarta-commons/codec/src/java/org/apache/commons/codec/binary Base64.java
tobrien 2003/10/12 12:48:15
Modified: codec/src/java/org/apache/commons/codec/language
Metaphone.java RefinedSoundex.java Soundex.java
codec/src/java/org/apache/commons/codec/binary Base64.java
Log:
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.
Revision Changes Path
1.8 +21 -51 jakarta-commons/codec/src/java/org/apache/commons/codec/language/Metaphone.java
Index: Metaphone.java
===================================================================
RCS file: /home/cvs/jakarta-commons/codec/src/java/org/apache/commons/codec/language/Metaphone.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Metaphone.java 5 Oct 2003 21:45:48 -0000 1.7
+++ Metaphone.java 12 Oct 2003 19:48:14 -0000 1.8
@@ -115,8 +115,7 @@
public String metaphone(String txt) {
int mtsz = 0 ;
boolean hard = false ;
- if ((txt == null)
- || (txt.length() == 0)) {
+ if ((txt == null) || (txt.length() == 0)) {
return "" ;
}
// single character is itself
@@ -170,12 +169,10 @@
int wdsz = local.length();
int n = 0 ;
- while ((mtsz < maxCodeLen) // max code size of 4 works well
- && (n < wdsz)) {
+ while ((mtsz < maxCodeLen) && (n < wdsz)) { // max code size of 4 works well
char symb = local.charAt(n) ;
// remove duplicate letters except C
- if ((symb != 'C')
- && (n > 0) && (local.charAt(n - 1) == symb)) {
+ if ((symb != 'C') && (n > 0) && (local.charAt(n - 1) == symb)) {
n++ ;
} else { // not dup
switch(symb) {
@@ -186,9 +183,7 @@
}
break ; // only use vowel if leading char
case 'B' :
- if ((n > 0)
- && !(n + 1 == wdsz) // not MB at end of word
- && (local.charAt(n - 1) == 'M')) {
+ if ((n > 0) && !(n + 1 == wdsz) && (local.charAt(n - 1) == 'M')) { // not MB at end of word
code.append(symb);
} else {
code.append(symb);
@@ -197,32 +192,25 @@
break;
case 'C' : // lots of C special cases
/* discard if SCI, SCE or SCY */
- if ((n > 0)
- && (local.charAt(n - 1) == 'S')
- && (n + 1 < wdsz)
- && (frontv.indexOf(local.charAt(n + 1)) >= 0)) {
+ if ((n > 0) && (local.charAt(n - 1) == 'S') && (n + 1 < wdsz) && (frontv.indexOf(local.charAt(n + 1)) >= 0)) {
break ;
}
tmpS = local.toString();
if (tmpS.indexOf("CIA", n) == n) { // "CIA" -> X
code.append('X'); mtsz++; break ;
}
- if ((n + 1 < wdsz)
- && (frontv.indexOf(local.charAt(n + 1)) >= 0)) {
+ if ((n + 1 < wdsz) && (frontv.indexOf(local.charAt(n + 1)) >= 0)) {
code.append('S');
mtsz++;
break ; // CI,CE,CY -> S
}
- if ((n > 0)
- && (tmpS.indexOf("SCH", n - 1) == n - 1)) { // SCH->sk
+ if ((n > 0) && (tmpS.indexOf("SCH", n - 1) == n - 1)) { // SCH->sk
code.append('K') ;
mtsz++;
break ;
}
if (tmpS.indexOf("CH", n) == n) { // detect CH
- if ((n == 0)
- && (wdsz >= 3) // CH consonant -> K consonant
- && (vowels.indexOf(local.charAt(2)) < 0)) {
+ if ((n == 0) && (wdsz >= 3) && (vowels.indexOf(local.charAt(2)) < 0)) { // CH consonant -> K consonant
code.append('K');
} else {
code.append('X'); // CHvowel -> X
@@ -234,9 +222,7 @@
}
break ;
case 'D' :
- if ((n + 2 < wdsz) // DGE DGI DGY -> J
- && (local.charAt(n + 1) == 'G')
- && (frontv.indexOf(local.charAt(n + 2)) >= 0)) {
+ if ((n + 2 < wdsz) && (local.charAt(n + 1) == 'G') && (frontv.indexOf(local.charAt(n + 2)) >= 0)) { // DGE DGI DGY -> J
code.append('J'); n += 2 ;
} else {
code.append('T');
@@ -244,30 +230,22 @@
mtsz++;
break ;
case 'G' : // GH silent at end or before consonant
- if ((n + 2 == wdsz)
- && (local.charAt(n + 1) == 'H')) {
+ if ((n + 2 == wdsz) && (local.charAt(n + 1) == 'H')) {
break;
}
- if ((n + 2 < wdsz)
- && (local.charAt(n + 1) == 'H')
- && (vowels.indexOf(local.charAt(n + 2)) < 0)) {
+ if ((n + 2 < wdsz) && (local.charAt(n + 1) == 'H') && (vowels.indexOf(local.charAt(n + 2)) < 0)) {
break;
}
tmpS = local.toString();
- if ((n > 0)
- && (tmpS.indexOf("GN", n) == n)
- || (tmpS.indexOf("GNED", n) == n)) {
+ if ((n > 0) && (tmpS.indexOf("GN", n) == n) || (tmpS.indexOf("GNED", n) == n)) {
break; // silent G
}
- if ((n > 0)
- && (local.charAt(n - 1) == 'G')) {
+ if ((n > 0) && (local.charAt(n - 1) == 'G')) {
hard = true ;
} else {
hard = false ;
}
- if ((n + 1 < wdsz)
- && (frontv.indexOf(local.charAt(n + 1)) >= 0)
- && (!hard)) {
+ if ((n + 1 < wdsz) && (frontv.indexOf(local.charAt(n + 1)) >= 0) && (!hard)) {
code.append('J');
} else {
code.append('K');
@@ -278,8 +256,7 @@
if (n + 1 == wdsz) {
break ; // terminal H
}
- if ((n > 0)
- && (varson.indexOf(local.charAt(n - 1)) >= 0)) {
+ if ((n > 0) && (varson.indexOf(local.charAt(n - 1)) >= 0)) {
break;
}
if (vowels.indexOf(local.charAt(n + 1)) >= 0) {
@@ -307,8 +284,7 @@
mtsz++ ;
break ;
case 'P' :
- if ((n + 1 < wdsz)
- && (local.charAt(n + 1) == 'H')) {
+ if ((n + 1 < wdsz) && (local.charAt(n + 1) == 'H')) {
// PH -> F
code.append('F');
} else {
@@ -322,9 +298,7 @@
break;
case 'S' :
tmpS = local.toString();
- if ((tmpS.indexOf("SH", n) == n)
- || (tmpS.indexOf("SIO", n) == n)
- || (tmpS.indexOf("SIA", n) == n)) {
+ if ((tmpS.indexOf("SH", n) == n) || (tmpS.indexOf("SIO", n) == n) || (tmpS.indexOf("SIA", n) == n)) {
code.append('X');
} else {
code.append('S');
@@ -333,8 +307,7 @@
break;
case 'T' :
tmpS = local.toString(); // TIA TIO -> X
- if ((tmpS.indexOf("TIA", n) == n)
- || (tmpS.indexOf("TIO", n) == n)) {
+ if ((tmpS.indexOf("TIA", n) == n) || (tmpS.indexOf("TIO", n) == n)) {
code.append('X');
mtsz++;
break;
@@ -353,8 +326,7 @@
case 'V' :
code.append('F'); mtsz++;break ;
case 'W' : case 'Y' : // silent if not followed by vowel
- if ((n + 1 < wdsz)
- && (vowels.indexOf(local.charAt(n + 1)) >= 0)) {
+ if ((n + 1 < wdsz) && (vowels.indexOf(local.charAt(n + 1)) >= 0)) {
code.append(symb);
mtsz++;
}
@@ -388,9 +360,7 @@
public Object encode(Object pObject) throws EncoderException {
Object result;
if (!(pObject instanceof java.lang.String)) {
- throw new EncoderException("Parameter supplied to Metaphone "
- + "encode is not of type "
- + "java.lang.String");
+ throw new EncoderException("Parameter supplied to Metaphone encode is not of type java.lang.String");
} else {
result = metaphone((String) pObject);
}
1.10 +2 -5 jakarta-commons/codec/src/java/org/apache/commons/codec/language/RefinedSoundex.java
Index: RefinedSoundex.java
===================================================================
RCS file: /home/cvs/jakarta-commons/codec/src/java/org/apache/commons/codec/language/RefinedSoundex.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- RefinedSoundex.java 5 Oct 2003 21:45:48 -0000 1.9
+++ RefinedSoundex.java 12 Oct 2003 19:48:14 -0000 1.10
@@ -176,10 +176,7 @@
public Object encode(Object pObject) throws EncoderException {
Object result;
if (!(pObject instanceof java.lang.String)) {
- throw new EncoderException("Parameter supplied to "
- + "RefinedSoundex "
- + "encode is not of type "
- + "java.lang.String");
+ throw new EncoderException("Parameter supplied to RefinedSoundex encode is not of type java.lang.String");
} else {
result = soundex((String) pObject);
}
1.9 +3 -8 jakarta-commons/codec/src/java/org/apache/commons/codec/language/Soundex.java
Index: Soundex.java
===================================================================
RCS file: /home/cvs/jakarta-commons/codec/src/java/org/apache/commons/codec/language/Soundex.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Soundex.java 5 Oct 2003 21:45:48 -0000 1.8
+++ Soundex.java 12 Oct 2003 19:48:15 -0000 1.9
@@ -134,9 +134,7 @@
int incount = 1, count = 1;
out[0] = Character.toUpperCase(str.charAt(0));
last = getMappingCode(str.charAt(0));
- while ((incount < str.length())
- && (mapped = getMappingCode(str.charAt(incount++))) != 0
- && (count < maxLength)) {
+ while ((incount < str.length()) && (mapped = getMappingCode(str.charAt(incount++))) != 0 && (count < maxLength)) {
if ((mapped != '0') && (mapped != last)) {
out[count++] = mapped;
}
@@ -162,10 +160,7 @@
Object result;
if (!(pObject instanceof java.lang.String)) {
- throw new EncoderException("Parameter supplied to "
- + "Soundex "
- + "encode is not of type "
- + "java.lang.String");
+ throw new EncoderException("Parameter supplied to Soundex encode is not of type java.lang.String");
} else {
result = soundex((String) pObject);
}
1.11 +12 -31 jakarta-commons/codec/src/java/org/apache/commons/codec/binary/Base64.java
Index: Base64.java
===================================================================
RCS file: /home/cvs/jakarta-commons/codec/src/java/org/apache/commons/codec/binary/Base64.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Base64.java 5 Oct 2003 21:45:49 -0000 1.10
+++ Base64.java 12 Oct 2003 19:48:15 -0000 1.11
@@ -245,10 +245,7 @@
Object result;
if (!(pObject instanceof byte[])) {
- throw new DecoderException(
- "Parameter supplied to "
- + "Base64 "
- + "decode is not a byte[]");
+ throw new DecoderException("Parameter supplied to Base64 decode is not a byte[]");
} else {
result = decode((byte[]) pObject);
}
@@ -302,9 +299,7 @@
if (isChunked) {
nbrChunks =
- (CHUNK_SEPARATOR.length == 0
- ? 0
- : (int) Math.ceil((float) encodedDataLength / CHUNK_SIZE));
+ (CHUNK_SEPARATOR.length == 0 ? 0 : (int) Math.ceil((float) encodedDataLength / CHUNK_SIZE));
encodedDataLength += nbrChunks * CHUNK_SEPARATOR.length;
}
@@ -331,17 +326,11 @@
k = (byte) (b1 & 0x03);
byte val1 =
- ((b1 & SIGN) == 0)
- ? (byte) (b1 >> 2)
- : (byte) ((b1) >> 2 ^ 0xc0);
+ ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
byte val2 =
- ((b2 & SIGN) == 0)
- ? (byte) (b2 >> 4)
- : (byte) ((b2) >> 4 ^ 0xf0);
+ ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
byte val3 =
- ((b3 & SIGN) == 0)
- ? (byte) (b3 >> 6)
- : (byte) ((b3) >> 6 ^ 0xfc);
+ ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc);
encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
//log.debug( "val2 = " + val2 );
@@ -367,8 +356,8 @@
CHUNK_SEPARATOR.length);
chunksSoFar++;
nextSeparatorIndex =
- (CHUNK_SIZE * (chunksSoFar + 1))
- + (chunksSoFar * CHUNK_SEPARATOR.length);
+ (CHUNK_SIZE * (chunksSoFar + 1)) +
+ (chunksSoFar * CHUNK_SEPARATOR.length);
encodedIndex += CHUNK_SEPARATOR.length;
}
}
@@ -383,9 +372,7 @@
//log.debug("b1=" + b1);
//log.debug("b1<<2 = " + (b1>>2) );
byte val1 =
- ((b1 & SIGN) == 0)
- ? (byte) (b1 >> 2)
- : (byte) ((b1) >> 2 ^ 0xc0);
+ ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
encodedData[encodedIndex + 1] = lookUpBase64Alphabet[k << 4];
encodedData[encodedIndex + 2] = PAD;
@@ -398,13 +385,9 @@
k = (byte) (b1 & 0x03);
byte val1 =
- ((b1 & SIGN) == 0)
- ? (byte) (b1 >> 2)
- : (byte) ((b1) >> 2 ^ 0xc0);
+ ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
byte val2 =
- ((b2 & SIGN) == 0)
- ? (byte) (b2 >> 4)
- : (byte) ((b2) >> 4 ^ 0xf0);
+ ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
encodedData[encodedIndex] = lookUpBase64Alphabet[val1];
encodedData[encodedIndex + 1] =
@@ -573,9 +556,7 @@
if (!(pObject instanceof byte[])) {
throw new EncoderException(
- "Parameter supplied to "
- + "Base64 "
- + "encode is not a byte[]");
+ "Parameter supplied to Base64 encode is not a byte[]");
} else {
result = encode((byte[]) pObject);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org