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 1dd511132f104e15d370c468f8afc267d9ae827e
Author: Gary Gregory <gardgreg...@gmail.com>
AuthorDate: Mon Jun 3 11:12:41 2019 -0400

    Sort members and clean up comments.
---
 .../org/apache/commons/lang3/CharSetUtils.java     | 203 ++++++++++-----------
 1 file changed, 97 insertions(+), 106 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/CharSetUtils.java 
b/src/main/java/org/apache/commons/lang3/CharSetUtils.java
index fbf3c58..b01534a 100644
--- a/src/main/java/org/apache/commons/lang3/CharSetUtils.java
+++ b/src/main/java/org/apache/commons/lang3/CharSetUtils.java
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.lang3;
 
+import java.nio.charset.Charset;
+
 /**
  * <p>Operations on {@code CharSet} instances.</p>
  *
@@ -30,72 +32,6 @@ package org.apache.commons.lang3;
 public class CharSetUtils {
 
     /**
-     * <p>CharSetUtils instances should NOT be constructed in standard 
programming.
-     * Instead, the class should be used as {@code 
CharSetUtils.evaluateSet(null);}.</p>
-     *
-     * <p>This constructor is public to permit tools that require a JavaBean 
instance
-     * to operate.</p>
-     */
-    public CharSetUtils() {
-      super();
-    }
-
-    // Squeeze
-    //-----------------------------------------------------------------------
-    /**
-     * <p>Squeezes any repetitions of a character that is mentioned in the
-     * supplied set.</p>
-     *
-     * <pre>
-     * CharSetUtils.squeeze(null, *)        = null
-     * CharSetUtils.squeeze("", *)          = ""
-     * CharSetUtils.squeeze(*, null)        = *
-     * CharSetUtils.squeeze(*, "")          = *
-     * CharSetUtils.squeeze("hello", "k-p") = "helo"
-     * CharSetUtils.squeeze("hello", "a-e") = "hello"
-     * </pre>
-     *
-     * @see CharSet#getInstance(java.lang.String...) for set-syntax.
-     * @param str  the string to squeeze, may be null
-     * @param set  the character set to use for manipulation, may be null
-     * @return the modified String, {@code null} if null string input
-     */
-    public static String squeeze(final String str, final String... set) {
-        if (StringUtils.isEmpty(str) || deepEmpty(set)) {
-            return str;
-        }
-        final CharSet chars = CharSet.getInstance(set);
-        final StringBuilder buffer = new StringBuilder(str.length());
-        final char[] chrs = str.toCharArray();
-        final int sz = chrs.length;
-        char lastChar = chrs[0];
-        char ch = ' ';
-        Character inChars = null;
-        Character notInChars = null;
-        buffer.append(lastChar);
-        for (int i = 1; i < sz; i++) {
-            ch = chrs[i];
-            if (ch == lastChar) {
-                if (inChars != null && ch == inChars) {
-                    continue;
-                }
-                if (notInChars == null || ch != notInChars) {
-                    if (chars.contains(ch)) {
-                        inChars = ch;
-                        continue;
-                    }
-                    notInChars = ch;
-                }
-            }
-            buffer.append(ch);
-            lastChar = ch;
-        }
-        return buffer.toString();
-    }
-
-    // ContainsAny
-    //-----------------------------------------------------------------------
-    /**
      * <p>Takes an argument in set-syntax, see evaluateSet,
      * and identifies whether any of the characters are present in the 
specified string.</p>
      *
@@ -127,8 +63,6 @@ public class CharSetUtils {
         return false;
     }
 
-    // Count
-    //-----------------------------------------------------------------------
     /**
      * <p>Takes an argument in set-syntax, see evaluateSet,
      * and returns the number of characters present in the specified 
string.</p>
@@ -161,39 +95,24 @@ public class CharSetUtils {
         return count;
     }
 
-    // Keep
-    //-----------------------------------------------------------------------
     /**
-     * <p>Takes an argument in set-syntax, see evaluateSet,
-     * and keeps any of characters present in the specified string.</p>
-     *
-     * <pre>
-     * CharSetUtils.keep(null, *)        = null
-     * CharSetUtils.keep("", *)          = ""
-     * CharSetUtils.keep(*, null)        = ""
-     * CharSetUtils.keep(*, "")          = ""
-     * CharSetUtils.keep("hello", "hl")  = "hll"
-     * CharSetUtils.keep("hello", "le")  = "ell"
-     * </pre>
+     * Determines whether or not all the Strings in an array are
+     * empty or not.
      *
-     * @see CharSet#getInstance(java.lang.String...) for set-syntax.
-     * @param str  String to keep characters from, may be null
-     * @param set  String[] set of characters to keep, may be null
-     * @return the modified String, {@code null} if null string input
-     * @since 2.0
+     * @param strings String[] whose elements are being checked for emptiness
+     * @return whether or not the String is empty
      */
