You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/02/11 18:17:44 UTC

[text] No need to nest else clause.

Repository: commons-text
Updated Branches:
  refs/heads/master 1de362f43 -> a99fbb826


No need to nest else clause.

Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/a99fbb82
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/a99fbb82
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/a99fbb82

Branch: refs/heads/master
Commit: a99fbb826653be20f3c1629989bdad413916f53e
Parents: 1de362f
Author: Gary Gregory <ga...@gmail.com>
Authored: Sun Feb 11 11:17:41 2018 -0700
Committer: Gary Gregory <ga...@gmail.com>
Committed: Sun Feb 11 11:17:41 2018 -0700

----------------------------------------------------------------------
 .../java/org/apache/commons/text/CaseUtils.java |   3 +-
 .../java/org/apache/commons/text/WordUtils.java |   3 +-
 .../text/translate/NumericEntityUnescaper.java  | 277 +++++++++----------
 3 files changed, 140 insertions(+), 143 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-text/blob/a99fbb82/src/main/java/org/apache/commons/text/CaseUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/CaseUtils.java b/src/main/java/org/apache/commons/text/CaseUtils.java
index 2f83861..0144db8 100644
--- a/src/main/java/org/apache/commons/text/CaseUtils.java
+++ b/src/main/java/org/apache/commons/text/CaseUtils.java
@@ -107,9 +107,8 @@ public class CaseUtils {
         }
         if (outOffset != 0) {
             return new String(newCodePoints, 0, outOffset);
-        } else {
-            return str;
         }
+        return str;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-text/blob/a99fbb82/src/main/java/org/apache/commons/text/WordUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/WordUtils.java b/src/main/java/org/apache/commons/text/WordUtils.java
index 1a6a407..21b504e 100644
--- a/src/main/java/org/apache/commons/text/WordUtils.java
+++ b/src/main/java/org/apache/commons/text/WordUtils.java
@@ -307,9 +307,8 @@ public class WordUtils {
                 if (matcher.start() == 0) {
                     offset += matcher.end();
                     continue;
-                } else {
-                    spaceToWrapAt = matcher.start() + offset;
                 }
+                spaceToWrapAt = matcher.start() + offset;
             }
 
             // only last line without leading spaces is left

