Skip to content

Commit 05f8780

Browse files
committed
Statement unnecessarily nested within else clause.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1725161 13f79535-47bb-0310-9956-ffa450edef68
1 parent 535bd81 commit 05f8780

9 files changed

Lines changed: 99 additions & 116 deletions

File tree

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,21 +348,20 @@ void decode(final byte[] in, int inPos, final int inAvail, final Context context
348348
// We're done.
349349
context.eof = true;
350350
break;
351-
} else {
352-
final byte[] buffer = ensureBufferSize(decodeSize, context);
353-
if (b >= 0 && b < this.decodeTable.length) {
354-
final int result = this.decodeTable[b];
355-
if (result >= 0) {
356-
context.modulus = (context.modulus+1) % BYTES_PER_ENCODED_BLOCK;
357-
// collect decoded bytes
358-
context.lbitWorkArea = (context.lbitWorkArea << BITS_PER_ENCODED_BYTE) + result;
359-
if (context.modulus == 0) { // we can output the 5 bytes
360-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 32) & MASK_8BITS);
361-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 24) & MASK_8BITS);
362-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
363-
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
364-
buffer[context.pos++] = (byte) (context.lbitWorkArea & MASK_8BITS);
365-
}
351+
}
352+
final byte[] buffer = ensureBufferSize(decodeSize, context);
353+
if (b >= 0 && b < this.decodeTable.length) {
354+
final int result = this.decodeTable[b];
355+
if (result >= 0) {
356+
context.modulus = (context.modulus+1) % BYTES_PER_ENCODED_BLOCK;
357+
// collect decoded bytes
358+
context.lbitWorkArea = (context.lbitWorkArea << BITS_PER_ENCODED_BYTE) + result;
359+
if (context.modulus == 0) { // we can output the 5 bytes
360+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 32) & MASK_8BITS);
361+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 24) & MASK_8BITS);
362+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
363+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
364+
buffer[context.pos++] = (byte) (context.lbitWorkArea & MASK_8BITS);
366365
}
367366
}
368367
}

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -441,17 +441,16 @@ void decode(final byte[] in, int inPos, final int inAvail, final Context context
441441
// We're done.
442442
context.eof = true;
443443
break;
444-
} else {
445-
if (b >= 0 && b < DECODE_TABLE.length) {
446-
final int result = DECODE_TABLE[b];
447-
if (result >= 0) {
448-
context.modulus = (context.modulus+1) % BYTES_PER_ENCODED_BLOCK;
449-
context.ibitWorkArea = (context.ibitWorkArea << BITS_PER_ENCODED_BYTE) + result;
450-
if (context.modulus == 0) {
451-
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 16) & MASK_8BITS);
452-
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS);
453-
buffer[context.pos++] = (byte) (context.ibitWorkArea & MASK_8BITS);
454-
}
444+
}
445+
if (b >= 0 && b < DECODE_TABLE.length) {
446+
final int result = DECODE_TABLE[b];
447+
if (result >= 0) {
448+
context.modulus = (context.modulus+1) % BYTES_PER_ENCODED_BLOCK;
449+
context.ibitWorkArea = (context.ibitWorkArea << BITS_PER_ENCODED_BYTE) + result;
450+
if (context.modulus == 0) {
451+
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 16) & MASK_8BITS);
452+
buffer[context.pos++] = (byte) ((context.ibitWorkArea >> 8) & MASK_8BITS);
453+
buffer[context.pos++] = (byte) (context.ibitWorkArea & MASK_8BITS);
455454
}
456455
}
457456
}

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

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -286,42 +286,40 @@ private static void parseRules(final Scanner scanner, final String location,
286286
if (parts.length != 2) {
287287
throw new IllegalArgumentException("Malformed folding statement split into " + parts.length +
288288
" parts: " + rawLine + " in " + location);
289-
} else {
290-
final String leftCharacter = parts[0];
291-
final String rightCharacter = parts[1];
292-
293-
if (leftCharacter.length() != 1 || rightCharacter.length() != 1) {
294-
throw new IllegalArgumentException("Malformed folding statement - " +
295-
"patterns are not single characters: " + rawLine + " in " + location);
296-
}
289+
}
290+
final String leftCharacter = parts[0];
291+
final String rightCharacter = parts[1];
297292

298-
asciiFoldings.put(leftCharacter.charAt(0), rightCharacter.charAt(0));
293+
if (leftCharacter.length() != 1 || rightCharacter.length() != 1) {
294+
throw new IllegalArgumentException("Malformed folding statement - " +
295+
"patterns are not single characters: " + rawLine + " in " + location);
299296
}
297+
298+
asciiFoldings.put(leftCharacter.charAt(0), rightCharacter.charAt(0));
300299
} else {
301300
// rule
302301
final String[] parts = line.split("\\s+");
303302
if (parts.length != 4) {
304303
throw new IllegalArgumentException("Malformed rule statement split into " + parts.length +
305304
" parts: " + rawLine + " in " + location);
306-
} else {
307-
try {
308-
final String pattern = stripQuotes(parts[0]);
309-
final String replacement1 = stripQuotes(parts[1]);
310-
final String replacement2 = stripQuotes(parts[2]);
311-
final String replacement3 = stripQuotes(parts[3]);
312-
313-
final Rule r = new Rule(pattern, replacement1, replacement2, replacement3);
314-
final char patternKey = r.pattern.charAt(0);
315-
List<Rule> rules = ruleMapping.get(patternKey);
316-
if (rules == null) {
317-
rules = new ArrayList<Rule>();
318-
ruleMapping.put(patternKey, rules);
319-
}
320-
rules.add(r);
321-
} catch (final IllegalArgumentException e) {
322-
throw new IllegalStateException(
323-
"Problem parsing line '" + currentLine + "' in " + location, e);
305+
}
306+
try {
307+
final String pattern = stripQuotes(parts[0]);
308+
final String replacement1 = stripQuotes(parts[1]);
309+
final String replacement2 = stripQuotes(parts[2]);
310+
final String replacement3 = stripQuotes(parts[3]);
311+
312+
final Rule r = new Rule(pattern, replacement1, replacement2, replacement3);
313+
final char patternKey = r.pattern.charAt(0);
314+
List<Rule> rules = ruleMapping.get(patternKey);
315+
if (rules == null) {
316+
rules = new ArrayList<Rule>();
317+
ruleMapping.put(patternKey, rules);
324318
}
319+
rules.add(r);
320+
} catch (final IllegalArgumentException e) {
321+
throw new IllegalStateException(
322+
"Problem parsing line '" + currentLine + "' in " + location, e);
325323
}
326324
}
327325
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,8 @@ String getFirst3Last3(final String name) {
163163
final String firstThree = name.substring(0, THREE);
164164
final String lastThree = name.substring(nameLength - THREE, nameLength);
165165
return firstThree + lastThree;
166-
} else {
167-
return name;
168166
}
167+
return name;
169168
}
170169