-    public static String keep(final String str, final String... set) {
-        if (str == null) {
-            return null;
-        }
-        if (str.isEmpty() || deepEmpty(set)) {
-            return StringUtils.EMPTY;
+    private static boolean deepEmpty(final String[] strings) {
+        if (strings != null) {
+            for (final String s : strings) {
+                if (StringUtils.isNotEmpty(s)) {
+                    return false;
+                }
+            }
         }
-        return modify(str, set, true);
+        return true;
     }
 
-    // Delete
-    //-----------------------------------------------------------------------
     /**
      * <p>Takes an argument in set-syntax, see evaluateSet,
      * and deletes any of characters present in the specified string.</p>
@@ -219,7 +138,35 @@ public class CharSetUtils {
         return modify(str, set, false);
     }
 
-    //-----------------------------------------------------------------------
+    /**
+     * <p>Takes an argument in set-syntax, see evaluateSet,
+     * and keeps any of characters present in the specified string.</p>
+     *
+     * <pre>
+     * CharSetUtils.keep(null, *)        = null
+     * CharSetUtils.keep("", *)          = ""
+     * CharSetUtils.keep(*, null)        = ""
+     * CharSetUtils.keep(*, "")          = ""
+     * CharSetUtils.keep("hello", "hl")  = "hll"
+     * CharSetUtils.keep("hello", "le")  = "ell"
+     * </pre>
+     *
+     * @see CharSet#getInstance(java.lang.String...) for set-syntax.
+     * @param str  String to keep characters from, may be null
+     * @param set  String[] set of characters to keep, may be null
+     * @return the modified String, {@code null} if null string input
+     * @since 2.0
+     */
+    public static String keep(final String str, final String... set) {
+        if (str == null) {
+            return null;
+        }
+        if (str.isEmpty() || deepEmpty(set)) {
+            return StringUtils.EMPTY;
+        }
+        return modify(str, set, true);
+    }
+
     /**
      * Implementation of delete and keep
      *
@@ -241,20 +188,64 @@ public class CharSetUtils {
     }
 
     /**
-     * Determines whether or not all the Strings in an array are
-     * empty or not.
+     * <p>Squeezes any repetitions of a character that is mentioned in the
+     * supplied set.</p>
      *
-     * @param strings String[] whose elements are being checked for emptiness
-     * @return whether or not the String is empty
+     * <pre>
+     * CharSetUtils.squeeze(null, *)        = null
+     * CharSetUtils.squeeze("", *)          = ""
+     * CharSetUtils.squeeze(*, null)        = *
+     * CharSetUtils.squeeze(*, "")          = *
+     * CharSetUtils.squeeze("hello", "k-p") = "helo"
+     * CharSetUtils.squeeze("hello", "a-e") = "hello"
+     * </pre>
+     *
+     * @see CharSet#getInstance(java.lang.String...) for set-syntax.
+     * @param str  the string to squeeze, may be null
+     * @param set  the character set to use for manipulation, may be null
+     * @return the modified String, {@code null} if null string input
      */
-    private static boolean deepEmpty(final String[] strings) {
-        if (strings != null) {
-            for (final String s : strings) {
-                if (StringUtils.isNotEmpty(s)) {
-                    return false;
+    public static String squeeze(final String str, final String... set) {
+        if (StringUtils.isEmpty(str) || deepEmpty(set)) {
+            return str;
+        }
+        final CharSet chars = CharSet.getInstance(set);
+        final StringBuilder buffer = new StringBuilder(str.length());
+        final char[] chrs = str.toCharArray();
+        final int sz = chrs.length;
+        char lastChar = chrs[0];
+        char ch = ' ';
+        Character inChars = null;
+        Character notInChars = null;
+        buffer.append(lastChar);
+        for (int i = 1; i < sz; i++) {
+            ch = chrs[i];
+            if (ch == lastChar) {
+                if (inChars != null && ch == inChars) {
+                    continue;
+                }
+                if (notInChars == null || ch != notInChars) {
+                    if (chars.contains(ch)) {
+                        inChars = ch;
+                        continue;
+                    }
+                    notInChars = ch;
                 }
             }
+            buffer.append(ch);
+            lastChar = ch;
         }
-        return true;
+        return buffer.toString();
+    }
+
+    /**
+     * <p>CharSetUtils instances should NOT be constructed in standard 
programming.
+     * Instead, the class should be used as {@code 
CharSetUtils.evaluateSet(null);}.</p>
+     *
+     * <p>This constructor is public to permit tools that require a JavaBean 
instance
+     * to operate.</p>
+     */
+    public CharSetUtils() {
+      super();
     }
 }

Reply via email to