This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 91928eed34c1284f0d3c0db0635c39c0cb114047
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Mon Feb 22 11:12:20 2021 -0500

    Combine nested 'if' statement in 'else' block to 'else if'.
---
 .../java/org/apache/commons/lang3/ClassUtils.java  |   6 +-
 .../apache/commons/lang3/RandomStringUtils.java    |  16 +-
 .../java/org/apache/commons/lang3/StringUtils.java |  22 +--
 .../commons/lang3/builder/CompareToBuilder.java    |  18 +-
 .../commons/lang3/builder/EqualsBuilder.java       |  26 ++-
 .../commons/lang3/builder/HashCodeBuilder.java     |  12 +-
 .../commons/lang3/builder/ToStringStyle.java       |   8 +-
 .../apache/commons/lang3/text/StrSubstitutor.java  | 192 ++++++++++-----------
 .../org/apache/commons/lang3/text/WordUtils.java   |  36 ++--
 .../lang3/text/translate/NumericEntityEscaper.java |   6 +-
 .../lang3/text/translate/UnicodeEscaper.java       |   6 +-
 .../commons/lang3/time/DurationFormatUtils.java    |  54 +++---
 12 files changed, 185 insertions(+), 217 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java 
b/src/main/java/org/apache/commons/lang3/ClassUtils.java
index d1462ed..e6a0931 100644
--- a/src/main/java/org/apache/commons/lang3/ClassUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java
@@ -1458,10 +1458,8 @@ public class ClassUtils {
                 className.endsWith(";")
                     ? className.length() - 1
                     : className.length());
-        } else {
-            if (!className.isEmpty()) {
-                className = reverseAbbreviationMap.get(className.substring(0, 
1));
-            }
+        } else if (!className.isEmpty()) {
+            className = reverseAbbreviationMap.get(className.substring(0, 1));
         }
         final StringBuilder canonicalClassNameBuffer = new 