171170
/**
@@ -335,9 +334,8 @@ int leftToRightThenRightToLeftProcessing(final String name1, final String name2)
335334
// Final bit - subtract longest string from 6 and return this int value
336335
if (strA.length() > strB.length()) {
337336
return Math.abs(SIX - strA.length());
338-
} else {
339-
return Math.abs(SIX - strB.length());
340337
}
338+
return Math.abs(SIX - strB.length());
341339
}
342340

343341
/**
@@ -419,8 +417,7 @@ String removeVowels(String name) {
419417
// return isVowel(firstLetter) ? (firstLetter + name) : name;
420418
if (isVowel(firstLetter)) {
421419
return firstLetter + name;
422-
} else {
423-
return name;
424420
}
421+
return name;
425422
}
426423
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ private static char[] transcodeRemaining(final char prev, final char curr, final
139139
if (curr == 'K') {
140140
if (next == 'N') {
141141
return CHARS_NN;
142-
} else {
143-
return CHARS_C;
144142
}
143+
return CHARS_C;
145144
}
146145

147146
// 4. SCH -> SSS

src/main/java/org/apache/commons/codec/language/bm/Rule.java

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,8 @@ private static Phoneme parsePhoneme(final String ph) {
373373
final Set<String> langs = new HashSet<String>(Arrays.asList(in.split("[+]")));
374374

375375
return new Phoneme(before, Languages.LanguageSet.from(langs));
376-
} else {
377-
return new Phoneme(ph, Languages.ANY_LANGUAGE);
378376
}
377+
return new Phoneme(ph, Languages.ANY_LANGUAGE);
379378
}
380379

381380
private static PhonemeExpr parsePhonemeExpr(final String ph) {
@@ -394,9 +393,8 @@ private static PhonemeExpr parsePhonemeExpr(final String ph) {
394393
}
395394

396395
return new PhonemeList(phs);
397-
} else {
398-
return parsePhoneme(ph);
399396
}
397+
return parsePhoneme(ph);
400398
}
401399

402400
private static Map<String, List<Rule>> parseRules(final Scanner scanner, final String location) {
@@ -436,50 +434,48 @@ private static Map<String, List<Rule>> parseRules(final Scanner scanner, final S
436434
if (incl.contains(" ")) {
437435
throw new IllegalArgumentException("Malformed import statement '" + rawLine + "' in " +
438436
location);
439-
} else {
440-
lines.putAll(parseRules(createScanner(incl), location + "->" + incl));
441437
}
438+
lines.putAll(parseRules(createScanner(incl), location + "->" + incl));
442439
} else {
443440
// rule
444441
final String[] parts = line.split("\\s+");
445442
if (parts.length != 4) {
446443
throw new IllegalArgumentException("Malformed rule statement split into " + parts.length +
447444
" parts: " + rawLine + " in " + location);
448-
} else {
449-
try {
450-
final String pat = stripQuotes(parts[0]);
451-
final String lCon = stripQuotes(parts[1]);
452-
final String rCon = stripQuotes(parts[2]);
453-
final PhonemeExpr ph = parsePhonemeExpr(stripQuotes(parts[3]));
454-
final int cLine = currentLine;
455-
final Rule r = new Rule(pat, lCon, rCon, ph) {
456-
private final int myLine = cLine;
457-
private final String loc = location;
458-
459-
@Override
460-
public String toString() {
461-
final StringBuilder sb = new StringBuilder();
462-
sb.append("Rule");
463-
sb.append("{line=").append(myLine);
464-
sb.append(", loc='").append(loc).append('\'');
465-
sb.append(", pat='").append(pat).append('\'');
466-
sb.append(", lcon='").append(lCon).append('\'');
467-
sb.append(", rcon='").append(rCon).append('\'');
468-
sb.append('}');
469-
return sb.toString();
470-
}
471-
};
472-
final String patternKey = r.pattern.substring(0,1);
473-
List<Rule> rules = lines.get(patternKey);
474-
if (rules == null) {
475-
rules = new ArrayList<Rule>();
476-
lines.put(patternKey, rules);
445+
}
446+
try {
447+
final String pat = stripQuotes(parts[0]);
448+
final String lCon = stripQuotes(parts[1]);
449+
final String rCon = stripQuotes(parts[2]);
450+
final PhonemeExpr ph = parsePhonemeExpr(stripQuotes(parts[3]));
451+
final int cLine = currentLine;
452+
final Rule r = new Rule(pat, lCon, rCon, ph) {
453+
private final int myLine = cLine;
454+
private final String loc = location;
455+
456+
@Override
457+
public String toString() {
458+
final StringBuilder sb = new StringBuilder();
459+
sb.append("Rule");
460+
sb.append("{line=").append(myLine);
461+
sb.append(", loc='").append(loc).append('\'');
462+
sb.append(", pat='").append(pat).append('\'');
463+
sb.append(", lcon='").append(lCon).append('\'');
464+
sb.append(", rcon='").append(rCon).append('\'');
465+
sb.append('}');
466+
return sb.toString();
477467
}
478-
rules.add(r);
479-
} catch (final IllegalArgumentException e) {
480-
throw new IllegalStateException("Problem parsing line '" + currentLine + "' in " +
481-
location, e);
468+
};
469+
final String patternKey = r.pattern.substring(0,1);
470+
List<Rule> rules = lines.get(patternKey);
471+
if (rules == null) {
472+
rules = new ArrayList<Rule>();
473+
lines.put(patternKey, rules);
482474
}
475+
rules.add(r);
476+
} catch (final IllegalArgumentException e) {
477+
throw new IllegalStateException("Problem parsing line '" + currentLine + "' in " +
478+
location, e);
483479
}
484480
}
485481
}
@@ -513,14 +509,13 @@ public boolean isMatch(final CharSequence input) {
513509
return input.length() == 0;
514510
}
515511
};
516-
} else {
517-
return new RPattern() {
518-
@Override
519-
public boolean isMatch(final CharSequence input) {
520-
return input.equals(content);
521-
}
522-
};
523512
}
513+
return new RPattern() {
514+
@Override
515+
public boolean isMatch(final CharSequence input) {
516+
return input.equals(content);
517+
}
518+
};
524519
} else if ((startsWith || endsWith) && content.length() == 0) {
525520
// matches every string
526521
return ALL_STRINGS_RMATCHER;

src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,9 @@ private static int encodeByte(final int b, final boolean encode,
221221
final ByteArrayOutputStream buffer) {
222222
if (encode) {
223223
return encodeQuotedPrintable(b, buffer);
224-
} else {
225-
buffer.write(b);
226-
return 1;
227224
}
225+
buffer.write(b);
226+
return 1;
228227
}
229228

230229
/**

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,16 @@ public class Codec105ErrorInputStream extends InputStream {
3737
public int read() throws IOException {
3838
if (this.countdown-- > 0) {
3939
return '\n';
40-
} else {
41-
return EOF;
4240
}
41+
return EOF;
4342
}
4443

4544
@Override
4645
public int read(final byte b[], final int pos, final int len) throws IOException {
4746
if (this.countdown-- > 0) {
4847
b[pos] = '\n';
4948
return 1;
50-
} else {
51-
return EOF;
5249
}
50+
return EOF;
5351
}
5452
}

src/test/java/org/apache/commons/codec/language/bm/PhoneticEngineRegressionTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ private static String encode(final Map<String, String> args, final boolean conca
237237
*/
238238
if (languageSet == null) {
239239
return engine.encode(input);
240-
} else {
241-
return engine.encode(input, languageSet);
242240
}
241+
return engine.encode(input, languageSet);
243242
}
244243
}

0 commit comments

Comments
 (0)