Skip to content

Commit 96a0c5e

Browse files
committed
Fix formatting
1 parent 9ef918f commit 96a0c5e

4 files changed

Lines changed: 38 additions & 58 deletions

File tree

src/main/java/org/apache/commons/codec/binary/Base64OutputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Base64OutputStream(final OutputStream outputStream) {
8282
* true if we should encode all data written to us, false if we should decode.
8383
*/
8484
public Base64OutputStream(final OutputStream outputStream, final boolean doEncode) {
85-
super(outputStream,new Base64(false), doEncode);
85+
super(outputStream, new Base64(false), doEncode);
8686
}
8787

8888
/**

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

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ public String metaphone(final String txt) {
9898
final char[] inwd = txt.toUpperCase(java.util.Locale.ENGLISH).toCharArray();
9999

100100
final StringBuilder local = new StringBuilder(40); // manipulate
101-
final StringBuilder code = new StringBuilder(10); // output
101+
final StringBuilder code = new StringBuilder(10); // output
102102
// handle initial 2 characters exceptions
103-
switch(inwd[0]) {
103+
switch (inwd[0]) {
104104
case 'K':
105105
case 'G':
106-
case 'P': /* looking for KN, etc*/
106+
case 'P': /* looking for KN, etc */
107107
if (inwd[1] == 'N') {
108108
local.append(inwd, 1, inwd.length - 1);
109109
} else {
@@ -118,7 +118,7 @@ public String metaphone(final String txt) {
118118
}
119119
break;
120120
case 'W': /* looking for WR or WH */
121-
if (inwd[1] == 'R') { // WR -> R
121+
if (inwd[1] == 'R') { // WR -> R
122122
local.append(inwd, 1, inwd.length - 1);
123123
break;
124124
}
@@ -140,14 +140,13 @@ public String metaphone(final String txt) {
140140
final int wdsz = local.length();
141141
int n = 0;
142142

143-
while (code.length() < this.getMaxCodeLen() &&
144-
n < wdsz ) { // max code size of 4 works well
143+
while (code.length() < this.getMaxCodeLen() && n < wdsz) { // max code size of 4 works well
145144
final char symb = local.charAt(n);
146145
// remove duplicate letters except C
147-
if (symb != 'C' && isPreviousChar( local, n, symb ) ) {
146+
if (symb != 'C' && isPreviousChar(local, n, symb)) {
148147
n++;
149148
} else { // not dup
150-
switch(symb) {
149+
switch (symb) {
151150
case 'A':
152151
case 'E':
153152
case 'I':
@@ -158,37 +157,30 @@ public String metaphone(final String txt) {
158157
}
159158
break; // only use vowel if leading char
160159
case 'B':
161-
if ( isPreviousChar(local, n, 'M') &&
162-
isLastChar(wdsz, n) ) { // B is silent if word ends in MB
160+
if (isPreviousChar(local, n, 'M') && isLastChar(wdsz, n)) { // B is silent if word ends in MB
163161
break;
164162
}
165163
code.append(symb);
166164
break;
167165
case 'C': // lots of C special cases
168166
/* discard if SCI, SCE or SCY */
169-
if ( isPreviousChar(local, n, 'S') &&
170-
!isLastChar(wdsz, n) &&
171-
FRONTV.indexOf(local.charAt(n + 1)) >= 0 ) {
167+
if (isPreviousChar(local, n, 'S') && !isLastChar(wdsz, n) && FRONTV.indexOf(local.charAt(n + 1)) >= 0) {
172168
break;
173169
}
174170
if (regionMatch(local, n, "CIA")) { // "CIA" -> X
175171
code.append('X');
176172
break;
177173
}
178-
if (!isLastChar(wdsz, n) &&
179-
FRONTV.indexOf(local.charAt(n + 1)) >= 0) {
174+
if (!isLastChar(wdsz, n) && FRONTV.indexOf(local.charAt(n + 1)) >= 0) {
180175
code.append('S');
181176
break; // CI,CE,CY -> S
182177
}
183-
if (isPreviousChar(local, n, 'S') &&
184-
isNextChar(local, n, 'H') ) { // SCH->sk
178+
if (isPreviousChar(local, n, 'S') && isNextChar(local, n, 'H')) { // SCH->sk
185179
code.append('K');
186180
break;
187181
}
188182
if (isNextChar(local, n, 'H')) { // detect CH
189-
if (n == 0 &&
190-
wdsz >= 3 &&
191-
isVowel(local,2) ) { // CH consonant -> K consonant
183+
if (n == 0 && wdsz >= 3 && isVowel(local, 2)) { // CH consonant -> K consonant
192184
code.append('K');
193185
} else {
194186
code.append('X'); // CHvowel -> X
@@ -198,34 +190,26 @@ public String metaphone(final String txt) {
198190
}
199191
break;
200192
case 'D':
201-
if (!isLastChar(wdsz, n + 1) &&
202-
isNextChar(local, n, 'G') &&
203-
FRONTV.indexOf(local.charAt(n + 2)) >= 0) { // DGE DGI DGY -> J
204-
code.append('J'); n += 2;
193+
if (!isLastChar(wdsz, n + 1) && isNextChar(local, n, 'G') && FRONTV.indexOf(local.charAt(n + 2)) >= 0) { // DGE DGI DGY -> J
194+
code.append('J');
195+
n += 2;
205196
} else {
206197
code.append('T');
207198
}
208199
break;
209200
case 'G': // GH silent at end or before consonant
210-
if (isLastChar(wdsz, n + 1) &&
211-
isNextChar(local, n, 'H')) {
201+
if (isLastChar(wdsz, n + 1) && isNextChar(local, n, 'H')) {
212202
break;
213203
}
214-
if (!isLastChar(wdsz, n + 1) &&
215-
isNextChar(local,n,'H') &&
216-
!isVowel(local,n+2)) {
204+
if (!isLastChar(wdsz, n + 1) && isNextChar(local, n, 'H') && !isVowel(local, n + 2)) {
217205
break;
218206
}
219-
if (n > 0 &&
220-
( regionMatch(local, n, "GN") ||
221-
regionMatch(local, n, "GNED") ) ) {
207+
if (n > 0 && (regionMatch(local, n, "GN") || regionMatch(local, n, "GNED"))) {
222208
break; // silent G
223209
}
224210
// NOTE: Given that duplicated chars are removed, I don't see how this can ever be true
225211
hard = isPreviousChar(local, n, 'G');
226-
if (!isLastChar(wdsz, n) &&
227-
FRONTV.indexOf(local.charAt(n + 1)) >= 0 &&
228-
!hard) {
212+
if (!isLastChar(wdsz, n) && FRONTV.indexOf(local.charAt(n + 1)) >= 0 && !hard) {
229213
code.append('J');
230214
} else {
231215
code.append('K');
@@ -235,11 +219,10 @@ public String metaphone(final String txt) {
235219
if (isLastChar(wdsz, n)) {
236220
break; // terminal H
237221
}
238-
if (n > 0 &&
239-
VARSON.indexOf(local.charAt(n - 1)) >= 0) {
222+
if (n > 0 && VARSON.indexOf(local.charAt(n - 1)) >= 0) {
240223
break;
241224
}
242-
if (isVowel(local,n+1)) {
225+
if (isVowel(local, n + 1)) {
243226
code.append('H'); // Hvowel
244227
}
245228
break;
@@ -261,7 +244,7 @@ public String metaphone(final String txt) {
261244
}
262245
break;
263246
case 'P':
264-
if (isNextChar(local,n,'H')) {
247+
if (isNextChar(local, n, 'H')) {
265248
// PH -> F
266249
code.append('F');
267250
} else {
@@ -272,37 +255,34 @@ public String metaphone(final String txt) {
272255
code.append('K');
273256
break;
274257
case 'S':
275-
if (regionMatch(local,n,"SH") ||
276-
regionMatch(local,n,"SIO") ||
277-
regionMatch(local,n,"SIA")) {
258+
if (regionMatch(local, n, "SH") || regionMatch(local, n, "SIO") || regionMatch(local, n, "SIA")) {
278259
code.append('X');
279260
} else {
280261
code.append('S');
281262
}
282263
break;
283264
case 'T':
284-
if (regionMatch(local,n,"TIA") ||
285-
regionMatch(local,n,"TIO")) {
265+
if (regionMatch(local, n, "TIA") || regionMatch(local, n, "TIO")) {
286266
code.append('X');
287267
break;
288268
}
289-
if (regionMatch(local,n,"TCH")) {
269+
if (regionMatch(local, n, "TCH")) {
290270
// Silent if in "TCH"
291271
break;
292272
}
293273
// substitute numeral 0 for TH (resembles theta after all)
294-
if (regionMatch(local,n,"TH")) {
274+
if (regionMatch(local, n, "TH")) {
295275
code.append('0');
296276
} else {
297277
code.append('T');
298278
}
299279
break;
300280
case 'V':
301-
code.append('F'); break;
281+
code.append('F');
282+
break;
302283
case 'W':
303284
case 'Y': // silent if not followed by vowel
304-
if (!isLastChar(wdsz,n) &&
305-
isVowel(local,n+1)) {
285+
if (!isLastChar(wdsz, n) && isVowel(local, n + 1)) {
306286
code.append(symb);
307287
}
308288
break;

src/test/java/org/apache/commons/codec/binary/Base32Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public void testRandomBytes() {
336336
final Base32 codec = new Base32();
337337
final byte[][] b = BaseNTestData.randomData(codec, i);
338338
assertEquals(b[1].length, codec.getEncodedLength(b[0]), i + " " + codec.lineLength);
339-
//assertEquals(b[0],codec.decode(b[1]));
339+
//assertEquals(b[0], codec.decode(b[1]));
340340
}
341341
}
342342

@@ -346,7 +346,7 @@ public void testRandomBytesChunked() {
346346
final Base32 codec = new Base32(10);
347347
final byte[][] b = BaseNTestData.randomData(codec, i);
348348
assertEquals(b[1].length, codec.getEncodedLength(b[0]), i + " " + codec.lineLength);
349-
//assertEquals(b[0],codec.decode(b[1]));
349+
//assertEquals(b[0], codec.decode(b[1]));
350350
}
351351
}
352352

@@ -356,7 +356,7 @@ public void testRandomBytesHex() {
356356
final Base32 codec = new Base32(true);
357357
final byte[][] b = BaseNTestData.randomData(codec, i);
358358
assertEquals(b[1].length, codec.getEncodedLength(b[0]), i + " " + codec.lineLength);
359-
//assertEquals(b[0],codec.decode(b[1]));
359+
//assertEquals(b[0], codec.decode(b[1]));
360360
}
361361
}
362362

src/test/java/org/apache/commons/codec/digest/MessageDigestAlgorithmsTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static String[] data() {
9494
private DigestUtilsTest digestUtilsTest;
9595

9696
private byte[] digestTestData(final String messageDigestAlgorithm) {
97-
return DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),getTestData());
97+
return DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), getTestData());
9898
}
9999

100100
private byte[] getTestData() {
@@ -139,9 +139,8 @@ public void testAlgorithm(final String messageDigestAlgorithm) throws NoSuchAlgo
139139
@MethodSource("data")
140140
public void testDigestByteArray(final String messageDigestAlgorithm) {
141141
assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
142-
assertArrayEquals(digestTestData(messageDigestAlgorithm),
143-
DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), getTestData()));
144-
assertArrayEquals(digestTestData(messageDigestAlgorithm), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),getTestData()));
142+
assertArrayEquals(digestTestData(messageDigestAlgorithm), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), getTestData()));
143+
assertArrayEquals(digestTestData(messageDigestAlgorithm), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), getTestData()));
145144
}
146145

147146
@ParameterizedTest
@@ -169,7 +168,8 @@ public void testDigestInputStream(final String messageDigestAlgorithm) throws IO
169168
assumeTrue(DigestUtils.isAvailable(messageDigestAlgorithm));
170169
assertArrayEquals(digestTestData(messageDigestAlgorithm),
171170
DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), new ByteArrayInputStream(getTestData())));
172-
assertArrayEquals(digestTestData(messageDigestAlgorithm), DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm),new ByteArrayInputStream(getTestData())));
171+
assertArrayEquals(digestTestData(messageDigestAlgorithm),
172+
DigestUtils.digest(DigestUtils.getDigest(messageDigestAlgorithm), new ByteArrayInputStream(getTestData())));
173173
}
174174

175175
@ParameterizedTest

0 commit comments

Comments
 (0)