No need to nest in else.
diff --git a/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java b/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java
index 256d1f1..b054253 100644
--- a/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java
+++ b/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java
@@ -456,11 +456,11 @@
public Object decode(final Object obj) throws DecoderException {
if (obj instanceof byte[]) {
return decode((byte[]) obj);
- } else if (obj instanceof String) {
- return decode((String) obj);
- } else {
- throw new DecoderException("Parameter supplied to Base-N decode is not a byte[] or a String");
}
+ if (obj instanceof String) {
+ return decode((String) obj);
+ }
+ throw new DecoderException("Parameter supplied to Base-N decode is not a byte[] or a String");
}
/**
diff --git a/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java b/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java
index ff99e5c..f225aab 100644
--- a/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java
+++ b/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java
@@ -145,42 +145,43 @@
Objects.requireNonNull(array, "array");
if (offset < 0 || len < 0) {
throw new IndexOutOfBoundsException();
- } else if (offset > array.length || offset + len > array.length) {
- throw new IndexOutOfBoundsException();
- } else if (len == 0) {
- return 0;
- } else {
- int readLen = 0;
- /*
- Rationale for while-loop on (readLen == 0):
- -----
- Base32.readResults() usually returns > 0 or EOF (-1). In the
- rare case where it returns 0, we just keep trying.
-
- This is essentially an undocumented contract for InputStream
- implementors that want their code to work properly with
- java.io.InputStreamReader, since the latter hates it when
- InputStream.read(byte[]) returns a zero. Unfortunately our
- readResults() call must return 0 if a large amount of the data
- being decoded was non-base32, so this while-loop enables proper
- interop with InputStreamReader for that scenario.
- -----
- This is a fix for CODEC-101
- */
- while (readLen == 0) {
- if (!baseNCodec.hasData(context)) {
- final byte[] buf = new byte[doEncode ? 4096 : 8192];
- final int c = in.read(buf);
- if (doEncode) {
- baseNCodec.encode(buf, 0, c, context);
- } else {
- baseNCodec.decode(buf, 0, c, context);
- }
- }
- readLen = baseNCodec.readResults(array, offset, len, context);
- }
- return readLen;
}
+ if (offset > array.length || offset + len > array.length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len == 0) {
+ return 0;
+ }
+ int readLen = 0;
+ /*
+ Rationale for while-loop on (readLen == 0):
+ -----
+ Base32.readResults() usually returns > 0 or EOF (-1). In the
+ rare case where it returns 0, we just keep trying.
+
+ This is essentially an undocumented contract for InputStream
+ implementors that want their code to work properly with
+ java.io.InputStreamReader, since the latter hates it when
+ InputStream.read(byte[]) returns a zero. Unfortunately our
+ readResults() call must return 0 if a large amount of the data
+ being decoded was non-base32, so this while-loop enables proper
+ interop with InputStreamReader for that scenario.
+ -----
+ This is a fix for CODEC-101
+ */
+ while (readLen == 0) {
+ if (!baseNCodec.hasData(context)) {
+ final byte[] buf = new byte[doEncode ? 4096 : 8192];
+ final int c = in.read(buf);
+ if (doEncode) {
+ baseNCodec.encode(buf, 0, c, context);
+ } else {
+ baseNCodec.decode(buf, 0, c, context);
+ }
+ }
+ readLen = baseNCodec.readResults(array, offset, len, context);
+ }
+ return readLen;
}
/**
diff --git a/src/main/java/org/apache/commons/codec/binary/BaseNCodecOutputStream.java b/src/main/java/org/apache/commons/codec/binary/BaseNCodecOutputStream.java
index 074f96d..16cb6cd 100644
--- a/src/main/java/org/apache/commons/codec/binary/BaseNCodecOutputStream.java
+++ b/src/main/java/org/apache/commons/codec/binary/BaseNCodecOutputStream.java
@@ -166,9 +166,11 @@
Objects.requireNonNull(array, "array");
if (offset < 0 || len < 0) {
throw new IndexOutOfBoundsException();
- } else if (offset > array.length || offset + len > array.length) {
+ }
+ if (offset > array.length || offset + len > array.length) {
throw new IndexOutOfBoundsException();
- } else if (len > 0) {
+ }
+ if (len > 0) {
if (doEncode) {
baseNCodec.encode(array, offset, len, context);
} else {
diff --git a/src/main/java/org/apache/commons/codec/binary/Hex.java b/src/main/java/org/apache/commons/codec/binary/Hex.java
index 7075ab9..5e086b6 100644
--- a/src/main/java/org/apache/commons/codec/binary/Hex.java
+++ b/src/main/java/org/apache/commons/codec/binary/Hex.java
@@ -451,16 +451,17 @@
public Object decode(final Object object) throws DecoderException {
if (object instanceof String) {
return decode(((String) object).toCharArray());
- } else if (object instanceof byte[]) {
+ }
+ if (object instanceof byte[]) {
return decode((byte[]) object);
- } else if (object instanceof ByteBuffer) {
+ }
+ if (object instanceof ByteBuffer) {
return decode((ByteBuffer) object);
- } else {
- try {
- return decodeHex((char[]) object);
- } catch (final ClassCastException e) {
- throw new DecoderException(e.getMessage(), e);
- }
+ }
+ try {
+ return decodeHex((char[]) object);
+ } catch (final ClassCastException e) {
+ throw new DecoderException(e.getMessage(), e);
}
}
diff --git a/src/main/java/org/apache/commons/codec/digest/Crypt.java b/src/main/java/org/apache/commons/codec/digest/Crypt.java
index e73ec9f..f6ac066 100644
--- a/src/main/java/org/apache/commons/codec/digest/Crypt.java
+++ b/src/main/java/org/apache/commons/codec/digest/Crypt.java
@@ -74,15 +74,17 @@
public static String crypt(final byte[] keyBytes, final String salt) {
if (salt == null) {
return Sha2Crypt.sha512Crypt(keyBytes);
- } else if (salt.startsWith(Sha2Crypt.SHA512_PREFIX)) {
- return Sha2Crypt.sha512Crypt(keyBytes, salt);
- } else if (salt.startsWith(Sha2Crypt.SHA256_PREFIX)) {
- return Sha2Crypt.sha256Crypt(keyBytes, salt);
- } else if (salt.startsWith(Md5Crypt.MD5_PREFIX)) {
- return Md5Crypt.md5Crypt(keyBytes, salt);
- } else {
- return UnixCrypt.crypt(keyBytes, salt);
}
+ if (salt.startsWith(Sha2Crypt.SHA512_PREFIX)) {
+ return Sha2Crypt.sha512Crypt(keyBytes, salt);
+ }
+ if (salt.startsWith(Sha2Crypt.SHA256_PREFIX)) {
+ return Sha2Crypt.sha256Crypt(keyBytes, salt);
+ }
+ if (salt.startsWith(Md5Crypt.MD5_PREFIX)) {
+ return Md5Crypt.md5Crypt(keyBytes, salt);
+ }
+ return UnixCrypt.crypt(keyBytes, salt);
}
/**
diff --git a/src/main/java/org/apache/commons/codec/language/DaitchMokotoffSoundex.java b/src/main/java/org/apache/commons/codec/language/DaitchMokotoffSoundex.java
index cff0f1e..4d4c74a 100644
--- a/src/main/java/org/apache/commons/codec/language/DaitchMokotoffSoundex.java
+++ b/src/main/java/org/apache/commons/codec/language/DaitchMokotoffSoundex.java
@@ -520,11 +520,10 @@
nextBranch.processNextReplacement(nextReplacement, force);
- if (branching) {
- nextBranches.add(nextBranch);
- } else {
+ if (!branching) {
break;
}
+ nextBranches.add(nextBranch);
}
}
diff --git a/src/main/java/org/apache/commons/codec/language/DoubleMetaphone.java b/src/main/java/org/apache/commons/codec/language/DoubleMetaphone.java
index 63e0922..ec2a2e0 100644
--- a/src/main/java/org/apache/commons/codec/language/DoubleMetaphone.java
+++ b/src/main/java/org/apache/commons/codec/language/DoubleMetaphone.java
@@ -354,26 +354,27 @@
if (index > 0 && contains(value, index, 4, "CHAE")) { // Michael
result.append('K', 'X');
return index + 2;
- } else if (conditionCH0(value, index)) {
+ }
+ if (conditionCH0(value, index)) {
//-- Greek roots ("chemistry", "chorus", etc.) --//
result.append('K');
return index + 2;
- } else if (conditionCH1(value, index)) {
+ }
+ if (conditionCH1(value, index)) {
//-- Germanic, Greek, or otherwise 'ch' for 'kh' sound --//
result.append('K');
return index + 2;
- } else {
- if (index > 0) {
- if (contains(value, 0, 2, "MC")) {
- result.append('K');
- } else {
- result.append('X', 'K');
- }
- } else {
- result.append('X');
- }
- return index + 2;
}
+ if (index > 0) {
+ if (contains(value, 0, 2, "MC")) {
+ result.append('K');
+ } else {
+ result.append('X', 'K');
+ }
+ } else {
+ result.append('X');
+ }
+ return index + 2;
}
/**
@@ -779,17 +780,19 @@
private boolean conditionC0(final String value, final int index) {
if (contains(value, index, 4, "CHIA")) {
return true;
- } else if (index <= 1) {
- return false;
- } else if (isVowel(charAt(value, index - 2))) {
- return false;
- } else if (!contains(value, index - 1, 3, "ACH")) {
- return false;
- } else {
- final char c = charAt(value, index + 2);
- return (c != 'I' && c != 'E') ||
- contains(value, index - 2, 6, "BACHER", "MACHER");
}
+ if (index <= 1) {
+ return false;
+ }
+ if (isVowel(charAt(value, index - 2))) {
+ return false;
+ }
+ if (!contains(value, index - 1, 3, "ACH")) {
+ return false;
+ }
+ final char c = charAt(value, index + 2);
+ return (c != 'I' && c != 'E') ||
+ contains(value, index - 2, 6, "BACHER", "MACHER");
}
/**
@@ -798,14 +801,15 @@
private boolean conditionCH0(final String value, final int index) {
if (index != 0) {
return false;
- } else if (!contains(value, index + 1, 5, "HARAC", "HARIS") &&
+ }
+ if (!contains(value, index + 1, 5, "HARAC", "HARIS") &&
!contains(value, index + 1, 3, "HOR", "HYM", "HIA", "HEM")) {
return false;
- } else if (contains(value, 0, 5, "CHORE")) {
- return false;
- } else {
- return true;
}
+ if (contains(value, 0, 5, "CHORE")) {
+ return false;
+ }
+ return true;
}
/**
@@ -826,13 +830,13 @@
if (index == value.length() - 3 &&
contains(value, index - 1, 4, "ILLO", "ILLA", "ALLE")) {
return true;
- } else if ((contains(value, value.length() - 2, 2, "AS", "OS") ||
+ }
+ if ((contains(value, value.length() - 2, 2, "AS", "OS") ||
contains(value, value.length() - 1, 1, "A", "O")) &&
contains(value, index - 1, 4, "ALLE")) {
return true;
- } else {
- return false;
}
+ return false;
}
/**
diff --git a/src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java b/src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java
index 50f6e81..dc56fb4 100644
--- a/src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java
+++ b/src/main/java/org/apache/commons/codec/language/MatchRatingApproachEncoder.java
@@ -212,11 +212,14 @@
// Bulletproof for trivial input - NINO
if (name1 == null || EMPTY.equalsIgnoreCase(name1) || SPACE.equalsIgnoreCase(name1)) {
return false;
- } else if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) {
+ }
+ if (name2 == null || EMPTY.equalsIgnoreCase(name2) || SPACE.equalsIgnoreCase(name2)) {
return false;
- } else if (name1.length() == 1 || name2.length() == 1) {
+ }
+ if (name1.length() == 1 || name2.length() == 1) {
return false;
- } else if (name1.equalsIgnoreCase(name2)) {
+ }
+ if (name1.equalsIgnoreCase(name2)) {
return true;
}
diff --git a/src/main/java/org/apache/commons/codec/language/RefinedSoundex.java b/src/main/java/org/apache/commons/codec/language/RefinedSoundex.java
index e98f1a0..72a914a 100644
--- a/src/main/java/org/apache/commons/codec/language/RefinedSoundex.java
+++ b/src/main/java/org/apache/commons/codec/language/RefinedSoundex.java
@@ -204,7 +204,8 @@
current = getMappingCode(str.charAt(i));
if (current == last) {
continue;
- } else if (current != 0) {
+ }
+ if (current != 0) {
sBuf.append(current);
}
diff --git a/src/main/java/org/apache/commons/codec/language/bm/Languages.java b/src/main/java/org/apache/commons/codec/language/bm/Languages.java
index 778b072..4e058ed 100644
--- a/src/main/java/org/apache/commons/codec/language/bm/Languages.java
+++ b/src/main/java/org/apache/commons/codec/language/bm/Languages.java
@@ -120,32 +120,32 @@
public LanguageSet restrictTo(final LanguageSet other) {
if (other == NO_LANGUAGES) {
return other;
- } else if (other == ANY_LANGUAGE) {
- return this;
- } else {
- final SomeLanguages someLanguages = (SomeLanguages) other;
- final Set<String> set = new HashSet<>(Math.min(languages.size(), someLanguages.languages.size()));
- for (final String lang : languages) {
- if (someLanguages.languages.contains(lang)) {
- set.add(lang);
- }
- }
- return from(set);
}
+ if (other == ANY_LANGUAGE) {
+ return this;
+ }
+ final SomeLanguages someLanguages = (SomeLanguages) other;
+ final Set<String> set = new HashSet<>(Math.min(languages.size(), someLanguages.languages.size()));
+ for (final String lang : languages) {
+ if (someLanguages.languages.contains(lang)) {
+ set.add(lang);
+ }
+ }
+ return from(set);
}
@Override
public LanguageSet merge(final LanguageSet other) {
if (other == NO_LANGUAGES) {
return this;
- } else if (other == ANY_LANGUAGE) {
- return other;
- } else {
- final SomeLanguages someLanguages = (SomeLanguages) other;
- final Set<String> set = new HashSet<>(languages);
- set.addAll(someLanguages.languages);
- return from(set);
}
+ if (other == ANY_LANGUAGE) {
+ return other;
+ }
+ final SomeLanguages someLanguages = (SomeLanguages) other;
+ final Set<String> set = new HashSet<>(languages);
+ set.addAll(someLanguages.languages);
+ return from(set);
}
@Override
diff --git a/src/main/java/org/apache/commons/codec/language/bm/Rule.java b/src/main/java/org/apache/commons/codec/language/bm/Rule.java
index 1939945..f46f544 100644
--- a/src/main/java/org/apache/commons/codec/language/bm/Rule.java
+++ b/src/main/java/org/apache/commons/codec/language/bm/Rule.java
@@ -515,10 +515,12 @@
return input.equals(content);
}
};
- } else if ((startsWith || endsWith) && content.isEmpty()) {
+ }
+ if ((startsWith || endsWith) && content.isEmpty()) {
// matches every string
return ALL_STRINGS_RMATCHER;
- } else if (startsWith) {
+ }
+ if (startsWith) {
// matches from start
return new RPattern() {
@Override
@@ -526,7 +528,8 @@
return startsWith(input, content);
}
};
- } else if (endsWith) {
+ }
+ if (endsWith) {
// matches from start
return new RPattern() {
@Override
@@ -558,7 +561,8 @@
return input.length() == 1 && contains(bContent, input.charAt(0)) == shouldMatch;
}
};
- } else if (startsWith) {
+ }
+ if (startsWith) {
// first char
return new RPattern() {
@Override
@@ -566,7 +570,8 @@
return input.length() > 0 && contains(bContent, input.charAt(0)) == shouldMatch;
}
};
- } else if (endsWith) {
+ }
+ if (endsWith) {
// last char
return new RPattern() {
@Override
@@ -706,7 +711,8 @@
// fail early if any of the evaluations is not successful
if (!input.subSequence(i, ipl).equals(this.pattern)) {
return false;
- } else if (!this.rContext.isMatch(input.subSequence(ipl, input.length()))) {
+ }
+ if (!this.rContext.isMatch(input.subSequence(ipl, input.length()))) {
return false;
}
return this.lContext.isMatch(input.subSequence(0, i));
diff --git a/src/main/java/org/apache/commons/codec/net/BCodec.java b/src/main/java/org/apache/commons/codec/net/BCodec.java
index 46263c2..6da4600 100644
--- a/src/main/java/org/apache/commons/codec/net/BCodec.java
+++ b/src/main/java/org/apache/commons/codec/net/BCodec.java
@@ -241,13 +241,13 @@
public Object encode(final Object value) throws EncoderException {
if (value == null) {
return null;
- } else if (value instanceof String) {
- return encode((String) value);
- } else {
- throw new EncoderException("Objects of type " +
- value.getClass().getName() +
- " cannot be encoded using BCodec");
}
+ if (value instanceof String) {
+ return encode((String) value);
+ }
+ throw new EncoderException("Objects of type " +
+ value.getClass().getName() +
+ " cannot be encoded using BCodec");
}
/**
@@ -265,13 +265,13 @@
public Object decode(final Object value) throws DecoderException {
if (value == null) {
return null;
- } else if (value instanceof String) {
- return decode((String) value);
- } else {
- throw new DecoderException("Objects of type " +
- value.getClass().getName() +
- " cannot be decoded using BCodec");
}
+ if (value instanceof String) {
+ return decode((String) value);
+ }
+ throw new DecoderException("Objects of type " +
+ value.getClass().getName() +
+ " cannot be decoded using BCodec");
}
/**
diff --git a/src/main/java/org/apache/commons/codec/net/PercentCodec.java b/src/main/java/org/apache/commons/codec/net/PercentCodec.java
index 2c0ca4c..16e3320 100644
--- a/src/main/java/org/apache/commons/codec/net/PercentCodec.java
+++ b/src/main/java/org/apache/commons/codec/net/PercentCodec.java
@@ -236,11 +236,11 @@
public Object encode(final Object obj) throws EncoderException {
if (obj == null) {
return null;
- } else if (obj instanceof byte[]) {
- return encode((byte[]) obj);
- } else {
- throw new EncoderException("Objects of type " + obj.getClass().getName() + " cannot be Percent encoded");
}
+ if (obj instanceof byte[]) {
+ return encode((byte[]) obj);
+ }
+ throw new EncoderException("Objects of type " + obj.getClass().getName() + " cannot be Percent encoded");
}
/**
@@ -254,10 +254,10 @@
public Object decode(final Object obj) throws DecoderException {
if (obj == null) {
return null;
- } else if (obj instanceof byte[]) {
- return decode((byte[]) obj);
- } else {
- throw new DecoderException("Objects of type " + obj.getClass().getName() + " cannot be Percent decoded");
}
+ if (obj instanceof byte[]) {
+ return decode((byte[]) obj);
+ }
+ throw new DecoderException("Objects of type " + obj.getClass().getName() + " cannot be Percent decoded");
}
}
diff --git a/src/main/java/org/apache/commons/codec/net/QCodec.java b/src/main/java/org/apache/commons/codec/net/QCodec.java
index 0250e08..5a6745f 100644
--- a/src/main/java/org/apache/commons/codec/net/QCodec.java
+++ b/src/main/java/org/apache/commons/codec/net/QCodec.java
@@ -285,13 +285,13 @@
public Object encode(final Object obj) throws EncoderException {
if (obj == null) {
return null;
- } else if (obj instanceof String) {
- return encode((String) obj);
- } else {
- throw new EncoderException("Objects of type " +
- obj.getClass().getName() +
- " cannot be encoded using Q codec");
}
+ if (obj instanceof String) {
+ return encode((String) obj);
+ }
+ throw new EncoderException("Objects of type " +
+ obj.getClass().getName() +
+ " cannot be encoded using Q codec");
}
/**
@@ -309,13 +309,13 @@
public Object decode(final Object obj) throws DecoderException {
if (obj == null) {
return null;
- } else if (obj instanceof String) {
- return decode((String) obj);
- } else {
- throw new DecoderException("Objects of type " +
- obj.getClass().getName() +
- " cannot be decoded using Q codec");
}
+ if (obj instanceof String) {
+ return decode((String) obj);
+ }
+ throw new DecoderException("Objects of type " +
+ obj.getClass().getName() +
+ " cannot be decoded using Q codec");
}
/**
diff --git a/src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java b/src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java
index 5641dc8..7ab7707 100644
--- a/src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java
+++ b/src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java
@@ -507,15 +507,16 @@
public Object encode(final Object obj) throws EncoderException {
if (obj == null) {
return null;
- } else if (obj instanceof byte[]) {
- return encode((byte[]) obj);
- } else if (obj instanceof String) {
- return encode((String) obj);
- } else {
- throw new EncoderException("Objects of type " +
- obj.getClass().getName() +
- " cannot be quoted-printable encoded");
}
+ if (obj instanceof byte[]) {
+ return encode((byte[]) obj);
+ }
+ if (obj instanceof String) {
+ return encode((String) obj);
+ }
+ throw new EncoderException("Objects of type " +
+ obj.getClass().getName() +
+ " cannot be quoted-printable encoded");
}
/**
@@ -533,15 +534,16 @@
public Object decode(final Object obj) throws DecoderException {
if (obj == null) {
return null;
- } else if (obj instanceof byte[]) {
- return decode((byte[]) obj);
- } else if (obj instanceof String) {
- return decode((String) obj);
- } else {
- throw new DecoderException("Objects of type " +
- obj.getClass().getName() +
- " cannot be quoted-printable decoded");
}
+ if (obj instanceof byte[]) {
+ return decode((byte[]) obj);
+ }
+ if (obj instanceof String) {
+ return decode((String) obj);
+ }
+ throw new DecoderException("Objects of type " +
+ obj.getClass().getName() +
+ " cannot be quoted-printable decoded");
}
/**
diff --git a/src/main/java/org/apache/commons/codec/net/URLCodec.java b/src/main/java/org/apache/commons/codec/net/URLCodec.java
index 5c19bc6..d5809f3 100644
--- a/src/main/java/org/apache/commons/codec/net/URLCodec.java
+++ b/src/main/java/org/apache/commons/codec/net/URLCodec.java
@@ -315,14 +315,14 @@
public Object encode(final Object obj) throws EncoderException {
if (obj == null) {
return null;
- } else if (obj instanceof byte[]) {
- return encode((byte[])obj);
- } else if (obj instanceof String) {
- return encode((String)obj);
- } else {
- throw new EncoderException("Objects of type " + obj.getClass().getName() + " cannot be URL encoded");
-
}
+ if (obj instanceof byte[]) {
+ return encode((byte[])obj);
+ }
+ if (obj instanceof String) {
+ return encode((String)obj);
+ }
+ throw new EncoderException("Objects of type " + obj.getClass().getName() + " cannot be URL encoded");
}
/**
@@ -340,14 +340,14 @@
public Object decode(final Object obj) throws DecoderException {
if (obj == null) {
return null;
- } else if (obj instanceof byte[]) {
- return decode((byte[]) obj);
- } else if (obj instanceof String) {
- return decode((String) obj);
- } else {
- throw new DecoderException("Objects of type " + obj.getClass().getName() + " cannot be URL decoded");
-
}
+ if (obj instanceof byte[]) {
+ return decode((byte[]) obj);
+ }
+ if (obj instanceof String) {
+ return decode((String) obj);
+ }
+ throw new DecoderException("Objects of type " + obj.getClass().getName() + " cannot be URL decoded");
}
/**