http://git-wip-us.apache.org/repos/asf/commons-text/blob/a99fbb82/src/main/java/org/apache/commons/text/translate/NumericEntityUnescaper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/translate/NumericEntityUnescaper.java b/src/main/java/org/apache/commons/text/translate/NumericEntityUnescaper.java
index 4a89153..c06d7f2 100644
--- a/src/main/java/org/apache/commons/text/translate/NumericEntityUnescaper.java
+++ b/src/main/java/org/apache/commons/text/translate/NumericEntityUnescaper.java
@@ -1,139 +1,138 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.text.translate;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Arrays;
-import java.util.EnumSet;
-
-/**
- * Translate XML numeric entities of the form &amp;#[xX]?\d+;? to
- * the specific codepoint.
- *
- * Note that the semi-colon is optional.
- *
- * @since 1.0
- */
-public class NumericEntityUnescaper extends CharSequenceTranslator {
-
-    /** NumericEntityUnescaper option enum. */
-    public enum OPTION { semiColonRequired, semiColonOptional, errorIfNoSemiColon }
-
-    /** EnumSet of OPTIONS, given from the constructor. */
-    private final EnumSet<OPTION> options;
-
-    /**
-     * Create a UnicodeUnescaper.
-     *
-     * The constructor takes a list of options, only one type of which is currently
-     * available (whether to allow, error or ignore the semi-colon on the end of a
-     * numeric entity to being missing).
-     *
-     * For example, to support numeric entities without a ';':
-     *    new NumericEntityUnescaper(NumericEntityUnescaper.OPTION.semiColonOptional)
-     * and to throw an IllegalArgumentException when they're missing:
-     *    new NumericEntityUnescaper(NumericEntityUnescaper.OPTION.errorIfNoSemiColon)
-     *
-     * Note that the default behaviour is to ignore them.
-     *
-     * @param options to apply to this unescaper
-     */
-    public NumericEntityUnescaper(final OPTION... options) {
-        if (options.length > 0) {
-            this.options = EnumSet.copyOf(Arrays.asList(options));
-        } else {
-            this.options = EnumSet.copyOf(Arrays.asList(new OPTION[] {OPTION.semiColonRequired}));
-        }
-    }
-
-    /**
-     * Whether the passed in option is currently set.
-     *
-     * @param option to check state of
-     * @return whether the option is set
-     */
-    public boolean isSet(final OPTION option) {
-        return options != null && options.contains(option);
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public int translate(final CharSequence input, final int index, final Writer out) throws IOException {
-        final int seqEnd = input.length();
-        // Uses -2 to ensure there is something after the &#
-        if (input.charAt(index) == '&' && index < seqEnd - 2 && input.charAt(index + 1) == '#') {
-            int start = index + 2;
-            boolean isHex = false;
-
-            final char firstChar = input.charAt(start);
-            if (firstChar == 'x' || firstChar == 'X') {
-                start++;
-                isHex = true;
-
-                // Check there's more than just an x after the &#
-                if (start == seqEnd) {
-                    return 0;
-                }
-            }
-
-            int end = start;
-            // Note that this supports character codes without a ; on the end
-            while (end < seqEnd && (input.charAt(end) >= '0' && input.charAt(end) <= '9'
-                                    || input.charAt(end) >= 'a' && input.charAt(end) <= 'f'
-                                    || input.charAt(end) >= 'A' && input.charAt(end) <= 'F')) {
-                end++;
-            }
-
-            final boolean semiNext = end != seqEnd && input.charAt(end) == ';';
-
-            if (!semiNext) {
-                if (isSet(OPTION.semiColonRequired)) {
-                    return 0;
-                } else {
-                    if (isSet(OPTION.errorIfNoSemiColon)) {
-                        throw new IllegalArgumentException("Semi-colon required at end of numeric entity");
-                    }
-                }
-            }
-
-            int entityValue;
-            try {
-                if (isHex) {
-                    entityValue = Integer.parseInt(input.subSequence(start, end).toString(), 16);
-                } else {
-                    entityValue = Integer.parseInt(input.subSequence(start, end).toString(), 10);
-                }
-            } catch (final NumberFormatException nfe) {
-                return 0;
-            }
-
-            if (entityValue > 0xFFFF) {
-                final char[] chrs = Character.toChars(entityValue);
-                out.write(chrs[0]);
-                out.write(chrs[1]);
-            } else {
-                out.write(entityValue);
-            }
-
-            return 2 + end - start + (isHex ? 1 : 0) + (semiNext ? 1 : 0);
-        }
-        return 0;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.text.translate;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Arrays;
+import java.util.EnumSet;
+
+/**
+ * Translate XML numeric entities of the form &amp;#[xX]?\d+;? to
+ * the specific codepoint.
+ *
+ * Note that the semi-colon is optional.
+ *
+ * @since 1.0
+ */
+public class NumericEntityUnescaper extends CharSequenceTranslator {
+
+    /** NumericEntityUnescaper option enum. */
+    public enum OPTION { semiColonRequired, semiColonOptional, errorIfNoSemiColon }
+
+    /** EnumSet of OPTIONS, given from the constructor. */
+    private final EnumSet<OPTION> options;
+
+    /**
+     * Create a UnicodeUnescaper.
+     *
+     * The constructor takes a list of options, only one type of which is currently
+     * available (whether to allow, error or ignore the semi-colon on the end of a
+     * numeric entity to being missing).
+     *
+     * For example, to support numeric entities without a ';':
+     *    new NumericEntityUnescaper(NumericEntityUnescaper.OPTION.semiColonOptional)
+     * and to throw an IllegalArgumentException when they're missing:
+     *    new NumericEntityUnescaper(NumericEntityUnescaper.OPTION.errorIfNoSemiColon)
+     *
+     * Note that the default behaviour is to ignore them.
+     *
+     * @param options to apply to this unescaper
+     */
+    public NumericEntityUnescaper(final OPTION... options) {
+        if (options.length > 0) {
+            this.options = EnumSet.copyOf(Arrays.asList(options));
+        } else {
+            this.options = EnumSet.copyOf(Arrays.asList(new OPTION[] {OPTION.semiColonRequired}));
+        }
+    }
+
+    /**
+     * Whether the passed in option is currently set.
+     *
+     * @param option to check state of
+     * @return whether the option is set
+     */
+    public boolean isSet(final OPTION option) {
+        return options != null && options.contains(option);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public int translate(final CharSequence input, final int index, final Writer out) throws IOException {
+        final int seqEnd = input.length();
+        // Uses -2 to ensure there is something after the &#
+        if (input.charAt(index) == '&' && index < seqEnd - 2 && input.charAt(index + 1) == '#') {
+            int start = index + 2;
+            boolean isHex = false;
+
+            final char firstChar = input.charAt(start);
+            if (firstChar == 'x' || firstChar == 'X') {
+                start++;
+                isHex = true;
+
+                // Check there's more than just an x after the &#
+                if (start == seqEnd) {
+                    return 0;
+                }
+            }
+
+            int end = start;
+            // Note that this supports character codes without a ; on the end
+            while (end < seqEnd && (input.charAt(end) >= '0' && input.charAt(end) <= '9'
+                                    || input.charAt(end) >= 'a' && input.charAt(end) <= 'f'
+                                    || input.charAt(end) >= 'A' && input.charAt(end) <= 'F')) {
+                end++;
+            }
+
+            final boolean semiNext = end != seqEnd && input.charAt(end) == ';';
+
+            if (!semiNext) {
+                if (isSet(OPTION.semiColonRequired)) {
+                    return 0;
+                }
+                if (isSet(OPTION.errorIfNoSemiColon)) {
+                    throw new IllegalArgumentException("Semi-colon required at end of numeric entity");
+                }
+            }
+
+            int entityValue;
+            try {
+                if (isHex) {
+                    entityValue = Integer.parseInt(input.subSequence(start, end).toString(), 16);
+                } else {
+                    entityValue = Integer.parseInt(input.subSequence(start, end).toString(), 10);
+                }
+            } catch (final NumberFormatException nfe) {
+                return 0;
+            }
+
+            if (entityValue > 0xFFFF) {
+                final char[] chrs = Character.toChars(entityValue);
+                out.write(chrs[0]);
+                out.write(chrs[1]);
+            } else {
+                out.write(entityValue);
+            }
+
+            return 2 + end - start + (isHex ? 1 : 0) + (semiNext ? 1 : 0);
+        }
+        return 0;
+    }
+}