StringBuilder(className);
         for (int i = 0; i < dim; i++) {
diff --git a/src/main/java/org/apache/commons/lang3/RandomStringUtils.java 
b/src/main/java/org/apache/commons/lang3/RandomStringUtils.java
index f089394..23d2161 100644
--- a/src/main/java/org/apache/commons/lang3/RandomStringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/RandomStringUtils.java
@@ -372,18 +372,14 @@ public class RandomStringUtils {
         if (start == 0 && end == 0) {
             if (chars != null) {
                 end = chars.length;
+            } else if (!letters && !numbers) {
+                end = Character.MAX_CODE_POINT;
             } else {
-                if (!letters && !numbers) {
-                    end = Character.MAX_CODE_POINT;
-                } else {
-                    end = 'z' + 1;
-                    start = ' ';
-                }
-            }
-        } else {
-            if (end <= start) {
-                throw new IllegalArgumentException("Parameter end (" + end + 
") must be greater than start (" + start + ")");
+                end = 'z' + 1;
+                start = ' ';
             }
+        } else if (end <= start) {
+            throw new IllegalArgumentException("Parameter end (" + end + ") 
must be greater than start (" + start + ")");
         }
 
         final int zero_digit_ascii = 48;
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java 
b/src/main/java/org/apache/commons/lang3/StringUtils.java
index cea878f..284c202 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -2946,10 +2946,8 @@ public class StringUtils {
                 if (chFound && CharSequenceUtils.indexOf(searchChars, ch2, 0) 
< 0) {
                     return i;
                 }
-            } else {
-                if (!chFound) {
-                    return i;
-                }
+            } else if (!chFound) {
+                return i;
             }
         }
         return INDEX_NOT_FOUND;
@@ -6747,11 +6745,9 @@ public class StringUtils {
             // see if we need to keep searching for this
             if (tempIndex == -1) {
                 noMoreMatchesForReplIndex[i] = true;
-            } else {
-                if (textIndex == -1 || tempIndex < textIndex) {
-                    textIndex = tempIndex;
-                    replaceIndex = i;
-                }
+            } else if (textIndex == -1 || tempIndex < textIndex) {
+                textIndex = tempIndex;
+                replaceIndex = i;
             }
         }
         // NOTE: logic mostly below END
@@ -6804,11 +6800,9 @@ public class StringUtils {
                 // see if we need to keep searching for this
                 if (tempIndex == -1) {
                     noMoreMatchesForReplIndex[i] = true;
-                } else {
-                    if (textIndex == -1 || tempIndex < textIndex) {
-                        textIndex = tempIndex;
-                        replaceIndex = i;
-                    }
+                } else if (textIndex == -1 || tempIndex < textIndex) {
+                    textIndex = tempIndex;
+                    replaceIndex = i;
                 }
             }
             // NOTE: logic duplicated above END
diff --git 
a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java 
b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
index ecb9bcc..8a8580b 100644
--- a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
@@ -420,17 +420,15 @@ public class CompareToBuilder implements Builder<Integer> 
{
         if (lhs.getClass().isArray()) {
             // factor out array case in order to keep method small enough to 
be inlined
             appendArray(lhs, rhs, comparator);
+        } else // the simple case, not an array, just test the element
+        if (comparator == null) {
+            @SuppressWarnings("unchecked") // assume this can be done; if not 
throw CCE as per Javadoc
+            final Comparable<Object> comparable = (Comparable<Object>) lhs;
+            comparison = comparable.compareTo(rhs);
         } else {
-            // the simple case, not an array, just test the element
-            if (comparator == null) {
-                @SuppressWarnings("unchecked") // assume this can be done; if 
not throw CCE as per Javadoc
-                final Comparable<Object> comparable = (Comparable<Object>) lhs;
-                comparison = comparable.compareTo(rhs);
-            } else {
-                @SuppressWarnings("unchecked") // assume this can be done; if 
not throw CCE as per Javadoc
-                final Comparator<Object> comparator2 = (Comparator<Object>) 
comparator;
-                comparison = comparator2.compare(lhs, rhs);
-            }
+            @SuppressWarnings("unchecked") // assume this can be done; if not 
throw CCE as per Javadoc
+            final Comparator<Object> comparator2 = (Comparator<Object>) 
comparator;
+            comparison = comparator2.compare(lhs, rhs);
         }
         return this;
     }
diff --git a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java 
b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
index 0911def..41b6948 100644
--- a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
@@ -532,17 +532,15 @@ public class EqualsBuilder implements Builder<Boolean> {
         try {
             if (testClass.isArray()) {
                 append(lhs, rhs);
+            } else //If either class is being excluded, call normal object 
equals method on lhsClass.
+            if (bypassReflectionClasses != null
+                    && (bypassReflectionClasses.contains(lhsClass) || 
bypassReflectionClasses.contains(rhsClass))) {
+                isEquals = lhs.equals(rhs);
             } else {
-                //If either class is being excluded, call normal object equals 
method on lhsClass.
-                if (bypassReflectionClasses != null
-                        && (bypassReflectionClasses.contains(lhsClass) || 
bypassReflectionClasses.contains(rhsClass))) {
-                    isEquals = lhs.equals(rhs);
-                } else {
+                reflectionAppend(lhs, rhs, testClass);
+                while (testClass.getSuperclass() != null && testClass != 
reflectUpToClass) {
+                    testClass = testClass.getSuperclass();
                     reflectionAppend(lhs, rhs, testClass);
-                    while (testClass.getSuperclass() != null && testClass != 
reflectUpToClass) {
-                        testClass = testClass.getSuperclass();
-                        reflectionAppend(lhs, rhs, testClass);
-                    }
                 }
             }
         } catch (final IllegalArgumentException e) {
@@ -644,13 +642,11 @@ public class EqualsBuilder implements Builder<Boolean> {
             // factor out array case in order to keep method small enough
             // to be inlined
             appendArray(lhs, rhs);
+        } else // The simple case, not an array, just test the element
+        if (testRecursive && !ClassUtils.isPrimitiveOrWrapper(lhsClass)) {
+            reflectionAppend(lhs, rhs);
         } else {
-            // The simple case, not an array, just test the element
-            if (testRecursive && !ClassUtils.isPrimitiveOrWrapper(lhsClass)) {
-                reflectionAppend(lhs, rhs);
-            } else {
-                isEquals = lhs.equals(rhs);
-            }
+            isEquals = lhs.equals(rhs);
         }
         return this;
     }
diff --git 
a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java 
b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
index 319f704..b1cc73d 100644
--- a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
@@ -842,14 +842,12 @@ public class HashCodeBuilder implements Builder<Integer> {
         if (object == null) {
             iTotal = iTotal * iConstant;
 
+        } else if (object.getClass().isArray()) {
+            // factor out array case in order to keep method small enough
+            // to be inlined
+            appendArray(object);
         } else {
-            if (object.getClass().isArray()) {
-                // factor out array case in order to keep method small enough
-                // to be inlined
-                appendArray(object);
-            } else {
-                iTotal = iTotal * iConstant + object.hashCode();
-            }
+            iTotal = iTotal * iConstant + object.hashCode();
         }
         return this;
     }
diff --git a/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java 
b/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java
index 3497c36..c2860d2 100644
--- a/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java
+++ b/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java
@@ -575,12 +575,10 @@ public abstract class ToStringStyle implements 
Serializable {
                     appendSummary(buffer, fieldName, (Object[]) value);
                 }
 
+            } else if (detail) {
+                appendDetail(buffer, fieldName, value);
             } else {
-                if (detail) {
-                    appendDetail(buffer, fieldName, value);
-                } else {
-                    appendSummary(buffer, fieldName, value);
-                }
+                appendSummary(buffer, fieldName, value);
             }
         } finally {
             unregister(value);
diff --git a/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java 
b/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java
index 44d16a1..bc52884 100644
--- a/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java
+++ b/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java
@@ -773,114 +773,112 @@ public class StrSubstitutor {
                     bufEnd);
             if (startMatchLen == 0) {
                 pos++;
+            } else // found variable start marker
+            if (pos > offset && chars[pos - 1] == escape) {
+                // escaped
+                if (preserveEscapes) {
+                    pos++;
+                    continue;
+                }
+                buf.deleteCharAt(pos - 1);
+                chars = buf.buffer; // in case buffer was altered
+                lengthChange--;
+                altered = true;
+                bufEnd--;
             } else {
-                // found variable start marker
-                if (pos > offset && chars[pos - 1] == escape) {
-                    // escaped
-                    if (preserveEscapes) {
-                        pos++;
+                // find suffix
+                final int startPos = pos;
+                pos += startMatchLen;
+                int endMatchLen = 0;
+                int nestedVarCount = 0;
+                while (pos < bufEnd) {
+                    if (substitutionInVariablesEnabled
+                            && (endMatchLen = pfxMatcher.isMatch(chars,
+                                    pos, offset, bufEnd)) != 0) {
+                        // found a nested variable start
+                        nestedVarCount++;
+                        pos += endMatchLen;
                         continue;
                     }
-                    buf.deleteCharAt(pos - 1);
-                    chars = buf.buffer; // in case buffer was altered
-                    lengthChange--;
-                    altered = true;
-                    bufEnd--;
-                } else {
-                    // find suffix
-                    final int startPos = pos;
-                    pos += startMatchLen;
-                    int endMatchLen = 0;
-                    int nestedVarCount = 0;
-                    while (pos < bufEnd) {
-                        if (substitutionInVariablesEnabled
-                                && (endMatchLen = pfxMatcher.isMatch(chars,
-                                        pos, offset, bufEnd)) != 0) {
-                            // found a nested variable start
-                            nestedVarCount++;
-                            pos += endMatchLen;
-                            continue;
-                        }
 
-                        endMatchLen = suffMatcher.isMatch(chars, pos, offset,
-                                bufEnd);
-                        if (endMatchLen == 0) {
-                            pos++;
-                        } else {
-                            // found variable end marker
-                            if (nestedVarCount == 0) {
-                                String varNameExpr = new String(chars, startPos
-                                        + startMatchLen, pos - startPos
-                                        - startMatchLen);
-                                if (substitutionInVariablesEnabled) {
-                                    final StrBuilder bufName = new 
StrBuilder(varNameExpr);
-                                    substitute(bufName, 0, bufName.length());
-                                    varNameExpr = bufName.toString();
-                                }
-                                pos += endMatchLen;
-                                final int endPos = pos;
-
-                                String varName = varNameExpr;
-                                String varDefaultValue = null;
-
-                                if (valueDelimMatcher != null) {
-                                    final char [] varNameExprChars = 
varNameExpr.toCharArray();
-                                    int valueDelimiterMatchLen = 0;
-                                    for (int i = 0; i < 
varNameExprChars.length; i++) {
-                                        // if there's any nested variable when 
nested variable substitution disabled, then stop resolving name and default 
value.
-                                        if (!substitutionInVariablesEnabled
-                                                && 
pfxMatcher.isMatch(varNameExprChars, i, i, varNameExprChars.length) != 0) {
-                                            break;
-                                        }
-                                        if ((valueDelimiterMatchLen = 
valueDelimMatcher.isMatch(varNameExprChars, i)) != 0) {
-                                            varName = varNameExpr.substring(0, 
i);
-                                            varDefaultValue = 
varNameExpr.substring(i + valueDelimiterMatchLen);
-                                            break;
-                                        }
+                    endMatchLen = suffMatcher.isMatch(chars, pos, offset,
+                            bufEnd);
+                    if (endMatchLen == 0) {
+                        pos++;
+                    } else {
+                        // found variable end marker
+                        if (nestedVarCount == 0) {
+                            String varNameExpr = new String(chars, startPos
+                                    + startMatchLen, pos - startPos
+                                    - startMatchLen);
+                            if (substitutionInVariablesEnabled) {
+                                final StrBuilder bufName = new 
StrBuilder(varNameExpr);
+                                substitute(bufName, 0, bufName.length());
+                                varNameExpr = bufName.toString();
+                            }
+                            pos += endMatchLen;
+                            final int endPos = pos;
+
+                            String varName = varNameExpr;
+                            String varDefaultValue = null;
+
+                            if (valueDelimMatcher != null) {
+                                final char [] varNameExprChars = 
varNameExpr.toCharArray();
+                                int valueDelimiterMatchLen = 0;
+                                for (int i = 0; i < varNameExprChars.length; 
i++) {
+                                    // if there's any nested variable when 
nested variable substitution disabled, then stop resolving name and default 
value.
+                                    if (!substitutionInVariablesEnabled
+                                            && 
pfxMatcher.isMatch(varNameExprChars, i, i, varNameExprChars.length) != 0) {
+                                        break;
+                                    }
+                                    if ((valueDelimiterMatchLen = 
valueDelimMatcher.isMatch(varNameExprChars, i)) != 0) {
+                                        varName = varNameExpr.substring(0, i);
+                                        varDefaultValue = 
varNameExpr.substring(i + valueDelimiterMatchLen);
+                                        break;
                                     }
                                 }
+                            }
 
-                                // on the first call initialize priorVariables
-                                if (priorVariables == null) {
-                                    priorVariables = new ArrayList<>();
-                                    priorVariables.add(new String(chars,
-                                            offset, length));
-                                }
-
-                                // handle cyclic substitution
-                                checkCyclicSubstitution(varName, 
priorVariables);
-                                priorVariables.add(varName);
+                            // on the first call initialize priorVariables
+                            if (priorVariables == null) {
+                                priorVariables = new ArrayList<>();
+                                priorVariables.add(new String(chars,
+                                        offset, length));
+                            }
 
-                                // resolve the variable
-                                String varValue = resolveVariable(varName, buf,
-                                        startPos, endPos);
-                                if (varValue == null) {
-                                    varValue = varDefaultValue;
-                                }
-                                if (varValue != null) {
-                                    // recursive replace
-                                    final int varLen = varValue.length();
-                                    buf.replace(startPos, endPos, varValue);
-                                    altered = true;
-                                    int change = substitute(buf, startPos,
-                                            varLen, priorVariables);
-                                    change = change
-                                            + varLen - (endPos - startPos);
-                                    pos += change;
-                                    bufEnd += change;
-                                    lengthChange += change;
-                                    chars = buf.buffer; // in case buffer was
-                                                        // altered
-                                }
+                            // handle cyclic substitution
+                            checkCyclicSubstitution(varName, priorVariables);
+                            priorVariables.add(varName);
 
-                                // remove variable from the cyclic stack
-                                priorVariables
-                                        .remove(priorVariables.size() - 1);
-                                break;
+                            // resolve the variable
+                            String varValue = resolveVariable(varName, buf,
+                                    startPos, endPos);
+                            if (varValue == null) {
+                                varValue = varDefaultValue;
                             }
-                            nestedVarCount--;
-                            pos += endMatchLen;
+                            if (varValue != null) {
+                                // recursive replace
+                                final int varLen = varValue.length();
+                                buf.replace(startPos, endPos, varValue);
+                                altered = true;
+                                int change = substitute(buf, startPos,
+                                        varLen, priorVariables);
+                                change = change
+                                        + varLen - (endPos - startPos);
+                                pos += change;
+                                bufEnd += change;
+                                lengthChange += change;
+                                chars = buf.buffer; // in case buffer was
+                                                    // altered
+                            }
+
+                            // remove variable from the cyclic stack
+                            priorVariables
+                                    .remove(priorVariables.size() - 1);
+                            break;
                         }
+                        nestedVarCount--;
+                        pos += endMatchLen;
                     }
                 }
             }
diff --git a/src/main/java/org/apache/commons/lang3/text/WordUtils.java 
b/src/main/java/org/apache/commons/lang3/text/WordUtils.java
index 99ec998..5a43dc7 100644
--- a/src/main/java/org/apache/commons/lang3/text/WordUtils.java
+++ b/src/main/java/org/apache/commons/lang3/text/WordUtils.java
@@ -315,28 +315,26 @@ public class WordUtils {
                 wrappedLine.append(newLineStr);
                 offset = spaceToWrapAt + 1;
 
+            } else // really long word or URL
+            if (wrapLongWords) {
+                // wrap really long word one line at a time
+                wrappedLine.append(str, offset, wrapLength + offset);
+                wrappedLine.append(newLineStr);
+                offset += wrapLength;
             } else {
-                // really long word or URL
-                if (wrapLongWords) {
-                    // wrap really long word one line at a time
-                    wrappedLine.append(str, offset, wrapLength + offset);
+                // do not wrap really long word, just extend beyond limit
+                matcher = patternToWrapOn.matcher(str.substring(offset + 
wrapLength));
+                if (matcher.find()) {
+                    spaceToWrapAt = matcher.start() + offset + wrapLength;
+                }
+
+                if (spaceToWrapAt >= 0) {
+                    wrappedLine.append(str, offset, spaceToWrapAt);
                     wrappedLine.append(newLineStr);
-                    offset += wrapLength;
+                    offset = spaceToWrapAt + 1;
                 } else {
-                    // do not wrap really long word, just extend beyond limit
-                    matcher = patternToWrapOn.matcher(str.substring(offset + 
wrapLength));
-                    if (matcher.find()) {
-                        spaceToWrapAt = matcher.start() + offset + wrapLength;
-                    }
-
-                    if (spaceToWrapAt >= 0) {
-                        wrappedLine.append(str, offset, spaceToWrapAt);
-                        wrappedLine.append(newLineStr);
-                        offset = spaceToWrapAt + 1;
-                    } else {
-                        wrappedLine.append(str, offset, str.length());
-                        offset = inputLineLength;
-                    }
+                    wrappedLine.append(str, offset, str.length());
+                    offset = inputLineLength;
                 }
             }
         }
diff --git 
a/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityEscaper.java
 
b/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityEscaper.java
index 6f82af1..a57e79f 100644
--- 
a/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityEscaper.java
+++ 
b/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityEscaper.java
@@ -108,10 +108,8 @@ public class NumericEntityEscaper extends 
CodePointTranslator {
             if (codepoint < below || codepoint > above) {
                 return false;
             }
-        } else {
-            if (codepoint >= below && codepoint <= above) {
-                return false;
-            }
+        } else if (codepoint >= below && codepoint <= above) {
+            return false;
         }
 
         out.write("&#");
diff --git 
a/src/main/java/org/apache/commons/lang3/text/translate/UnicodeEscaper.java 
b/src/main/java/org/apache/commons/lang3/text/translate/UnicodeEscaper.java
index 709b30a..4b15826 100644
--- a/src/main/java/org/apache/commons/lang3/text/translate/UnicodeEscaper.java
+++ b/src/main/java/org/apache/commons/lang3/text/translate/UnicodeEscaper.java
@@ -108,10 +108,8 @@ public class UnicodeEscaper extends CodePointTranslator {
             if (codepoint < below || codepoint > above) {
                 return false;
             }
-        } else {
-            if (codepoint >= below && codepoint <= above) {
-                return false;
-            }
+        } else if (codepoint >= below && codepoint <= above) {
+            return false;
         }
 
         // TODO: Handle potential + sign per various Unicode escape 
implementations
diff --git 
a/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java 
b/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java
index 64b04a2..60a895e 100644
--- a/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java
+++ b/src/main/java/org/apache/commons/lang3/time/DurationFormatUtils.java
@@ -431,35 +431,33 @@ public class DurationFormatUtils {
             final int count = token.getCount();
             if (value instanceof StringBuilder) {
                 buffer.append(value.toString());
-            } else {
-                if (value.equals(y)) {
-                    buffer.append(paddedValue(years, padWithZeros, count));
-                    lastOutputSeconds = false;
-                } else if (value.equals(M)) {
-                    buffer.append(paddedValue(months, padWithZeros, count));
-                    lastOutputSeconds = false;
-                } else if (value.equals(d)) {
-                    buffer.append(paddedValue(days, padWithZeros, count));
-                    lastOutputSeconds = false;
-                } else if (value.equals(H)) {
-                    buffer.append(paddedValue(hours, padWithZeros, count));
-                    lastOutputSeconds = false;
-                } else if (value.equals(m)) {
-                    buffer.append(paddedValue(minutes, padWithZeros, count));
-                    lastOutputSeconds = false;
-                } else if (value.equals(s)) {
-                    buffer.append(paddedValue(seconds, padWithZeros, count));
-                    lastOutputSeconds = true;
-                } else if (value.equals(S)) {
-                    if (lastOutputSeconds) {
-                        // ensure at least 3 digits are displayed even if 
padding is not selected
-                        final int width = padWithZeros ? Math.max(3, count) : 
3;
-                        buffer.append(paddedValue(milliseconds, true, width));
-                    } else {
-                        buffer.append(paddedValue(milliseconds, padWithZeros, 
count));
-                    }
-                    lastOutputSeconds = false;
+            } else if (value.equals(y)) {
+                buffer.append(paddedValue(years, padWithZeros, count));
+                lastOutputSeconds = false;
+            } else if (value.equals(M)) {
+                buffer.append(paddedValue(months, padWithZeros, count));
+                lastOutputSeconds = false;
+            } else if (value.equals(d)) {
+                buffer.append(paddedValue(days, padWithZeros, count));
+                lastOutputSeconds = false;
+            } else if (value.equals(H)) {
+                buffer.append(paddedValue(hours, padWithZeros, count));
+                lastOutputSeconds = false;
+            } else if (value.equals(m)) {
+                buffer.append(paddedValue(minutes, padWithZeros, count));
+                lastOutputSeconds = false;
+            } else if (value.equals(s)) {
+                buffer.append(paddedValue(seconds, padWithZeros, count));
+                lastOutputSeconds = true;
+            } else if (value.equals(S)) {
+                if (lastOutputSeconds) {
+                    // ensure at least 3 digits are displayed even if padding 
is not selected
+                    final int width = padWithZeros ? Math.max(3, count) : 3;
+                    buffer.append(paddedValue(milliseconds, true, width));
+                } else {
+                    buffer.append(paddedValue(milliseconds, padWithZeros, 
count));
                 }
+                lastOutputSeconds = false;
             }
         }
         return buffer.toString();

Reply via email to