You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ba...@apache.org on 2016/02/26 06:18:51 UTC

[1/5] [lang] StrSubstitutor can preserve escapes

Repository: commons-lang
Updated Branches:
  refs/heads/master 242e1f549 -> 59c28bb25


StrSubstitutor can preserve escapes

StrSubstitutor can now optionally preserve the escape character for an
escaped reference, which is useful when substitution takes place in
multiple phases and some references are intentionally unresolved.  Prior
to this change, an unresolved reference `${a}` and an escaped reference
`$${a}` may result in the same string `${a}`, making it impossible for
an additional substitution phase to distinguish between escaped
references and non-escaped references.


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

Branch: refs/heads/master
Commit: e55aaa5706f031df2e8d68bdf088604c79944246
Parents: a72a5ce
Author: Samuel Karp <sk...@amazon.com>
Authored: Wed Feb 3 15:45:21 2016 -0800
Committer: Samuel Karp <sk...@amazon.com>
Committed: Thu Feb 25 17:02:56 2016 -0800

----------------------------------------------------------------------
 .../commons/lang3/text/StrSubstitutor.java      | 33 ++++++++++++++++++++
 .../commons/lang3/text/StrSubstitutorTest.java  | 15 +++++++++
 2 files changed, 48 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e55aaa57/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java
----------------------------------------------------------------------
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 766e161..6f8da7f 100644
--- a/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java
+++ b/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java
@@ -165,6 +165,10 @@ public class StrSubstitutor {
      * The flag whether substitution in variable names is enabled.
      */
     private boolean enableSubstitutionInVariables;
+    /**
+     * Whether escapes should be preserved.  Default is false;
+     */
+    private boolean preserveEscapes = false;
 
     //-----------------------------------------------------------------------
     /**
@@ -768,6 +772,10 @@ public class StrSubstitutor {
                 // 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--;
@@ -1192,4 +1200,29 @@ public class StrSubstitutor {
             final boolean enableSubstitutionInVariables) {
         this.enableSubstitutionInVariables = enableSubstitutionInVariables;
     }
+
+    /**
+     * Returns the flag controlling whether escapes are preserved during
+     * substitution.
+     * 
+     * @return the preserve escape flag
+     */
+    public boolean isPreserveEscapes() {
+        return preserveEscapes;
+    }
+
+    /**
+     * Sets a flag controlling whether escapes are preserved during
+     * substitution.  If set to <b>true</b>, the escape character is retained
+     * during substitution (e.g. <code>$${this-is-escaped}</code> remains
+     * <code>$${this-is-escaped}</code>).  If set to <b>false</b>, the escape
+     * character is removed during substitution (e.g.
+     * <code>$${this-is-escaped}</code> becomes
+     * <code>${this-is-escaped}</code>).  The default value is <b>false</b>
+     * 
+     * @param preserveEscapes
+     */
+    public void setPreserveEscapes(final boolean preserveEscapes) {
+        this.preserveEscapes = preserveEscapes;
+    }
 }

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/e55aaa57/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java b/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java
index 9c96150..2f8759f 100644
--- a/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java
+++ b/src/test/java/org/apache/commons/lang3/text/StrSubstitutorTest.java
@@ -623,6 +623,21 @@ public class StrSubstitutorTest {
         assertEquals("Hello there commons!", StrSubstitutor.replace("@greeting@ there @name@!", map, "@", "@"));
     }
 
+    @Test
+    public void testSubstitutePreserveEscape() {
+        final String org = "${not-escaped} $${escaped}";
+        final Map<String, String> map = new HashMap<String, String>();
+        map.put("not-escaped", "value");
+
+        StrSubstitutor sub = new StrSubstitutor(map, "${", "}", '$');
+        assertFalse(sub.isPreserveEscapes());
+        assertEquals("value ${escaped}", sub.replace(org));
+
+        sub.setPreserveEscapes(true);
+        assertTrue(sub.isPreserveEscapes());
+        assertEquals("value $${escaped}", sub.replace(org));
+    }
+
     //-----------------------------------------------------------------------
     private void doTestReplace(final String expectedResult, final String replaceTemplate, final boolean substring) {
         final String expectedShortResult = expectedResult.substring(1, expectedResult.length() - 1);


[4/5] [lang] Adding changes for LANG-1208

Posted by ba...@apache.org.
Adding changes for LANG-1208


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

Branch: refs/heads/master
Commit: 8e17410e8e468f0fe90c21123f29d2ef5137a695
Parents: 56e52fe
Author: Hen <he...@flamefew.com>
Authored: Thu Feb 25 21:16:38 2016 -0800
Committer: Hen <he...@flamefew.com>
Committed: Thu Feb 25 21:16:38 2016 -0800

----------------------------------------------------------------------
 src/changes/changes.xml | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/8e17410e/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 2b2d53c..c1d017e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -22,6 +22,7 @@
   <body>
 
   <release version="3.5" date="tba" description="tba">
+    <action issue="LANG-1208" type="update" dev="bayard" due-to="Samuel Karp">StrSubstitutor can preserve escapes</action>
     <action issue="LANG-1192" type="add" dev="chas" due-to="Dominik Stadler">FastDateFormat support of the week-year component (uppercase 'Y')</action>
     <action issue="LANG-1194" type="fix" dev="chas">Limit max heap memory for consistent Travis CI build</action>
     <action issue="LANG-1186" type="fix" dev="chas" due-to="NickManley">Fix NullPointerException in FastDateParser$TimeZoneStrategy</action>


[5/5] [lang] Merge branch '124-branch'

Posted by ba...@apache.org.
Merge branch '124-branch'

Conflicts:
	src/changes/changes.xml

LANG-1208: StrSubstitutor can preserve escapes
This closes #124 from github. Thanks to Samuel Karp.


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

Branch: refs/heads/master
Commit: 59c28bb25fff0fc667d1319b13a3358bd44e81d5
Parents: 242e1f5 8e17410
Author: Hen <he...@flamefew.com>
Authored: Thu Feb 25 21:17:53 2016 -0800
Committer: Hen <he...@flamefew.com>
Committed: Thu Feb 25 21:17:53 2016 -0800

----------------------------------------------------------------------
 src/changes/changes.xml                         |  1 +
 .../commons/lang3/text/StrSubstitutor.java      | 33 ++++++++++++++++++++
 .../commons/lang3/text/StrSubstitutorTest.java  | 15 +++++++++
 3 files changed, 49 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/59c28bb2/src/changes/changes.xml
----------------------------------------------------------------------
diff --cc src/changes/changes.xml
index c981921,c1d017e..29d704d
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@@ -22,7 -22,7 +22,8 @@@
    <body>
  
    <release version="3.5" date="tba" description="tba">
+     <action issue="LANG-1208" type="update" dev="bayard" due-to="Samuel Karp">StrSubstitutor can preserve escapes</action>
 +    <action issue="LANG-1175" type="fix" dev="wikier" due-to="Benedikt Ritter">Remove Ant-based build</action>
      <action issue="LANG-1192" type="add" dev="chas" due-to="Dominik Stadler">FastDateFormat support of the week-year component (uppercase 'Y')</action>
      <action issue="LANG-1194" type="fix" dev="chas">Limit max heap memory for consistent Travis CI build</action>
      <action issue="LANG-1186" type="fix" dev="chas" due-to="NickManley">Fix NullPointerException in FastDateParser$TimeZoneStrategy</action>


[2/5] [lang] newline pain, despite having run the config line

Posted by ba...@apache.org.
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/56e52fe4/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
index 01f276b..b53ba98 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -1,1580 +1,1580 @@
-/*
- * 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.lang3.math;
-
-import java.lang.reflect.Array;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.Validate;
-
-/**
- * <p>Provides extra functionality for Java Number classes.</p>
- *
- * @since 2.0
- */
-public class NumberUtils {
-    
-    /** Reusable Long constant for zero. */
-    public static final Long LONG_ZERO = Long.valueOf(0L);
-    /** Reusable Long constant for one. */
-    public static final Long LONG_ONE = Long.valueOf(1L);
-    /** Reusable Long constant for minus one. */
-    public static final Long LONG_MINUS_ONE = Long.valueOf(-1L);
-    /** Reusable Integer constant for zero. */
-    public static final Integer INTEGER_ZERO = Integer.valueOf(0);
-    /** Reusable Integer constant for one. */
-    public static final Integer INTEGER_ONE = Integer.valueOf(1);
-    /** Reusable Integer constant for minus one. */
-    public static final Integer INTEGER_MINUS_ONE = Integer.valueOf(-1);
-    /** Reusable Short constant for zero. */
-    public static final Short SHORT_ZERO = Short.valueOf((short) 0);
-    /** Reusable Short constant for one. */
-    public static final Short SHORT_ONE = Short.valueOf((short) 1);
-    /** Reusable Short constant for minus one. */
-    public static final Short SHORT_MINUS_ONE = Short.valueOf((short) -1);
-    /** Reusable Byte constant for zero. */
-    public static final Byte BYTE_ZERO = Byte.valueOf((byte) 0);
-    /** Reusable Byte constant for one. */
-    public static final Byte BYTE_ONE = Byte.valueOf((byte) 1);
-    /** Reusable Byte constant for minus one. */
-    public static final Byte BYTE_MINUS_ONE = Byte.valueOf((byte) -1);
-    /** Reusable Double constant for zero. */
-    public static final Double DOUBLE_ZERO = Double.valueOf(0.0d);
-    /** Reusable Double constant for one. */
-    public static final Double DOUBLE_ONE = Double.valueOf(1.0d);
-    /** Reusable Double constant for minus one. */
-    public static final Double DOUBLE_MINUS_ONE = Double.valueOf(-1.0d);
-    /** Reusable Float constant for zero. */
-    public static final Float FLOAT_ZERO = Float.valueOf(0.0f);
-    /** Reusable Float constant for one. */
-    public static final Float FLOAT_ONE = Float.valueOf(1.0f);
-    /** Reusable Float constant for minus one. */
-    public static final Float FLOAT_MINUS_ONE = Float.valueOf(-1.0f);
-
-    /**
-     * <p><code>NumberUtils</code> instances should NOT be constructed in standard programming.
-     * Instead, the class should be used as <code>NumberUtils.toInt("6");</code>.</p>
-     *
-     * <p>This constructor is public to permit tools that require a JavaBean instance
-     * to operate.</p>
-     */
-    public NumberUtils() {
-        super();
-    }
-
-    //-----------------------------------------------------------------------
-    /**
-     * <p>Convert a <code>String</code> to an <code>int</code>, returning
-     * <code>zero</code> if the conversion fails.</p>
-     *
-     * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
-     *
-     * <pre>
-     *   NumberUtils.toInt(null) = 0
-     *   NumberUtils.toInt("")   = 0
-     *   NumberUtils.toInt("1")  = 1
-     * </pre>
-     *
-     * @param str  the string to convert, may be null
-     * @return the int represented by the string, or <code>zero</code> if
-     *  conversion fails
-     * @since 2.1
-     */
-    public static int toInt(final String str) {
-        return toInt(str, 0);
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to an <code>int</code>, returning a
-     * default value if the conversion fails.</p>
-     *
-     * <p>If the string is <code>null</code>, the default value is returned.</p>
-     *
-     * <pre>
-     *   NumberUtils.toInt(null, 1) = 1
-     *   NumberUtils.toInt("", 1)   = 1
-     *   NumberUtils.toInt("1", 0)  = 1
-     * </pre>
-     *
-     * @param str  the string to convert, may be null
-     * @param defaultValue  the default value
-     * @return the int represented by the string, or the default if conversion fails
-     * @since 2.1
-     */
-    public static int toInt(final String str, final int defaultValue) {
-        if(str == null) {
-            return defaultValue;
-        }
-        try {
-            return Integer.parseInt(str);
-        } catch (final NumberFormatException nfe) {
-            return defaultValue;
-        }
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to a <code>long</code>, returning
-     * <code>zero</code> if the conversion fails.</p>
-     *
-     * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
-     *
-     * <pre>
-     *   NumberUtils.toLong(null) = 0L
-     *   NumberUtils.toLong("")   = 0L
-     *   NumberUtils.toLong("1")  = 1L
-     * </pre>
-     *
-     * @param str  the string to convert, may be null
-     * @return the long represented by the string, or <code>0</code> if
-     *  conversion fails
-     * @since 2.1
-     */
-    public static long toLong(final String str) {
-        return toLong(str, 0L);
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to a <code>long</code>, returning a
-     * default value if the conversion fails.</p>
-     *
-     * <p>If the string is <code>null</code>, the default value is returned.</p>
-     *
-     * <pre>
-     *   NumberUtils.toLong(null, 1L) = 1L
-     *   NumberUtils.toLong("", 1L)   = 1L
-     *   NumberUtils.toLong("1", 0L)  = 1L
-     * </pre>
-     *
-     * @param str  the string to convert, may be null
-     * @param defaultValue  the default value
-     * @return the long represented by the string, or the default if conversion fails
-     * @since 2.1
-     */
-    public static long toLong(final String str, final long defaultValue) {
-        if (str == null) {
-            return defaultValue;
-        }
-        try {
-            return Long.parseLong(str);
-        } catch (final NumberFormatException nfe) {
-            return defaultValue;
-        }
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to a <code>float</code>, returning
-     * <code>0.0f</code> if the conversion fails.</p>
-     *
-     * <p>If the string <code>str</code> is <code>null</code>,
-     * <code>0.0f</code> is returned.</p>
-     *
-     * <pre>
-     *   NumberUtils.toFloat(null)   = 0.0f
-     *   NumberUtils.toFloat("")     = 0.0f
-     *   NumberUtils.toFloat("1.5")  = 1.5f
-     * </pre>
-     *
-     * @param str the string to convert, may be <code>null</code>
-     * @return the float represented by the string, or <code>0.0f</code>
-     *  if conversion fails
-     * @since 2.1
-     */
-    public static float toFloat(final String str) {
-        return toFloat(str, 0.0f);
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to a <code>float</code>, returning a
-     * default value if the conversion fails.</p>
-     *
-     * <p>If the string <code>str</code> is <code>null</code>, the default
-     * value is returned.</p>
-     *
-     * <pre>
-     *   NumberUtils.toFloat(null, 1.1f)   = 1.0f
-     *   NumberUtils.toFloat("", 1.1f)     = 1.1f
-     *   NumberUtils.toFloat("1.5", 0.0f)  = 1.5f
-     * </pre>
-     *
-     * @param str the string to convert, may be <code>null</code>
-     * @param defaultValue the default value
-     * @return the float represented by the string, or defaultValue
-     *  if conversion fails
-     * @since 2.1
-     */
-    public static float toFloat(final String str, final float defaultValue) {
-      if (str == null) {
-          return defaultValue;
-      }     
-      try {
-          return Float.parseFloat(str);
-      } catch (final NumberFormatException nfe) {
-          return defaultValue;
-      }
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to a <code>double</code>, returning
-     * <code>0.0d</code> if the conversion fails.</p>
-     *
-     * <p>If the string <code>str</code> is <code>null</code>,
-     * <code>0.0d</code> is returned.</p>
-     *
-     * <pre>
-     *   NumberUtils.toDouble(null)   = 0.0d
-     *   NumberUtils.toDouble("")     = 0.0d
-     *   NumberUtils.toDouble("1.5")  = 1.5d
-     * </pre>
-     *
-     * @param str the string to convert, may be <code>null</code>
-     * @return the double represented by the string, or <code>0.0d</code>
-     *  if conversion fails
-     * @since 2.1
-     */
-    public static double toDouble(final String str) {
-        return toDouble(str, 0.0d);
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to a <code>double</code>, returning a
-     * default value if the conversion fails.</p>
-     *
-     * <p>If the string <code>str</code> is <code>null</code>, the default
-     * value is returned.</p>
-     *
-     * <pre>
-     *   NumberUtils.toDouble(null, 1.1d)   = 1.1d
-     *   NumberUtils.toDouble("", 1.1d)     = 1.1d
-     *   NumberUtils.toDouble("1.5", 0.0d)  = 1.5d
-     * </pre>
-     *
-     * @param str the string to convert, may be <code>null</code>
-     * @param defaultValue the default value
-     * @return the double represented by the string, or defaultValue
-     *  if conversion fails
-     * @since 2.1
-     */
-    public static double toDouble(final String str, final double defaultValue) {
-      if (str == null) {
-          return defaultValue;
-      }
-      try {
-          return Double.parseDouble(str);
-      } catch (final NumberFormatException nfe) {
-          return defaultValue;
-      }
-    }
-
-     //-----------------------------------------------------------------------
-     /**
-     * <p>Convert a <code>String</code> to a <code>byte</code>, returning
-     * <code>zero</code> if the conversion fails.</p>
-     *
-     * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
-     *
-     * <pre>
-     *   NumberUtils.toByte(null) = 0
-     *   NumberUtils.toByte("")   = 0
-     *   NumberUtils.toByte("1")  = 1
-     * </pre>
-     *
-     * @param str  the string to convert, may be null
-     * @return the byte represented by the string, or <code>zero</code> if
-     *  conversion fails
-     * @since 2.5
-     */
-    public static byte toByte(final String str) {
-        return toByte(str, (byte) 0);
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to a <code>byte</code>, returning a
-     * default value if the conversion fails.</p>
-     *
-     * <p>If the string is <code>null</code>, the default value is returned.</p>
-     *
-     * <pre>
-     *   NumberUtils.toByte(null, 1) = 1
-     *   NumberUtils.toByte("", 1)   = 1
-     *   NumberUtils.toByte("1", 0)  = 1
-     * </pre>
-     *
-     * @param str  the string to convert, may be null
-     * @param defaultValue  the default value
-     * @return the byte represented by the string, or the default if conversion fails
-     * @since 2.5
-     */
-    public static byte toByte(final String str, final byte defaultValue) {
-        if(str == null) {
-            return defaultValue;
-        }
-        try {
-            return Byte.parseByte(str);
-        } catch (final NumberFormatException nfe) {
-            return defaultValue;
-        }
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to a <code>short</code>, returning
-     * <code>zero</code> if the conversion fails.</p>
-     *
-     * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
-     *
-     * <pre>
-     *   NumberUtils.toShort(null) = 0
-     *   NumberUtils.toShort("")   = 0
-     *   NumberUtils.toShort("1")  = 1
-     * </pre>
-     *
-     * @param str  the string to convert, may be null
-     * @return the short represented by the string, or <code>zero</code> if
-     *  conversion fails
-     * @since 2.5
-     */
-    public static short toShort(final String str) {
-        return toShort(str, (short) 0);
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to an <code>short</code>, returning a
-     * default value if the conversion fails.</p>
-     *
-     * <p>If the string is <code>null</code>, the default value is returned.</p>
-     *
-     * <pre>
-     *   NumberUtils.toShort(null, 1) = 1
-     *   NumberUtils.toShort("", 1)   = 1
-     *   NumberUtils.toShort("1", 0)  = 1
-     * </pre>
-     *
-     * @param str  the string to convert, may be null
-     * @param defaultValue  the default value
-     * @return the short represented by the string, or the default if conversion fails
-     * @since 2.5
-     */
-    public static short toShort(final String str, final short defaultValue) {
-        if(str == null) {
-            return defaultValue;
-        }
-        try {
-            return Short.parseShort(str);
-        } catch (final NumberFormatException nfe) {
-            return defaultValue;
-        }
-    }
-
-    //-----------------------------------------------------------------------
-    // must handle Long, Float, Integer, Float, Short,
-    //                  BigDecimal, BigInteger and Byte
-    // useful methods:
-    // Byte.decode(String)
-    // Byte.valueOf(String,int radix)
-    // Byte.valueOf(String)
-    // Double.valueOf(String)
-    // Float.valueOf(String)
-    // Float.valueOf(String)
-    // Integer.valueOf(String,int radix)
-    // Integer.valueOf(String)
-    // Integer.decode(String)
-    // Integer.getInteger(String)
-    // Integer.getInteger(String,int val)
-    // Integer.getInteger(String,Integer val)
-    // Integer.valueOf(String)
-    // Double.valueOf(String)
-    // new Byte(String)
-    // Long.valueOf(String)
-    // Long.getLong(String)
-    // Long.getLong(String,int)
-    // Long.getLong(String,Integer)
-    // Long.valueOf(String,int)
-    // Long.valueOf(String)
-    // Short.valueOf(String)
-    // Short.decode(String)
-    // Short.valueOf(String,int)
-    // Short.valueOf(String)
-    // new BigDecimal(String)
-    // new BigInteger(String)
-    // new BigInteger(String,int radix)
-    // Possible inputs:
-    // 45 45.5 45E7 4.5E7 Hex Oct Binary xxxF xxxD xxxf xxxd
-    // plus minus everything. Prolly more. A lot are not separable.
-
-    /**
-     * <p>Turns a string value into a java.lang.Number.</p>
-     *
-     * <p>If the string starts with {@code 0x} or {@code -0x} (lower or upper case) or {@code #} or {@code -#}, it
-     * will be interpreted as a hexadecimal Integer - or Long, if the number of digits after the
-     * prefix is more than 8 - or BigInteger if there are more than 16 digits.
-     * </p>
-     * <p>Then, the value is examined for a type qualifier on the end, i.e. one of
-     * <code>'f','F','d','D','l','L'</code>.  If it is found, it starts 
-     * trying to create successively larger types from the type specified
-     * until one is found that can represent the value.</p>
-     *
-     * <p>If a type specifier is not found, it will check for a decimal point
-     * and then try successively larger types from <code>Integer</code> to
-     * <code>BigInteger</code> and from <code>Float</code> to
-    * <code>BigDecimal</code>.</p>
-    * 
-     * <p>
-     * Integral values with a leading {@code 0} will be interpreted as octal; the returned number will
-     * be Integer, Long or BigDecimal as appropriate.
-     * </p>
-     *
-     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
-     *
-     * <p>This method does not trim the input string, i.e., strings with leading
-     * or trailing spaces will generate NumberFormatExceptions.</p>
-     *
-     * @param str  String containing a number, may be null
-     * @return Number created from the string (or null if the input is null)
-     * @throws NumberFormatException if the value cannot be converted
-     */
-    public static Number createNumber(final String str) throws NumberFormatException {
-        if (str == null) {
-            return null;
-        }
-        if (StringUtils.isBlank(str)) {
-            throw new NumberFormatException("A blank string is not a valid number");
-        }
-        // Need to deal with all possible hex prefixes here
-        final String[] hex_prefixes = {"0x", "0X", "-0x", "-0X", "#", "-#"};
-        int pfxLen = 0;
-        for(final String pfx : hex_prefixes) {
-            if (str.startsWith(pfx)) {
-                pfxLen += pfx.length();
-                break;
-            }
-        }
-        if (pfxLen > 0) { // we have a hex number
-            char firstSigDigit = 0; // strip leading zeroes
-            for(int i = pfxLen; i < str.length(); i++) {
-                firstSigDigit = str.charAt(i);
-                if (firstSigDigit == '0') { // count leading zeroes
-                    pfxLen++;
-                } else {
-                    break;
-                }
-            }
-            final int hexDigits = str.length() - pfxLen;
-            if (hexDigits > 16 || (hexDigits == 16 && firstSigDigit > '7')) { // too many for Long
-                return createBigInteger(str);
-            }
-            if (hexDigits > 8 || (hexDigits == 8 && firstSigDigit > '7')) { // too many for an int
-                return createLong(str);
-            }
-            return createInteger(str);
-        }
-        final char lastChar = str.charAt(str.length() - 1);
-        String mant;
-        String dec;
-        String exp;
-        final int decPos = str.indexOf('.');
-        final int expPos = str.indexOf('e') + str.indexOf('E') + 1; // assumes both not present
-        // if both e and E are present, this is caught by the checks on expPos (which prevent IOOBE)
-        // and the parsing which will detect if e or E appear in a number due to using the wrong offset
-
-        int numDecimals = 0; // Check required precision (LANG-693)
-        if (decPos > -1) { // there is a decimal point
-
-            if (expPos > -1) { // there is an exponent
-                if (expPos < decPos || expPos > str.length()) { // prevents double exponent causing IOOBE
-                    throw new NumberFormatException(str + " is not a valid number.");
-                }
-                dec = str.substring(decPos + 1, expPos);
-            } else {
-                dec = str.substring(decPos + 1);
-            }
-            mant = getMantissa(str, decPos);
-            numDecimals = dec.length(); // gets number of digits past the decimal to ensure no loss of precision for floating point numbers.
-        } else {
-            if (expPos > -1) {
-                if (expPos > str.length()) { // prevents double exponent causing IOOBE
-                    throw new NumberFormatException(str + " is not a valid number.");
-                }
-                mant = getMantissa(str, expPos);
-            } else {
-                mant = getMantissa(str);
-            }
-            dec = null;
-        }
-        if (!Character.isDigit(lastChar) && lastChar != '.') {
-            if (expPos > -1 && expPos < str.length() - 1) {
-                exp = str.substring(expPos + 1, str.length() - 1);
-            } else {
-                exp = null;
-            }
-            //Requesting a specific type..
-            final String numeric = str.substring(0, str.length() - 1);
-            final boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
-            switch (lastChar) {
-                case 'l' :
-                case 'L' :
-                    if (dec == null
-                        && exp == null
-                        && (numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) {
-                        try {
-                            return createLong(numeric);
-                        } catch (final NumberFormatException nfe) { // NOPMD
-                            // Too big for a long
-                        }
-                        return createBigInteger(numeric);
-
-                    }
-                    throw new NumberFormatException(str + " is not a valid number.");
-                case 'f' :
-                case 'F' :
-                    try {
-                        final Float f = NumberUtils.createFloat(numeric);
-                        if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
-                            //If it's too big for a float or the float value = 0 and the string
-                            //has non-zeros in it, then float does not have the precision we want
-                            return f;
-                        }
-
-                    } catch (final NumberFormatException nfe) { // NOPMD
-                        // ignore the bad number
-                    }
-                    //$FALL-THROUGH$
-                case 'd' :
-                case 'D' :
-                    try {
-                        final Double d = NumberUtils.createDouble(numeric);
-                        if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) {
-                            return d;
-                        }
-                    } catch (final NumberFormatException nfe) { // NOPMD
-                        // ignore the bad number
-                    }
-                    try {
-                        return createBigDecimal(numeric);
-                    } catch (final NumberFormatException e) { // NOPMD
-                        // ignore the bad number
-                    }
-                    //$FALL-THROUGH$
-                default :
-                    throw new NumberFormatException(str + " is not a valid number.");
-
-            }
-        }
-        //User doesn't have a preference on the return type, so let's start
-        //small and go from there...
-        if (expPos > -1 && expPos < str.length() - 1) {
-            exp = str.substring(expPos + 1, str.length());
-        } else {
-            exp = null;
-        }
-        if (dec == null && exp == null) { // no decimal point and no exponent
-            //Must be an Integer, Long, Biginteger
-            try {
-                return createInteger(str);
-            } catch (final NumberFormatException nfe) { // NOPMD
-                // ignore the bad number
-            }
-            try {
-                return createLong(str);
-            } catch (final NumberFormatException nfe) { // NOPMD
-                // ignore the bad number
-            }
-            return createBigInteger(str);
-        }
-
-        //Must be a Float, Double, BigDecimal
-        final boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
-        try {
-            if(numDecimals <= 7){// If number has 7 or fewer digits past the decimal point then make it a float
-                final Float f = createFloat(str);
-                if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
-                    return f;
-                }
-            }
-        } catch (final NumberFormatException nfe) { // NOPMD
-            // ignore the bad number
-        }
-        try {
-            if(numDecimals <= 16){// If number has between 8 and 16 digits past the decimal point then make it a double
-                final Double d = createDouble(str);
-                if (!(d.isInfinite() || (d.doubleValue() == 0.0D && !allZeros))) {
-                    return d;
-                }
-            }
-        } catch (final NumberFormatException nfe) { // NOPMD
-            // ignore the bad number
-        }
-
-        return createBigDecimal(str);
-    }
-
-    /**
-     * <p>Utility method for {@link #createNumber(java.lang.String)}.</p>
-     *
-     * <p>Returns mantissa of the given number.</p>
-     * 
-     * @param str the string representation of the number
-     * @return mantissa of the given number
-     */
-    private static String getMantissa(final String str) {
-        return getMantissa(str, str.length());
-    }
-
-    /**
-     * <p>Utility method for {@link #createNumber(java.lang.String)}.</p>
-     *
-     * <p>Returns mantissa of the given number.</p>
-     * 
-     * @param str the string representation of the number
-     * @param stopPos the position of the exponent or decimal point
-     * @return mantissa of the given number
-     */
-    private static String getMantissa(final String str, final int stopPos) {
-        final char firstChar = str.charAt(0);
-        final boolean hasSign = (firstChar == '-' || firstChar == '+');
-
-        return hasSign ? str.substring(1, stopPos) : str.substring(0, stopPos);
-    }
-
-    /**
-     * <p>Utility method for {@link #createNumber(java.lang.String)}.</p>
-     *
-     * <p>Returns <code>true</code> if s is <code>null</code>.</p>
-     * 
-     * @param str  the String to check
-     * @return if it is all zeros or <code>null</code>
-     */
-    private static boolean isAllZeros(final String str) {
-        if (str == null) {
-            return true;
-        }
-        for (int i = str.length() - 1; i >= 0; i--) {
-            if (str.charAt(i) != '0') {
-                return false;
-            }
-        }
-        return str.length() > 0;
-    }
-
-    //-----------------------------------------------------------------------
-    /**
-     * <p>Convert a <code>String</code> to a <code>Float</code>.</p>
-     *
-     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
-     * 
-     * @param str  a <code>String</code> to convert, may be null
-     * @return converted <code>Float</code> (or null if the input is null)
-     * @throws NumberFormatException if the value cannot be converted
-     */
-    public static Float createFloat(final String str) {
-        if (str == null) {
-            return null;
-        }
-        return Float.valueOf(str);
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to a <code>Double</code>.</p>
-     * 
-     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
-     *
-     * @param str  a <code>String</code> to convert, may be null
-     * @return converted <code>Double</code> (or null if the input is null)
-     * @throws NumberFormatException if the value cannot be converted
-     */
-    public static Double createDouble(final String str) {
-        if (str == null) {
-            return null;
-        }
-        return Double.valueOf(str);
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to a <code>Integer</code>, handling
-     * hex (0xhhhh) and octal (0dddd) notations.
-     * N.B. a leading zero means octal; spaces are not trimmed.</p>
-     *
-     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
-     * 
-     * @param str  a <code>String</code> to convert, may be null
-     * @return converted <code>Integer</code> (or null if the input is null)
-     * @throws NumberFormatException if the value cannot be converted
-     */
-    public static Integer createInteger(final String str) {
-        if (str == null) {
-            return null;
-        }
-        // decode() handles 0xAABD and 0777 (hex and octal) as well.
-        return Integer.decode(str);
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to a <code>Long</code>; 
-     * since 3.1 it handles hex (0Xhhhh) and octal (0ddd) notations.
-     * N.B. a leading zero means octal; spaces are not trimmed.</p>
-     * 
-     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
-     *
-     * @param str  a <code>String</code> to convert, may be null
-     * @return converted <code>Long</code> (or null if the input is null)
-     * @throws NumberFormatException if the value cannot be converted
-     */
-    public static Long createLong(final String str) {
-        if (str == null) {
-            return null;
-        }
-        return Long.decode(str);
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to a <code>BigInteger</code>;
-     * since 3.2 it handles hex (0x or #) and octal (0) notations.</p>
-     *
-     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
-     * 
-     * @param str  a <code>String</code> to convert, may be null
-     * @return converted <code>BigInteger</code> (or null if the input is null)
-     * @throws NumberFormatException if the value cannot be converted
-     */
-    public static BigInteger createBigInteger(final String str) {
-        if (str == null) {
-            return null;
-        }
-        int pos = 0; // offset within string
-        int radix = 10;
-        boolean negate = false; // need to negate later?
-        if (str.startsWith("-")) {
-            negate = true;
-            pos = 1;
-        }
-        if (str.startsWith("0x", pos) || str.startsWith("0X", pos)) { // hex
-            radix = 16;
-            pos += 2;
-        } else if (str.startsWith("#", pos)) { // alternative hex (allowed by Long/Integer)
-            radix = 16;
-            pos ++;
-        } else if (str.startsWith("0", pos) && str.length() > pos + 1) { // octal; so long as there are additional digits
-            radix = 8;
-            pos ++;
-        } // default is to treat as decimal
-
-        final BigInteger value = new BigInteger(str.substring(pos), radix);
-        return negate ? value.negate() : value;
-    }
-
-    /**
-     * <p>Convert a <code>String</code> to a <code>BigDecimal</code>.</p>
-     * 
-     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
-     *
-     * @param str  a <code>String</code> to convert, may be null
-     * @return converted <code>BigDecimal</code> (or null if the input is null)
-     * @throws NumberFormatException if the value cannot be converted
-     */
-    public static BigDecimal createBigDecimal(final String str) {
-        if (str == null) {
-            return null;
-        }
-        // handle JDK1.3.1 bug where "" throws IndexOutOfBoundsException
-        if (StringUtils.isBlank(str)) {
-            throw new NumberFormatException("A blank string is not a valid number");
-        }
-        if (str.trim().startsWith("--")) {
-            // this is protection for poorness in java.lang.BigDecimal.
-            // it accepts this as a legal value, but it does not appear 
-            // to be in specification of class. OS X Java parses it to 
-            // a wrong value.
-            throw new NumberFormatException(str + " is not a valid number.");
-        }
-        return new BigDecimal(str);
-    }
-
-    // Min in array
-    //--------------------------------------------------------------------
-    /**
-     * <p>Returns the minimum value in an array.</p>
-     * 
-     * @param array  an array, must not be null or empty
-     * @return the minimum value in the array
-     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
-     * @throws IllegalArgumentException if <code>array</code> is empty
-     * @since 3.4 Changed signature from min(long[]) to min(long...)
-     */
-    public static long min(final long... array) {
-        // Validates input
-        validateArray(array);
-    
-        // Finds and returns min
-        long min = array[0];
-        for (int i = 1; i < array.length; i++) {
-            if (array[i] < min) {
-                min = array[i];
-            }
-        }
-    
-        return min;
-    }
-
-    /**
-     * <p>Returns the minimum value in an array.</p>
-     * 
-     * @param array  an array, must not be null or empty
-     * @return the minimum value in the array
-     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
-     * @throws IllegalArgumentException if <code>array</code> is empty
-     * @since 3.4 Changed signature from min(int[]) to min(int...)
-     */
-    public static int min(final int... array) {
-        // Validates input
-        validateArray(array);
-    
-        // Finds and returns min
-        int min = array[0];
-        for (int j = 1; j < array.length; j++) {
-            if (array[j] < min) {
-                min = array[j];
-            }
-        }
-    
-        return min;
-    }
-
-    /**
-     * <p>Returns the minimum value in an array.</p>
-     * 
-     * @param array  an array, must not be null or empty
-     * @return the minimum value in the array
-     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
-     * @throws IllegalArgumentException if <code>array</code> is empty
-     * @since 3.4 Changed signature from min(short[]) to min(short...)
-     */
-    public static short min(final short... array) {
-        // Validates input
-        validateArray(array);
-    
-        // Finds and returns min
-        short min = array[0];
-        for (int i = 1; i < array.length; i++) {
-            if (array[i] < min) {
-                min = array[i];
-            }
-        }
-    
-        return min;
-    }
-
-    /**
-     * <p>Returns the minimum value in an array.</p>
-     * 
-     * @param array  an array, must not be null or empty
-     * @return the minimum value in the array
-     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
-     * @throws IllegalArgumentException if <code>array</code> is empty
-     * @since 3.4 Changed signature from min(byte[]) to min(byte...)
-     */
-    public static byte min(final byte... array) {
-        // Validates input
-        validateArray(array);
-    
-        // Finds and returns min
-        byte min = array[0];
-        for (int i = 1; i < array.length; i++) {
-            if (array[i] < min) {
-                min = array[i];
-            }
-        }
-    
-        return min;
-    }
-
-     /**
-     * <p>Returns the minimum value in an array.</p>
-     * 
-     * @param array  an array, must not be null or empty
-     * @return the minimum value in the array
-     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
-     * @throws IllegalArgumentException if <code>array</code> is empty
-     * @see IEEE754rUtils#min(double[]) IEEE754rUtils for a version of this method that handles NaN differently
-     * @since 3.4 Changed signature from min(double[]) to min(double...)
-     */
-    public static double min(final double... array) {
-        // Validates input
-        validateArray(array);
-    
-        // Finds and returns min
-        double min = array[0];
-        for (int i = 1; i < array.length; i++) {
-            if (Double.isNaN(array[i])) {
-                return Double.NaN;
-            }
-            if (array[i] < min) {
-                min = array[i];
-            }
-        }
-    
-        return min;
-    }
-
-    /**
-     * <p>Returns the minimum value in an array.</p>
-     * 
-     * @param array  an array, must not be null or empty
-     * @return the minimum value in the array
-     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
-     * @throws IllegalArgumentException if <code>array</code> is empty
-     * @see IEEE754rUtils#min(float[]) IEEE754rUtils for a version of this method that handles NaN differently
-     * @since 3.4 Changed signature from min(float[]) to min(float...)
-     */
-    public static float min(final float... array) {
-        // Validates input
-        validateArray(array);
-    
-        // Finds and returns min
-        float min = array[0];
-        for (int i = 1; i < array.length; i++) {
-            if (Float.isNaN(array[i])) {
-                return Float.NaN;
-            }
-            if (array[i] < min) {
-                min = array[i];
-            }
-        }
-    
-        return min;
-    }
-
-    // Max in array
-    //--------------------------------------------------------------------
-    /**
-     * <p>Returns the maximum value in an array.</p>
-     * 
-     * @param array  an array, must not be null or empty
-     * @return the maximum value in the array
-     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
-     * @throws IllegalArgumentException if <code>array</code> is empty
-     * @since 3.4 Changed signature from max(long[]) to max(long...)
-     */
-    public static long max(final long... array) {
-        // Validates input
-        validateArray(array);
-
-        // Finds and returns max
-        long max = array[0];
-        for (int j = 1; j < array.length; j++) {
-            if (array[j] > max) {
-                max = array[j];
-            }
-        }
-
-        return max;
-    }
-
-    /**
-     * <p>Returns the maximum value in an array.</p>
-     * 
-     * @param array  an array, must not be null or empty
-     * @return the maximum value in the array
-     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
-     * @throws IllegalArgumentException if <code>array</code> is empty
-     * @since 3.4 Changed signature from max(int[]) to max(int...)
-     */
-    public static int max(final int... array) {
-        // Validates input
-        validateArray(array);
-    
-        // Finds and returns max
-        int max = array[0];
-        for (int j = 1; j < array.length; j++) {
-            if (array[j] > max) {
-                max = array[j];
-            }
-        }
-    
-        return max;
-    }
-
-    /**
-     * <p>Returns the maximum value in an array.</p>
-     * 
-     * @param array  an array, must not be null or empty
-     * @return the maximum value in the array
-     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
-     * @throws IllegalArgumentException if <code>array</code> is empty
-     * @since 3.4 Changed signature from max(short[]) to max(short...)
-     */
-    public static short max(final short... array) {
-        // Validates input
-        validateArray(array);
-    
-        // Finds and returns max
-        short max = array[0];
-        for (int i = 1; i < array.length; i++) {
-            if (array[i] > max) {
-                max = array[i];
-            }
-        }
-    
-        return max;
-    }
-
-    /**
-     * <p>Returns the maximum value in an array.</p>
-     * 
-     * @param array  an array, must not be null or empty
-     * @return the maximum value in the array
-     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
-     * @throws IllegalArgumentException if <code>array</code> is empty
-     * @since 3.4 Changed signature from max(byte[]) to max(byte...)
-     */
-    public static byte max(final byte... array) {
-        // Validates input
-        validateArray(array);
-    
-        // Finds and returns max
-        byte max = array[0];
-        for (int i = 1; i < array.length; i++) {
-            if (array[i] > max) {
-                max = array[i];
-            }
-        }
-    
-        return max;
-    }
-
-    /**
-     * <p>Returns the maximum value in an array.</p>
-     * 
-     * @param array  an array, must not be null or empty
-     * @return the maximum value in the array
-     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
-     * @throws IllegalArgumentException if <code>array</code> is empty
-     * @see IEEE754rUtils#max(double[]) IEEE754rUtils for a version of this method that handles NaN differently
-     * @since 3.4 Changed signature from max(double[]) to max(double...)
-     */
-    public static double max(final double... array) {
-        // Validates input
-        validateArray(array);
-
-        // Finds and returns max
-        double max = array[0];
-        for (int j = 1; j < array.length; j++) {
-            if (Double.isNaN(array[j])) {
-                return Double.NaN;
-            }
-            if (array[j] > max) {
-                max = array[j];
-            }
-        }
-    
-        return max;
-    }
-
-    /**
-     * <p>Returns the maximum value in an array.</p>
-     * 
-     * @param array  an array, must not be null or empty
-     * @return the maximum value in the array
-     * @throws IllegalArgumentException if <code>array</code> is <code>null</code>
-     * @throws IllegalArgumentException if <code>array</code> is empty
-     * @see IEEE754rUtils#max(float[]) IEEE754rUtils for a version of this method that handles NaN differently
-     * @since 3.4 Changed signature from max(float[]) to max(float...)
-     */
-    public static float max(final float... array) {
-        // Validates input
-        validateArray(array);
-
-        // Finds and returns max
-        float max = array[0];
-        for (int j = 1; j < array.length; j++) {
-            if (Float.isNaN(array[j])) {
-                return Float.NaN;
-            }
-            if (array[j] > max) {
-                max = array[j];
-            }
-        }
-
-        return max;
-    }
-
-    /**
-     * Checks if the specified array is neither null nor empty.
-     *
-     * @param array  the array to check
-     * @throws IllegalArgumentException if {@code array} is either {@code null} or empty
-     */
-    private static void validateArray(final Object array) {
-        if (array == null) {
-            throw new IllegalArgumentException("The Array must not be null");
-        }        
-        Validate.isTrue(Array.getLength(array) != 0, "Array cannot be empty.");        
-    }
-     
-    // 3 param min
-    //-----------------------------------------------------------------------
-    /**
-     * <p>Gets the minimum of three <code>long</code> values.</p>
-     * 
-     * @param a  value 1
-     * @param b  value 2
-     * @param c  value 3
-     * @return  the smallest of the values
-     */
-    public static long min(long a, final long b, final long c) {
-        if (b < a) {
-            a = b;
-        }
-        if (c < a) {
-            a = c;
-        }
-        return a;
-    }
-
-    /**
-     * <p>Gets the minimum of three <code>int</code> values.</p>
-     * 
-     * @param a  value 1
-     * @param b  value 2
-     * @param c  value 3
-     * @return  the smallest of the values
-     */
-    public static int min(int a, final int b, final int c) {
-        if (b < a) {
-            a = b;
-        }
-        if (c < a) {
-            a = c;
-        }
-        return a;
-    }
-
-    /**
-     * <p>Gets the minimum of three <code>short</code> values.</p>
-     * 
-     * @param a  value 1
-     * @param b  value 2
-     * @param c  value 3
-     * @return  the smallest of the values
-     */
-    public static short min(short a, final short b, final short c) {
-        if (b < a) {
-            a = b;
-        }
-        if (c < a) {
-            a = c;
-        }
-        return a;
-    }
-
-    /**
-     * <p>Gets the minimum of three <code>byte</code> values.</p>
-     * 
-     * @param a  value 1
-     * @param b  value 2
-     * @param c  value 3
-     * @return  the smallest of the values
-     */
-    public static byte min(byte a, final byte b, final byte c) {
-        if (b < a) {
-            a = b;
-        }
-        if (c < a) {
-            a = c;
-        }
-        return a;
-    }
-
-    /**
-     * <p>Gets the minimum of three <code>double</code> values.</p>
-     * 
-     * <p>If any value is <code>NaN</code>, <code>NaN</code> is
-     * returned. Infinity is handled.</p>
-     * 
-     * @param a  value 1
-     * @param b  value 2
-     * @param c  value 3
-     * @return  the smallest of the values
-     * @see IEEE754rUtils#min(double, double, double) for a version of this method that handles NaN differently
-     */
-    public static double min(final double a, final double b, final double c) {
-        return Math.min(Math.min(a, b), c);
-    }
-
-    /**
-     * <p>Gets the minimum of three <code>float</code> values.</p>
-     * 
-     * <p>If any value is <code>NaN</code>, <code>NaN</code> is
-     * returned. Infinity is handled.</p>
-     *
-     * @param a  value 1
-     * @param b  value 2
-     * @param c  value 3
-     * @return  the smallest of the values
-     * @see IEEE754rUtils#min(float, float, float) for a version of this method that handles NaN differently
-     */
-    public static float min(final float a, final float b, final float c) {
-        return Math.min(Math.min(a, b), c);
-    }
-
-    // 3 param max
-    //-----------------------------------------------------------------------
-    /**
-     * <p>Gets the maximum of three <code>long</code> values.</p>
-     * 
-     * @param a  value 1
-     * @param b  value 2
-     * @param c  value 3
-     * @return  the largest of the values
-     */
-    public static long max(long a, final long b, final long c) {
-        if (b > a) {
-            a = b;
-        }
-        if (c > a) {
-            a = c;
-        }
-        return a;
-    }
-
-    /**
-     * <p>Gets the maximum of three <code>int</code> values.</p>
-     * 
-     * @param a  value 1
-     * @param b  value 2
-     * @param c  value 3
-     * @return  the largest of the values
-     */
-    public static int max(int a, final int b, final int c) {
-        if (b > a) {
-            a = b;
-        }
-        if (c > a) {
-            a = c;
-        }
-        return a;
-    }
-
-    /**
-     * <p>Gets the maximum of three <code>short</code> values.</p>
-     * 
-     * @param a  value 1
-     * @param b  value 2
-     * @param c  value 3
-     * @return  the largest of the values
-     */
-    public static short max(short a, final short b, final short c) {
-        if (b > a) {
-            a = b;
-        }
-        if (c > a) {
-            a = c;
-        }
-        return a;
-    }
-
-    /**
-     * <p>Gets the maximum of three <code>byte</code> values.</p>
-     * 
-     * @param a  value 1
-     * @param b  value 2
-     * @param c  value 3
-     * @return  the largest of the values
-     */
-    public static byte max(byte a, final byte b, final byte c) {
-        if (b > a) {
-            a = b;
-        }
-        if (c > a) {
-            a = c;
-        }
-        return a;
-    }
-
-    /**
-     * <p>Gets the maximum of three <code>double</code> values.</p>
-     * 
-     * <p>If any value is <code>NaN</code>, <code>NaN</code> is
-     * returned. Infinity is handled.</p>
-     *
-     * @param a  value 1
-     * @param b  value 2
-     * @param c  value 3
-     * @return  the largest of the values
-     * @see IEEE754rUtils#max(double, double, double) for a version of this method that handles NaN differently
-     */
-    public static double max(final double a, final double b, final double c) {
-        return Math.max(Math.max(a, b), c);
-    }
-
-    /**
-     * <p>Gets the maximum of three <code>float</code> values.</p>
-     * 
-     * <p>If any value is <code>NaN</code>, <code>NaN</code> is
-     * returned. Infinity is handled.</p>
-     *
-     * @param a  value 1
-     * @param b  value 2
-     * @param c  value 3
-     * @return  the largest of the values
-     * @see IEEE754rUtils#max(float, float, float) for a version of this method that handles NaN differently
-     */
-    public static float max(final float a, final float b, final float c) {
-        return Math.max(Math.max(a, b), c);
-    }
-
-    //-----------------------------------------------------------------------
-    /**
-     * <p>Checks whether the <code>String</code> contains only
-     * digit characters.</p>
-     *
-     * <p><code>Null</code> and empty String will return
-     * <code>false</code>.</p>
-     *
-     * @param str  the <code>String</code> to check
-     * @return <code>true</code> if str contains only Unicode numeric
-     */
-    public static boolean isDigits(final String str) {
-        return StringUtils.isNumeric(str);
-    }
-
-    /**
-     * <p>Checks whether the String a valid Java number.</p>
-     *
-     * <p>Valid numbers include hexadecimal marked with the <code>0x</code> or
-     * <code>0X</code> qualifier, octal numbers, scientific notation and numbers 
-     * marked with a type qualifier (e.g. 123L).</p>
-     * 
-     * <p>Non-hexadecimal strings beginning with a leading zero are
-     * treated as octal values. Thus the string <code>09</code> will return
-     * <code>false</code>, since <code>9</code> is not a valid octal value.
-     * However, numbers beginning with {@code 0.} are treated as decimal.</p>
-     *
-     * <p><code>null</code> and empty/blank {@code String} will return
-     * <code>false</code>.</p>
-     *
-     * @param str  the <code>String</code> to check
-     * @return <code>true</code> if the string is a correctly formatted number
-     * @since 3.3 the code supports hex {@code 0Xhhh} and octal {@code 0ddd} validation
-     */
-    public static boolean isNumber(final String str) {
-        if (StringUtils.isEmpty(str)) {
-            return false;
-        }
-        final char[] chars = str.toCharArray();
-        int sz = chars.length;
-        boolean hasExp = false;
-        boolean hasDecPoint = false;
-        boolean allowSigns = false;
-        boolean foundDigit = false;
-        // deal with any possible sign up front
-        final int start = (chars[0] == '-') ? 1 : 0;
-        if (sz > start + 1 && chars[start] == '0') { // leading 0
-            if (
-                 (chars[start + 1] == 'x') || 
-                 (chars[start + 1] == 'X') 
-            ) { // leading 0x/0X
-                int i = start + 2;
-                if (i == sz) {
-                    return false; // str == "0x"
-                }
-                // checking hex (it can't be anything else)
-                for (; i < chars.length; i++) {
-                    if ((chars[i] < '0' || chars[i] > '9')
-                        && (chars[i] < 'a' || chars[i] > 'f')
-                        && (chars[i] < 'A' || chars[i] > 'F')) {
-                        return false;
-                    }
-                }
-                return true;
-           } else if (Character.isDigit(chars[start + 1])) {
-               // leading 0, but not hex, must be octal
-               int i = start + 1;
-               for (; i < chars.length; i++) {
-                   if (chars[i] < '0' || chars[i] > '7') {
-                       return false;
-                   }
-               }
-               return true;               
-           }
-        }
-        sz--; // don't want to loop to the last char, check it afterwords
-              // for type qualifiers
-        int i = start;
-        // loop to the next to last char or to the last char if we need another digit to
-        // make a valid number (e.g. chars[0..5] = "1234E")
-        while (i < sz || (i < sz + 1 && allowSigns && !foundDigit)) {
-            if (chars[i] >= '0' && chars[i] <= '9') {
-                foundDigit = true;
-                allowSigns = false;
-
-            } else if (chars[i] == '.') {
-                if (hasDecPoint || hasExp) {
-                    // two decimal points or dec in exponent   
-                    return false;
-                }
-                hasDecPoint = true;
-            } else if (chars[i] == 'e' || chars[i] == 'E') {
-                // we've already taken care of hex.
-                if (hasExp) {
-                    // two E's
-                    return false;
-                }
-                if (!foundDigit) {
-                    return false;
-                }
-                hasExp = true;
-                allowSigns = true;
-            } else if (chars[i] == '+' || chars[i] == '-') {
-                if (!allowSigns) {
-                    return false;
-                }
-                allowSigns = false;
-                foundDigit = false; // we need a digit after the E
-            } else {
-                return false;
-            }
-            i++;
-        }
-        if (i < chars.length) {
-            if (chars[i] >= '0' && chars[i] <= '9') {
-                // no type qualifier, OK
-                return true;
-            }
-            if (chars[i] == 'e' || chars[i] == 'E') {
-                // can't have an E at the last byte
-                return false;
-            }
-            if (chars[i] == '.') {
-                if (hasDecPoint || hasExp) {
-                    // two decimal points or dec in exponent
-                    return false;
-                }
-                // single trailing decimal point after non-exponent is ok
-                return foundDigit;
-            }
-            if (!allowSigns
-                && (chars[i] == 'd'
-                    || chars[i] == 'D'
-                    || chars[i] == 'f'
-                    || chars[i] == 'F')) {
-                return foundDigit;
-            }
-            if (chars[i] == 'l'
-                || chars[i] == 'L') {
-                // not allowing L with an exponent or decimal point
-                return foundDigit && !hasExp && !hasDecPoint;
-            }
-            // last character is illegal
-            return false;
-        }
-        // allowSigns is true iff the val ends in 'E'
-        // found digit it to make sure weird stuff like '.' and '1E-' doesn't pass
-        return !allowSigns && foundDigit;
-    }
-    
-    /**
-     * <p>Checks whether the given String is a parsable number.</p>
-     *
-     * <p>Parsable numbers include those Strings understood by {@link Integer#parseInt(String)},
-     * {@link Long#parseLong(String)}, {@link Float#parseFloat(String)} or
-     * {@link Double#parseDouble(String)}. This method can be used instead of catching {@link java.text.ParseException}
-     * when calling one of those methods.</p>
-     *
-     * <p>Hexadecimal and scientific notations are <strong>not</strong> considered parsable.
-     * See {@link #isNumber(String)} on those cases.</p>
-     *
-     * <p>{@code Null} and empty String will return <code>false</code>.</p>
-     *
-     * @param str the String to check.
-     * @return {@code true} if the string is a parsable number.
-     * @since 3.4
-     */
-    public static boolean isParsable(final String str) {
-        if( StringUtils.endsWith( str, "." ) ) {
-            return false;
-        }
-        if( StringUtils.startsWith( str, "-" ) ) {
-            return isDigits( StringUtils.replaceOnce( str.substring(1), ".", StringUtils.EMPTY ) );
-        }
-        return isDigits( StringUtils.replaceOnce( str, ".", StringUtils.EMPTY ) );
-    }
-
-    /**
-     * <p>Compares two {@code int} values numerically. This is the same functionality as provided in Java 7.</p>
-     *
-     * @param x the first {@code int} to compare
-     * @param y the second {@code int} to compare
-     * @return the value {@code 0} if {@code x == y};
-     *         a value less than {@code 0} if {@code x < y}; and
-     *         a value greater than {@code 0} if {@code x > y}
-     * @since 3.4
-     */
-    public static int compare(int x, int y) {
-        if (x == y) {
-            return 0;
-        }
-        return x < y ? -1 : 1;
-    }
-
-    /**
-     * <p>Compares to {@code long} values numerically. This is the same functionality as provided in Java 7.</p>
-     *
-     * @param x the first {@code long} to compare
-     * @param y the second {@code long} to compare
-     * @return the value {@code 0} if {@code x == y};
-     *         a value less than {@code 0} if {@code x < y}; and
-     *         a value greater than {@code 0} if {@code x > y}
-     * @since 3.4
-     */
-    public static int compare(long x, long y) {
-        if (x == y) {
-            return 0;
-        }
-        return x < y ? -1 : 1;
-    }
-
-    /**
-     * <p>Compares to {@code short} values numerically. This is the same functionality as provided in Java 7.</p>
-     *
-     * @param x the first {@code short} to compare
-     * @param y the second {@code short} to compare
-     * @return the value {@code 0} if {@code x == y};
-     *         a value less than {@code 0} if {@code x < y}; and
-     *         a value greater than {@code 0} if {@code x > y}
-     * @since 3.4
-     */
-    public static int compare(short x, short y) {
-        if (x == y) {
-            return 0;
-        }
-        return x < y ? -1 : 1;
-    }
-
-    /**
-     * <p>Compares two {@code byte} values numerically. This is the same functionality as provided in Java 7.</p>
-     *
-     * @param x the first {@code byte} to compare
-     * @param y the second {@code byte} to compare
-     * @return the value {@code 0} if {@code x == y};
-     *         a value less than {@code 0} if {@code x < y}; and
-     *         a value greater than {@code 0} if {@code x > y}
-     * @since 3.4
-     */
-    public static int compare(byte x, byte y) {
-        return x - y;
-    }
-}
+/*
+ * 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.lang3.math;
+
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * <p>Provides extra functionality for Java Number classes.</p>
+ *
+ * @since 2.0
+ */
+public class NumberUtils {
+    
+    /** Reusable Long constant for zero. */
+    public static final Long LONG_ZERO = Long.valueOf(0L);
+    /** Reusable Long constant for one. */
+    public static final Long LONG_ONE = Long.valueOf(1L);
+    /** Reusable Long constant for minus one. */
+    public static final Long LONG_MINUS_ONE = Long.valueOf(-1L);
+    /** Reusable Integer constant for zero. */
+    public static final Integer INTEGER_ZERO = Integer.valueOf(0);
+    /** Reusable Integer constant for one. */
+    public static final Integer INTEGER_ONE = Integer.valueOf(1);
+    /** Reusable Integer constant for minus one. */
+    public static final Integer INTEGER_MINUS_ONE = Integer.valueOf(-1);
+    /** Reusable Short constant for zero. */
+    public static final Short SHORT_ZERO = Short.valueOf((short) 0);
+    /** Reusable Short constant for one. */
+    public static final Short SHORT_ONE = Short.valueOf((short) 1);
+    /** Reusable Short constant for minus one. */
+    public static final Short SHORT_MINUS_ONE = Short.valueOf((short) -1);
+    /** Reusable Byte constant for zero. */
+    public static final Byte BYTE_ZERO = Byte.valueOf((byte) 0);
+    /** Reusable Byte constant for one. */
+    public static final Byte BYTE_ONE = Byte.valueOf((byte) 1);
+    /** Reusable Byte constant for minus one. */
+    public static final Byte BYTE_MINUS_ONE = Byte.valueOf((byte) -1);
+    /** Reusable Double constant for zero. */
+    public static final Double DOUBLE_ZERO = Double.valueOf(0.0d);
+    /** Reusable Double constant for one. */
+    public static final Double DOUBLE_ONE = Double.valueOf(1.0d);
+    /** Reusable Double constant for minus one. */
+    public static final Double DOUBLE_MINUS_ONE = Double.valueOf(-1.0d);
+    /** Reusable Float constant for zero. */
+    public static final Float FLOAT_ZERO = Float.valueOf(0.0f);
+    /** Reusable Float constant for one. */
+    public static final Float FLOAT_ONE = Float.valueOf(1.0f);
+    /** Reusable Float constant for minus one. */
+    public static final Float FLOAT_MINUS_ONE = Float.valueOf(-1.0f);
+
+    /**
+     * <p><code>NumberUtils</code> instances should NOT be constructed in standard programming.
+     * Instead, the class should be used as <code>NumberUtils.toInt("6");</code>.</p>
+     *
+     * <p>This constructor is public to permit tools that require a JavaBean instance
+     * to operate.</p>
+     */
+    public NumberUtils() {
+        super();
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Convert a <code>String</code> to an <code>int</code>, returning
+     * <code>zero</code> if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toInt(null) = 0
+     *   NumberUtils.toInt("")   = 0
+     *   NumberUtils.toInt("1")  = 1
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @return the int represented by the string, or <code>zero</code> if
+     *  conversion fails
+     * @since 2.1
+     */
+    public static int toInt(final String str) {
+        return toInt(str, 0);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to an <code>int</code>, returning a
+     * default value if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, the default value is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toInt(null, 1) = 1
+     *   NumberUtils.toInt("", 1)   = 1
+     *   NumberUtils.toInt("1", 0)  = 1
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @param defaultValue  the default value
+     * @return the int represented by the string, or the default if conversion fails
+     * @since 2.1
+     */
+    public static int toInt(final String str, final int defaultValue) {
+        if(str == null) {
+            return defaultValue;
+        }
+        try {
+            return Integer.parseInt(str);
+        } catch (final NumberFormatException nfe) {
+            return defaultValue;
+        }
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>long</code>, returning
+     * <code>zero</code> if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toLong(null) = 0L
+     *   NumberUtils.toLong("")   = 0L
+     *   NumberUtils.toLong("1")  = 1L
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @return the long represented by the string, or <code>0</code> if
+     *  conversion fails
+     * @since 2.1
+     */
+    public static long toLong(final String str) {
+        return toLong(str, 0L);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>long</code>, returning a
+     * default value if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, the default value is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toLong(null, 1L) = 1L
+     *   NumberUtils.toLong("", 1L)   = 1L
+     *   NumberUtils.toLong("1", 0L)  = 1L
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @param defaultValue  the default value
+     * @return the long represented by the string, or the default if conversion fails
+     * @since 2.1
+     */
+    public static long toLong(final String str, final long defaultValue) {
+        if (str == null) {
+            return defaultValue;
+        }
+        try {
+            return Long.parseLong(str);
+        } catch (final NumberFormatException nfe) {
+            return defaultValue;
+        }
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>float</code>, returning
+     * <code>0.0f</code> if the conversion fails.</p>
+     *
+     * <p>If the string <code>str</code> is <code>null</code>,
+     * <code>0.0f</code> is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toFloat(null)   = 0.0f
+     *   NumberUtils.toFloat("")     = 0.0f
+     *   NumberUtils.toFloat("1.5")  = 1.5f
+     * </pre>
+     *
+     * @param str the string to convert, may be <code>null</code>
+     * @return the float represented by the string, or <code>0.0f</code>
+     *  if conversion fails
+     * @since 2.1
+     */
+    public static float toFloat(final String str) {
+        return toFloat(str, 0.0f);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>float</code>, returning a
+     * default value if the conversion fails.</p>
+     *
+     * <p>If the string <code>str</code> is <code>null</code>, the default
+     * value is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toFloat(null, 1.1f)   = 1.0f
+     *   NumberUtils.toFloat("", 1.1f)     = 1.1f
+     *   NumberUtils.toFloat("1.5", 0.0f)  = 1.5f
+     * </pre>
+     *
+     * @param str the string to convert, may be <code>null</code>
+     * @param defaultValue the default value
+     * @return the float represented by the string, or defaultValue
+     *  if conversion fails
+     * @since 2.1
+     */
+    public static float toFloat(final String str, final float defaultValue) {
+      if (str == null) {
+          return defaultValue;
+      }     
+      try {
+          return Float.parseFloat(str);
+      } catch (final NumberFormatException nfe) {
+          return defaultValue;
+      }
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>double</code>, returning
+     * <code>0.0d</code> if the conversion fails.</p>
+     *
+     * <p>If the string <code>str</code> is <code>null</code>,
+     * <code>0.0d</code> is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toDouble(null)   = 0.0d
+     *   NumberUtils.toDouble("")     = 0.0d
+     *   NumberUtils.toDouble("1.5")  = 1.5d
+     * </pre>
+     *
+     * @param str the string to convert, may be <code>null</code>
+     * @return the double represented by the string, or <code>0.0d</code>
+     *  if conversion fails
+     * @since 2.1
+     */
+    public static double toDouble(final String str) {
+        return toDouble(str, 0.0d);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>double</code>, returning a
+     * default value if the conversion fails.</p>
+     *
+     * <p>If the string <code>str</code> is <code>null</code>, the default
+     * value is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toDouble(null, 1.1d)   = 1.1d
+     *   NumberUtils.toDouble("", 1.1d)     = 1.1d
+     *   NumberUtils.toDouble("1.5", 0.0d)  = 1.5d
+     * </pre>
+     *
+     * @param str the string to convert, may be <code>null</code>
+     * @param defaultValue the default value
+     * @return the double represented by the string, or defaultValue
+     *  if conversion fails
+     * @since 2.1
+     */
+    public static double toDouble(final String str, final double defaultValue) {
+      if (str == null) {
+          return defaultValue;
+      }
+      try {
+          return Double.parseDouble(str);
+      } catch (final NumberFormatException nfe) {
+          return defaultValue;
+      }
+    }
+
+     //-----------------------------------------------------------------------
+     /**
+     * <p>Convert a <code>String</code> to a <code>byte</code>, returning
+     * <code>zero</code> if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toByte(null) = 0
+     *   NumberUtils.toByte("")   = 0
+     *   NumberUtils.toByte("1")  = 1
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @return the byte represented by the string, or <code>zero</code> if
+     *  conversion fails
+     * @since 2.5
+     */
+    public static byte toByte(final String str) {
+        return toByte(str, (byte) 0);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>byte</code>, returning a
+     * default value if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, the default value is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toByte(null, 1) = 1
+     *   NumberUtils.toByte("", 1)   = 1
+     *   NumberUtils.toByte("1", 0)  = 1
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @param defaultValue  the default value
+     * @return the byte represented by the string, or the default if conversion fails
+     * @since 2.5
+     */
+    public static byte toByte(final String str, final byte defaultValue) {
+        if(str == null) {
+            return defaultValue;
+        }
+        try {
+            return Byte.parseByte(str);
+        } catch (final NumberFormatException nfe) {
+            return defaultValue;
+        }
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>short</code>, returning
+     * <code>zero</code> if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, <code>zero</code> is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toShort(null) = 0
+     *   NumberUtils.toShort("")   = 0
+     *   NumberUtils.toShort("1")  = 1
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @return the short represented by the string, or <code>zero</code> if
+     *  conversion fails
+     * @since 2.5
+     */
+    public static short toShort(final String str) {
+        return toShort(str, (short) 0);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to an <code>short</code>, returning a
+     * default value if the conversion fails.</p>
+     *
+     * <p>If the string is <code>null</code>, the default value is returned.</p>
+     *
+     * <pre>
+     *   NumberUtils.toShort(null, 1) = 1
+     *   NumberUtils.toShort("", 1)   = 1
+     *   NumberUtils.toShort("1", 0)  = 1
+     * </pre>
+     *
+     * @param str  the string to convert, may be null
+     * @param defaultValue  the default value
+     * @return the short represented by the string, or the default if conversion fails
+     * @since 2.5
+     */
+    public static short toShort(final String str, final short defaultValue) {
+        if(str == null) {
+            return defaultValue;
+        }
+        try {
+            return Short.parseShort(str);
+        } catch (final NumberFormatException nfe) {
+            return defaultValue;
+        }
+    }
+
+    //-----------------------------------------------------------------------
+    // must handle Long, Float, Integer, Float, Short,
+    //                  BigDecimal, BigInteger and Byte
+    // useful methods:
+    // Byte.decode(String)
+    // Byte.valueOf(String,int radix)
+    // Byte.valueOf(String)
+    // Double.valueOf(String)
+    // Float.valueOf(String)
+    // Float.valueOf(String)
+    // Integer.valueOf(String,int radix)
+    // Integer.valueOf(String)
+    // Integer.decode(String)
+    // Integer.getInteger(String)
+    // Integer.getInteger(String,int val)
+    // Integer.getInteger(String,Integer val)
+    // Integer.valueOf(String)
+    // Double.valueOf(String)
+    // new Byte(String)
+    // Long.valueOf(String)
+    // Long.getLong(String)
+    // Long.getLong(String,int)
+    // Long.getLong(String,Integer)
+    // Long.valueOf(String,int)
+    // Long.valueOf(String)
+    // Short.valueOf(String)
+    // Short.decode(String)
+    // Short.valueOf(String,int)
+    // Short.valueOf(String)
+    // new BigDecimal(String)
+    // new BigInteger(String)
+    // new BigInteger(String,int radix)
+    // Possible inputs:
+    // 45 45.5 45E7 4.5E7 Hex Oct Binary xxxF xxxD xxxf xxxd
+    // plus minus everything. Prolly more. A lot are not separable.
+
+    /**
+     * <p>Turns a string value into a java.lang.Number.</p>
+     *
+     * <p>If the string starts with {@code 0x} or {@code -0x} (lower or upper case) or {@code #} or {@code -#}, it
+     * will be interpreted as a hexadecimal Integer - or Long, if the number of digits after the
+     * prefix is more than 8 - or BigInteger if there are more than 16 digits.
+     * </p>
+     * <p>Then, the value is examined for a type qualifier on the end, i.e. one of
+     * <code>'f','F','d','D','l','L'</code>.  If it is found, it starts 
+     * trying to create successively larger types from the type specified
+     * until one is found that can represent the value.</p>
+     *
+     * <p>If a type specifier is not found, it will check for a decimal point
+     * and then try successively larger types from <code>Integer</code> to
+     * <code>BigInteger</code> and from <code>Float</code> to
+    * <code>BigDecimal</code>.</p>
+    * 
+     * <p>
+     * Integral values with a leading {@code 0} will be interpreted as octal; the returned number will
+     * be Integer, Long or BigDecimal as appropriate.
+     * </p>
+     *
+     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
+     *
+     * <p>This method does not trim the input string, i.e., strings with leading
+     * or trailing spaces will generate NumberFormatExceptions.</p>
+     *
+     * @param str  String containing a number, may be null
+     * @return Number created from the string (or null if the input is null)
+     * @throws NumberFormatException if the value cannot be converted
+     */
+    public static Number createNumber(final String str) throws NumberFormatException {
+        if (str == null) {
+            return null;
+        }
+        if (StringUtils.isBlank(str)) {
+            throw new NumberFormatException("A blank string is not a valid number");
+        }
+        // Need to deal with all possible hex prefixes here
+        final String[] hex_prefixes = {"0x", "0X", "-0x", "-0X", "#", "-#"};
+        int pfxLen = 0;
+        for(final String pfx : hex_prefixes) {
+            if (str.startsWith(pfx)) {
+                pfxLen += pfx.length();
+                break;
+            }
+        }
+        if (pfxLen > 0) { // we have a hex number
+            char firstSigDigit = 0; // strip leading zeroes
+            for(int i = pfxLen; i < str.length(); i++) {
+                firstSigDigit = str.charAt(i);
+                if (firstSigDigit == '0') { // count leading zeroes
+                    pfxLen++;
+                } else {
+                    break;
+                }
+            }
+            final int hexDigits = str.length() - pfxLen;
+            if (hexDigits > 16 || (hexDigits == 16 && firstSigDigit > '7')) { // too many for Long
+                return createBigInteger(str);
+            }
+            if (hexDigits > 8 || (hexDigits == 8 && firstSigDigit > '7')) { // too many for an int
+                return createLong(str);
+            }
+            return createInteger(str);
+        }
+        final char lastChar = str.charAt(str.length() - 1);
+        String mant;
+        String dec;
+        String exp;
+        final int decPos = str.indexOf('.');
+        final int expPos = str.indexOf('e') + str.indexOf('E') + 1; // assumes both not present
+        // if both e and E are present, this is caught by the checks on expPos (which prevent IOOBE)
+        // and the parsing which will detect if e or E appear in a number due to using the wrong offset
+
+        int numDecimals = 0; // Check required precision (LANG-693)
+        if (decPos > -1) { // there is a decimal point
+
+            if (expPos > -1) { // there is an exponent
+                if (expPos < decPos || expPos > str.length()) { // prevents double exponent causing IOOBE
+                    throw new NumberFormatException(str + " is not a valid number.");
+                }
+                dec = str.substring(decPos + 1, expPos);
+            } else {
+                dec = str.substring(decPos + 1);
+            }
+            mant = getMantissa(str, decPos);
+            numDecimals = dec.length(); // gets number of digits past the decimal to ensure no loss of precision for floating point numbers.
+        } else {
+            if (expPos > -1) {
+                if (expPos > str.length()) { // prevents double exponent causing IOOBE
+                    throw new NumberFormatException(str + " is not a valid number.");
+                }
+                mant = getMantissa(str, expPos);
+            } else {
+                mant = getMantissa(str);
+            }
+            dec = null;
+        }
+        if (!Character.isDigit(lastChar) && lastChar != '.') {
+            if (expPos > -1 && expPos < str.length() - 1) {
+                exp = str.substring(expPos + 1, str.length() - 1);
+            } else {
+                exp = null;
+            }
+            //Requesting a specific type..
+            final String numeric = str.substring(0, str.length() - 1);
+            final boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
+            switch (lastChar) {
+                case 'l' :
+                case 'L' :
+                    if (dec == null
+                        && exp == null
+                        && (numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) {
+                        try {
+                            return createLong(numeric);
+                        } catch (final NumberFormatException nfe) { // NOPMD
+                            // Too big for a long
+                        }
+                        return createBigInteger(numeric);
+
+                    }
+                    throw new NumberFormatException(str + " is not a valid number.");
+                case 'f' :
+                case 'F' :
+                    try {
+                        final Float f = NumberUtils.createFloat(numeric);
+                        if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
+                            //If it's too big for a float or the float value = 0 and the string
+                            //has non-zeros in it, then float does not have the precision we want
+                            return f;
+                        }
+
+                    } catch (final NumberFormatException nfe) { // NOPMD
+                        // ignore the bad number
+                    }
+                    //$FALL-THROUGH$
+                case 'd' :
+                case 'D' :
+                    try {
+                        final Double d = NumberUtils.createDouble(numeric);
+                        if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) {
+                            return d;
+                        }
+                    } catch (final NumberFormatException nfe) { // NOPMD
+                        // ignore the bad number
+                    }
+                    try {
+                        return createBigDecimal(numeric);
+                    } catch (final NumberFormatException e) { // NOPMD
+                        // ignore the bad number
+                    }
+                    //$FALL-THROUGH$
+                default :
+                    throw new NumberFormatException(str + " is not a valid number.");
+
+            }
+        }
+        //User doesn't have a preference on the return type, so let's start
+        //small and go from there...
+        if (expPos > -1 && expPos < str.length() - 1) {
+            exp = str.substring(expPos + 1, str.length());
+        } else {
+            exp = null;
+        }
+        if (dec == null && exp == null) { // no decimal point and no exponent
+            //Must be an Integer, Long, Biginteger
+            try {
+                return createInteger(str);
+            } catch (final NumberFormatException nfe) { // NOPMD
+                // ignore the bad number
+            }
+            try {
+                return createLong(str);
+            } catch (final NumberFormatException nfe) { // NOPMD
+                // ignore the bad number
+            }
+            return createBigInteger(str);
+        }
+
+        //Must be a Float, Double, BigDecimal
+        final boolean allZeros = isAllZeros(mant) && isAllZeros(exp);
+        try {
+            if(numDecimals <= 7){// If number has 7 or fewer digits past the decimal point then make it a float
+                final Float f = createFloat(str);
+                if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) {
+                    return f;
+                }
+            }
+        } catch (final NumberFormatException nfe) { // NOPMD
+            // ignore the bad number
+        }
+        try {
+            if(numDecimals <= 16){// If number has between 8 and 16 digits past the decimal point then make it a double
+                final Double d = createDouble(str);
+                if (!(d.isInfinite() || (d.doubleValue() == 0.0D && !allZeros))) {
+                    return d;
+                }
+            }
+        } catch (final NumberFormatException nfe) { // NOPMD
+            // ignore the bad number
+        }
+
+        return createBigDecimal(str);
+    }
+
+    /**
+     * <p>Utility method for {@link #createNumber(java.lang.String)}.</p>
+     *
+     * <p>Returns mantissa of the given number.</p>
+     * 
+     * @param str the string representation of the number
+     * @return mantissa of the given number
+     */
+    private static String getMantissa(final String str) {
+        return getMantissa(str, str.length());
+    }
+
+    /**
+     * <p>Utility method for {@link #createNumber(java.lang.String)}.</p>
+     *
+     * <p>Returns mantissa of the given number.</p>
+     * 
+     * @param str the string representation of the number
+     * @param stopPos the position of the exponent or decimal point
+     * @return mantissa of the given number
+     */
+    private static String getMantissa(final String str, final int stopPos) {
+        final char firstChar = str.charAt(0);
+        final boolean hasSign = (firstChar == '-' || firstChar == '+');
+
+        return hasSign ? str.substring(1, stopPos) : str.substring(0, stopPos);
+    }
+
+    /**
+     * <p>Utility method for {@link #createNumber(java.lang.String)}.</p>
+     *
+     * <p>Returns <code>true</code> if s is <code>null</code>.</p>
+     * 
+     * @param str  the String to check
+     * @return if it is all zeros or <code>null</code>
+     */
+    private static boolean isAllZeros(final String str) {
+        if (str == null) {
+            return true;
+        }
+        for (int i = str.length() - 1; i >= 0; i--) {
+            if (str.charAt(i) != '0') {
+                return false;
+            }
+        }
+        return str.length() > 0;
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Convert a <code>String</code> to a <code>Float</code>.</p>
+     *
+     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
+     * 
+     * @param str  a <code>String</code> to convert, may be null
+     * @return converted <code>Float</code> (or null if the input is null)
+     * @throws NumberFormatException if the value cannot be converted
+     */
+    public static Float createFloat(final String str) {
+        if (str == null) {
+            return null;
+        }
+        return Float.valueOf(str);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>Double</code>.</p>
+     * 
+     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
+     *
+     * @param str  a <code>String</code> to convert, may be null
+     * @return converted <code>Double</code> (or null if the input is null)
+     * @throws NumberFormatException if the value cannot be converted
+     */
+    public static Double createDouble(final String str) {
+        if (str == null) {
+            return null;
+        }
+        return Double.valueOf(str);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>Integer</code>, handling
+     * hex (0xhhhh) and octal (0dddd) notations.
+     * N.B. a leading zero means octal; spaces are not trimmed.</p>
+     *
+     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
+     * 
+     * @param str  a <code>String</code> to convert, may be null
+     * @return converted <code>Integer</code> (or null if the input is null)
+     * @throws NumberFormatException if the value cannot be converted
+     */
+    public static Integer createInteger(final String str) {
+        if (str == null) {
+            return null;
+        }
+        // decode() handles 0xAABD and 0777 (hex and octal) as well.
+        return Integer.decode(str);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>Long</code>; 
+     * since 3.1 it handles hex (0Xhhhh) and octal (0ddd) notations.
+     * N.B. a leading zero means octal; spaces are not trimmed.</p>
+     * 
+     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
+     *
+     * @param str  a <code>String</code> to convert, may be null
+     * @return converted <code>Long</code> (or null if the input is null)
+     * @throws NumberFormatException if the value cannot be converted
+     */
+    public static Long createLong(final String str) {
+        if (str == null) {
+            return null;
+        }
+        return Long.decode(str);
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>BigInteger</code>;
+     * since 3.2 it handles hex (0x or #) and octal (0) notations.</p>
+     *
+     * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
+     * 
+     * @param str  a <code>String</code> to convert, may be null
+     * @return converted <code>BigInteger</code> (or null if the input is null)
+     * @throws NumberFormatException if the value cannot be converted
+     */
+    public static BigInteger createBigInteger(final String str) {
+        if (str == null) {
+            return null;
+        }
+        int pos = 0; // offset within string
+        int radix = 10;
+        boolean negate = false; // need to negate later?
+        if (str.startsWith("-")) {
+            negate = true;
+            pos = 1;
+        }
+        if (str.startsWith("0x", pos) || str.startsWith("0X", pos)) { // hex
+            radix = 16;
+            pos += 2;
+        } else if (str.startsWith("#", pos)) { // alternative hex (allowed by Long/Integer)
+            radix = 16;
+            pos ++;
+        } else if (str.startsWith("0", pos) && str.length() > pos + 1) { // octal; so long as there are additional digits
+            radix = 8;
+            pos ++;
+        } // default is to treat as decimal
+
+        final BigInteger value = new BigInteger(str.substring(pos), radix);
+        return negate ? value.negate() : value;
+    }
+
+    /**
+     * <p>Convert a <code>String</code> to a <code>BigDecimal</code>.</p>
+     * 
+     * <p>Returns <

<TRUNCATED>

[3/5] [lang] newline pain, despite having run the config line

Posted by ba...@apache.org.
newline pain, despite having run the config line


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

Branch: refs/heads/master
Commit: 56e52fe4cbf5d3ce8fbbad9fa1cc4739e2915ce0
Parents: e55aaa5
Author: Hen <he...@flamefew.com>
Authored: Thu Feb 25 21:15:13 2016 -0800
Committer: Hen <he...@flamefew.com>
Committed: Thu Feb 25 21:15:13 2016 -0800

----------------------------------------------------------------------
 .../org/apache/commons/lang3/ThreadUtils.java   |  920 ++---
 .../apache/commons/lang3/math/NumberUtils.java  | 3160 +++++++++---------
 2 files changed, 2040 insertions(+), 2040 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/56e52fe4/src/main/java/org/apache/commons/lang3/ThreadUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/ThreadUtils.java b/src/main/java/org/apache/commons/lang3/ThreadUtils.java
index 15f0c5c..89a59ce 100644
--- a/src/main/java/org/apache/commons/lang3/ThreadUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ThreadUtils.java
@@ -1,460 +1,460 @@
-/*
- * 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.lang3;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * <p>
- * Helpers for {@code java.lang.Thread} and {@code java.lang.ThreadGroup}.
- * </p>
- * <p>
- * #ThreadSafe#
- * </p>
- *
- * @see java.lang.Thread
- * @see java.lang.ThreadGroup
- * @since 3.5
- */
-public class ThreadUtils {
-
-    /**
-     * Return the active thread with the specified id if it belong's to the specified thread group.
-     *
-     * @param threadId The thread id
-     * @param threadGroup The thread group
-     * @return The thread which belongs to a specified thread group and the thread's id match the specified id.
-     * {@code null} is returned if no such thread exists
-     * @throws IllegalArgumentException if the specified id is zero or negative or the group is null
-     * @throws  SecurityException
-     *          if the current thread cannot access the system thread group
-     *
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static Thread findThreadById(final long threadId, final ThreadGroup threadGroup) {
-        if (threadGroup == null) {
-            throw new IllegalArgumentException("The thread group must not be null");
-        }
-        final Thread thread = findThreadById(threadId);
-        if(thread != null && threadGroup.equals(thread.getThreadGroup())) {
-            return thread;
-        }
-        return null;
-    }
-
-    /**
-     * Return the active thread with the specified id if it belong's to a thread group with the specified group name.
-     *
-     * @param threadId The thread id
-     * @param threadGroupName The thread group name
-     * @return The threads which belongs to a thread group with the specified group name and the thread's id match the specified id.
-     * {@code null} is returned if no such thread exists
-     * @throws IllegalArgumentException if the specified id is zero or negative or the group name is null
-     * @throws  SecurityException
-     *          if the current thread cannot access the system thread group
-     *
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static Thread findThreadById(final long threadId, final String threadGroupName) {
-        if (threadGroupName == null) {
-            throw new IllegalArgumentException("The thread group name must not be null");
-        }
-        final Thread thread = findThreadById(threadId);
-        if(thread != null && thread.getThreadGroup() != null && thread.getThreadGroup().getName().equals(threadGroupName)) {
-            return thread;
-        }
-        return null;
-    }
-
-    /**
-     * Return active threads with the specified name if they belong to a specified thread group.
-     *
-     * @param threadName The thread name
-     * @param threadGroup The thread group
-     * @return The threads which belongs to a thread group and the thread's name match the specified name,
-     * An empty collection is returned if no such thread exists. The collection returned is always unmodifiable.
-     * @throws IllegalArgumentException if the specified thread name or group is null
-     * @throws  SecurityException
-     *          if the current thread cannot access the system thread group
-     *
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static Collection<Thread> findThreadsByName(final String threadName, final ThreadGroup threadGroup) {
-        return findThreads(threadGroup, false, new NamePredicate(threadName));
-    }
-
-    /**
-     * Return active threads with the specified name if they belong to a thread group with the specified group name.
-     *
-     * @param threadName The thread name
-     * @param threadGroupName The thread group name
-     * @return The threads which belongs to a thread group with the specified group name and the thread's name match the specified name,
-     * An empty collection is returned if no such thread exists. The collection returned is always unmodifiable.
-     * @throws IllegalArgumentException if the specified thread name or group name is null
-     * @throws  SecurityException
-     *          if the current thread cannot access the system thread group
-     *
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static Collection<Thread> findThreadsByName(final String threadName, final String threadGroupName) {
-        if (threadName == null) {
-            throw new IllegalArgumentException("The thread name must not be null");
-        }
-        if (threadGroupName == null) {
-            throw new IllegalArgumentException("The thread group name must not be null");
-        }
-
-        final Collection<ThreadGroup> threadGroups = findThreadGroups(new NamePredicate(threadGroupName));
-
-        if(threadGroups.isEmpty()) {
-            return Collections.emptyList();
-        }
-
-        final Collection<Thread> result = new ArrayList<Thread>();
-        final NamePredicate threadNamePredicate = new NamePredicate(threadName);
-        for(final ThreadGroup group : threadGroups) {
-            result.addAll(findThreads(group, false, threadNamePredicate));
-        }
-        return Collections.unmodifiableCollection(result);
-    }
-
-    /**
-     * Return active thread groups with the specified group name.
-     *
-     * @param threadGroupName The thread group name
-     * @return the thread groups with the specified group name or an empty collection if no such thread group exists. The collection returned is always unmodifiable.
-     * @throws IllegalArgumentException if group name is null
-     * @throws  SecurityException
-     *          if the current thread cannot access the system thread group
-     *
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static Collection<ThreadGroup> findThreadGroupsByName(final String threadGroupName) {
-        return findThreadGroups(new NamePredicate(threadGroupName));
-    }
-
-    /**
-     * Return all active thread groups excluding the system thread group (A thread group is active if it has been not destroyed).
-     *
-     * @return all thread groups excluding the system thread group. The collection returned is always unmodifiable.
-     * @throws  SecurityException
-     *          if the current thread cannot access the system thread group
-     *
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static Collection<ThreadGroup> getAllThreadGroups() {
-        return findThreadGroups(ALWAYS_TRUE_PREDICATE);
-    }
-
-    /**
-     * Return the system thread group (sometimes also referred as "root thread group").
-     *
-     * @return the system thread group
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static ThreadGroup getSystemThreadGroup() {
-        ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
-        while(threadGroup.getParent() != null) {
-            threadGroup = threadGroup.getParent();
-        }
-        return threadGroup;
-    }
-
-    /**
-     * Return all active threads (A thread is active if it has been started and has not yet died).
-     *
-     * @return all active threads. The collection returned is always unmodifiable.
-     * @throws  SecurityException
-     *          if the current thread cannot access the system thread group
-     *
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static Collection<Thread> getAllThreads() {
-        return findThreads(ALWAYS_TRUE_PREDICATE);
-    }
-
-    /**
-     * Return active threads with the specified name.
-     *
-     * @param threadName The thread name
-     * @return The threads with the specified name or an empty collection if no such thread exists. The collection returned is always unmodifiable.
-     * @throws IllegalArgumentException if the specified name is null
-     * @throws  SecurityException
-     *          if the current thread cannot access the system thread group
-     *
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static Collection<Thread> findThreadsByName(final String threadName) {
-        return findThreads(new NamePredicate(threadName));
-    }
-
-    /**
-     * Return the active thread with the specified id.
-     *
-     * @param threadId The thread id
-     * @return The thread with the specified id or {@code null} if no such thread exists
-     * @throws IllegalArgumentException if the specified id is zero or negative
-     * @throws  SecurityException
-     *          if the current thread cannot access the system thread group
-     *
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static Thread findThreadById(final long threadId) {
-        final Collection<Thread> result = findThreads(new ThreadIdPredicate(threadId));
-        return result.isEmpty() ? null : result.iterator().next();
-    }
-
-    /**
-     * <p>
-     * ThreadUtils instances should NOT be constructed in standard programming. Instead, the class should be used as
-     * {@code ThreadUtils.getAllThreads()}
-     * </p>
-     * <p>
-     * This constructor is public to permit tools that require a JavaBean instance to operate.
-     * </p>
-     */
-    public ThreadUtils() {
-        super();
-    }
-
-    /**
-     * A predicate for selecting threads.
-     */
-    //if java minimal version for lang becomes 1.8 extend this interface from java.util.function.Predicate
-    public interface ThreadPredicate /*extends java.util.function.Predicate<Thread>*/{
-
-        /**
-         * Evaluates this predicate on the given thread.
-         * @param thread the thread
-         * @return {@code true} if the thread matches the predicate, otherwise {@code false}
-         */
-        boolean test(Thread thread);
-    }
-
-    /**
-     * A predicate for selecting threadgroups.
-     */
-    //if java minimal version for lang becomes 1.8 extend this interface from java.util.function.Predicate
-    public interface ThreadGroupPredicate /*extends java.util.function.Predicate<ThreadGroup>*/{
-
-        /**
-         * Evaluates this predicate on the given threadgroup.
-         * @param threadGroup the threadgroup
-         * @return {@code true} if the threadGroup matches the predicate, otherwise {@code false}
-         */
-        boolean test(ThreadGroup threadGroup);
-    }
-
-    /**
-     * Predicate which always returns true.
-     */
-    public static final AlwaysTruePredicate ALWAYS_TRUE_PREDICATE = new AlwaysTruePredicate();
-
-    /**
-     * A predicate implementation which always returns true.
-     */
-    private final static class AlwaysTruePredicate implements ThreadPredicate, ThreadGroupPredicate{
-
-        private AlwaysTruePredicate() {
-        }
-
-        @Override
-        public boolean test(final ThreadGroup threadGroup) {
-            return true;
-        }
-
-        @Override
-        public boolean test(final Thread thread) {
-            return true;
-        }
-    }
-
-    /**
-     * A predicate implementation which matches a thread or threadgroup name.
-     */
-    public static class NamePredicate implements ThreadPredicate, ThreadGroupPredicate {
-
-        private final String name;
-
-        /**
-         * Predicate constructor
-         *
-         * @param name thread or threadgroup name
-         * @throws IllegalArgumentException if the name is {@code null}
-         */
-        public NamePredicate(final String name) {
-            super();
-            if (name == null) {
-                throw new IllegalArgumentException("The name must not be null");
-            }
-            this.name = name;
-        }
-
-        @Override
-        public boolean test(final ThreadGroup threadGroup) {
-            return threadGroup != null && threadGroup.getName().equals(name);
-        }
-
-        @Override
-        public boolean test(final Thread thread) {
-            return thread != null && thread.getName().equals(name);
-        }
-    }
-
-    /**
-     * A predicate implementation which matches a thread id.
-     */
-    public static class ThreadIdPredicate implements ThreadPredicate {
-
-        private final long threadId;
-
-        /**
-         * Predicate constructor
-         *
-         * @param threadId the threadId to match
-         * @throws IllegalArgumentException if the threadId is zero or negative
-         */
-        public ThreadIdPredicate(final long threadId) {
-            super();
-            if (threadId <= 0) {
-                throw new IllegalArgumentException("The thread id must be greater than zero");
-            }
-            this.threadId = threadId;
-        }
-
-        @Override
-        public boolean test(final Thread thread) {
-            return thread != null && thread.getId() == threadId;
-        }
-    }
-
-    /**
-     * Select all active threads which match the given predicate.
-     *
-     * @param predicate the predicate
-     * @return An unmodifiable {@code Collection} of active threads matching the given predicate
-     *
-     * @throws IllegalArgumentException if the predicate is null
-     * @throws  SecurityException
-     *          if the current thread cannot access the system thread group
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static Collection<Thread> findThreads(final ThreadPredicate predicate){
-        return findThreads(getSystemThreadGroup(), true, predicate);
-    }
-
-    /**
-     * Select all active threadgroups which match the given predicate.
-     *
-     * @param predicate the predicate
-     * @return An unmodifiable {@code Collection} of active threadgroups matching the given predicate
-     * @throws IllegalArgumentException if the predicate is null
-     * @throws  SecurityException
-     *          if the current thread cannot access the system thread group
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static Collection<ThreadGroup> findThreadGroups(final ThreadGroupPredicate predicate){
-        return findThreadGroups(getSystemThreadGroup(), true, predicate);
-    }
-
-    /**
-     * Select all active threads which match the given predicate and which belongs to the given thread group (or one of its subgroups).
-     *
-     * @param group the thread group
-     * @param recurse if {@code true} then evaluate the predicate recursively on all threads in all subgroups of the given group
-     * @param predicate the predicate
-     * @return An unmodifiable {@code Collection} of active threads which match the given predicate and which belongs to the given thread group
-     * @throws IllegalArgumentException if the given group or predicate is null
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static Collection<Thread> findThreads(final ThreadGroup group, final boolean recurse, final ThreadPredicate predicate) {
-        if (group == null) {
-            throw new IllegalArgumentException("The group must not be null");
-        }
-        if (predicate == null) {
-            throw new IllegalArgumentException("The predicate must not be null");
-        }
-
-        int count = group.activeCount();
-        Thread[] threads;
-        do {
-            threads = new Thread[count + (count / 2) + 1]; //slightly grow the array size
-            count = group.enumerate(threads, recurse);
-            //return value of enumerate() must be strictly less than the array size according to javadoc
-        } while (count >= threads.length);
-
-        final List<Thread> result = new ArrayList<Thread>(count);
-        for (int i = 0; i < count; ++i) {
-            if (predicate.test(threads[i])) {
-                result.add(threads[i]);
-            }
-        }
-        return Collections.unmodifiableCollection(result);
-    }
-
-    /**
-     * Select all active threadgroups which match the given predicate and which is a subgroup of the given thread group (or one of its subgroups).
-     *
-     * @param group the thread group
-     * @param recurse if {@code true} then evaluate the predicate recursively on all threadgroups in all subgroups of the given group
-     * @param predicate the predicate
-     * @return An unmodifiable {@code Collection} of active threadgroups which match the given predicate and which is a subgroup of the given thread group
-     * @throws IllegalArgumentException if the given group or predicate is null
-     * @throws  SecurityException  if the current thread cannot modify
-     *          thread groups from this thread's thread group up to the system thread group
-     */
-    public static Collection<ThreadGroup> findThreadGroups(final ThreadGroup group, final boolean recurse, final ThreadGroupPredicate predicate){
-        if (group == null) {
-            throw new IllegalArgumentException("The group must not be null");
-        }
-        if (predicate == null) {
-            throw new IllegalArgumentException("The predicate must not be null");
-        }
-
-        int count = group.activeGroupCount();
-        ThreadGroup[] threadGroups;
-        do {
-            threadGroups = new ThreadGroup[count + (count / 2) + 1]; //slightly grow the array size
-            count = group.enumerate(threadGroups, recurse);
-            //return value of enumerate() must be strictly less than the array size according to javadoc
-        } while(count >= threadGroups.length);
-
-        final List<ThreadGroup> result = new ArrayList<ThreadGroup>(count);
-        for(int i = 0; i < count; ++i) {
-            if(predicate.test(threadGroups[i])) {
-                result.add(threadGroups[i]);
-            }
-        }
-        return Collections.unmodifiableCollection(result);
-    }
-}
+/*
+ * 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.lang3;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * <p>
+ * Helpers for {@code java.lang.Thread} and {@code java.lang.ThreadGroup}.
+ * </p>
+ * <p>
+ * #ThreadSafe#
+ * </p>
+ *
+ * @see java.lang.Thread
+ * @see java.lang.ThreadGroup
+ * @since 3.5
+ */
+public class ThreadUtils {
+
+    /**
+     * Return the active thread with the specified id if it belong's to the specified thread group.
+     *
+     * @param threadId The thread id
+     * @param threadGroup The thread group
+     * @return The thread which belongs to a specified thread group and the thread's id match the specified id.
+     * {@code null} is returned if no such thread exists
+     * @throws IllegalArgumentException if the specified id is zero or negative or the group is null
+     * @throws  SecurityException
+     *          if the current thread cannot access the system thread group
+     *
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static Thread findThreadById(final long threadId, final ThreadGroup threadGroup) {
+        if (threadGroup == null) {
+            throw new IllegalArgumentException("The thread group must not be null");
+        }
+        final Thread thread = findThreadById(threadId);
+        if(thread != null && threadGroup.equals(thread.getThreadGroup())) {
+            return thread;
+        }
+        return null;
+    }
+
+    /**
+     * Return the active thread with the specified id if it belong's to a thread group with the specified group name.
+     *
+     * @param threadId The thread id
+     * @param threadGroupName The thread group name
+     * @return The threads which belongs to a thread group with the specified group name and the thread's id match the specified id.
+     * {@code null} is returned if no such thread exists
+     * @throws IllegalArgumentException if the specified id is zero or negative or the group name is null
+     * @throws  SecurityException
+     *          if the current thread cannot access the system thread group
+     *
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static Thread findThreadById(final long threadId, final String threadGroupName) {
+        if (threadGroupName == null) {
+            throw new IllegalArgumentException("The thread group name must not be null");
+        }
+        final Thread thread = findThreadById(threadId);
+        if(thread != null && thread.getThreadGroup() != null && thread.getThreadGroup().getName().equals(threadGroupName)) {
+            return thread;
+        }
+        return null;
+    }
+
+    /**
+     * Return active threads with the specified name if they belong to a specified thread group.
+     *
+     * @param threadName The thread name
+     * @param threadGroup The thread group
+     * @return The threads which belongs to a thread group and the thread's name match the specified name,
+     * An empty collection is returned if no such thread exists. The collection returned is always unmodifiable.
+     * @throws IllegalArgumentException if the specified thread name or group is null
+     * @throws  SecurityException
+     *          if the current thread cannot access the system thread group
+     *
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static Collection<Thread> findThreadsByName(final String threadName, final ThreadGroup threadGroup) {
+        return findThreads(threadGroup, false, new NamePredicate(threadName));
+    }
+
+    /**
+     * Return active threads with the specified name if they belong to a thread group with the specified group name.
+     *
+     * @param threadName The thread name
+     * @param threadGroupName The thread group name
+     * @return The threads which belongs to a thread group with the specified group name and the thread's name match the specified name,
+     * An empty collection is returned if no such thread exists. The collection returned is always unmodifiable.
+     * @throws IllegalArgumentException if the specified thread name or group name is null
+     * @throws  SecurityException
+     *          if the current thread cannot access the system thread group
+     *
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static Collection<Thread> findThreadsByName(final String threadName, final String threadGroupName) {
+        if (threadName == null) {
+            throw new IllegalArgumentException("The thread name must not be null");
+        }
+        if (threadGroupName == null) {
+            throw new IllegalArgumentException("The thread group name must not be null");
+        }
+
+        final Collection<ThreadGroup> threadGroups = findThreadGroups(new NamePredicate(threadGroupName));
+
+        if(threadGroups.isEmpty()) {
+            return Collections.emptyList();
+        }
+
+        final Collection<Thread> result = new ArrayList<Thread>();
+        final NamePredicate threadNamePredicate = new NamePredicate(threadName);
+        for(final ThreadGroup group : threadGroups) {
+            result.addAll(findThreads(group, false, threadNamePredicate));
+        }
+        return Collections.unmodifiableCollection(result);
+    }
+
+    /**
+     * Return active thread groups with the specified group name.
+     *
+     * @param threadGroupName The thread group name
+     * @return the thread groups with the specified group name or an empty collection if no such thread group exists. The collection returned is always unmodifiable.
+     * @throws IllegalArgumentException if group name is null
+     * @throws  SecurityException
+     *          if the current thread cannot access the system thread group
+     *
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static Collection<ThreadGroup> findThreadGroupsByName(final String threadGroupName) {
+        return findThreadGroups(new NamePredicate(threadGroupName));
+    }
+
+    /**
+     * Return all active thread groups excluding the system thread group (A thread group is active if it has been not destroyed).
+     *
+     * @return all thread groups excluding the system thread group. The collection returned is always unmodifiable.
+     * @throws  SecurityException
+     *          if the current thread cannot access the system thread group
+     *
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static Collection<ThreadGroup> getAllThreadGroups() {
+        return findThreadGroups(ALWAYS_TRUE_PREDICATE);
+    }
+
+    /**
+     * Return the system thread group (sometimes also referred as "root thread group").
+     *
+     * @return the system thread group
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static ThreadGroup getSystemThreadGroup() {
+        ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
+        while(threadGroup.getParent() != null) {
+            threadGroup = threadGroup.getParent();
+        }
+        return threadGroup;
+    }
+
+    /**
+     * Return all active threads (A thread is active if it has been started and has not yet died).
+     *
+     * @return all active threads. The collection returned is always unmodifiable.
+     * @throws  SecurityException
+     *          if the current thread cannot access the system thread group
+     *
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static Collection<Thread> getAllThreads() {
+        return findThreads(ALWAYS_TRUE_PREDICATE);
+    }
+
+    /**
+     * Return active threads with the specified name.
+     *
+     * @param threadName The thread name
+     * @return The threads with the specified name or an empty collection if no such thread exists. The collection returned is always unmodifiable.
+     * @throws IllegalArgumentException if the specified name is null
+     * @throws  SecurityException
+     *          if the current thread cannot access the system thread group
+     *
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static Collection<Thread> findThreadsByName(final String threadName) {
+        return findThreads(new NamePredicate(threadName));
+    }
+
+    /**
+     * Return the active thread with the specified id.
+     *
+     * @param threadId The thread id
+     * @return The thread with the specified id or {@code null} if no such thread exists
+     * @throws IllegalArgumentException if the specified id is zero or negative
+     * @throws  SecurityException
+     *          if the current thread cannot access the system thread group
+     *
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static Thread findThreadById(final long threadId) {
+        final Collection<Thread> result = findThreads(new ThreadIdPredicate(threadId));
+        return result.isEmpty() ? null : result.iterator().next();
+    }
+
+    /**
+     * <p>
+     * ThreadUtils instances should NOT be constructed in standard programming. Instead, the class should be used as
+     * {@code ThreadUtils.getAllThreads()}
+     * </p>
+     * <p>
+     * This constructor is public to permit tools that require a JavaBean instance to operate.
+     * </p>
+     */
+    public ThreadUtils() {
+        super();
+    }
+
+    /**
+     * A predicate for selecting threads.
+     */
+    //if java minimal version for lang becomes 1.8 extend this interface from java.util.function.Predicate
+    public interface ThreadPredicate /*extends java.util.function.Predicate<Thread>*/{
+
+        /**
+         * Evaluates this predicate on the given thread.
+         * @param thread the thread
+         * @return {@code true} if the thread matches the predicate, otherwise {@code false}
+         */
+        boolean test(Thread thread);
+    }
+
+    /**
+     * A predicate for selecting threadgroups.
+     */
+    //if java minimal version for lang becomes 1.8 extend this interface from java.util.function.Predicate
+    public interface ThreadGroupPredicate /*extends java.util.function.Predicate<ThreadGroup>*/{
+
+        /**
+         * Evaluates this predicate on the given threadgroup.
+         * @param threadGroup the threadgroup
+         * @return {@code true} if the threadGroup matches the predicate, otherwise {@code false}
+         */
+        boolean test(ThreadGroup threadGroup);
+    }
+
+    /**
+     * Predicate which always returns true.
+     */
+    public static final AlwaysTruePredicate ALWAYS_TRUE_PREDICATE = new AlwaysTruePredicate();
+
+    /**
+     * A predicate implementation which always returns true.
+     */
+    private final static class AlwaysTruePredicate implements ThreadPredicate, ThreadGroupPredicate{
+
+        private AlwaysTruePredicate() {
+        }
+
+        @Override
+        public boolean test(final ThreadGroup threadGroup) {
+            return true;
+        }
+
+        @Override
+        public boolean test(final Thread thread) {
+            return true;
+        }
+    }
+
+    /**
+     * A predicate implementation which matches a thread or threadgroup name.
+     */
+    public static class NamePredicate implements ThreadPredicate, ThreadGroupPredicate {
+
+        private final String name;
+
+        /**
+         * Predicate constructor
+         *
+         * @param name thread or threadgroup name
+         * @throws IllegalArgumentException if the name is {@code null}
+         */
+        public NamePredicate(final String name) {
+            super();
+            if (name == null) {
+                throw new IllegalArgumentException("The name must not be null");
+            }
+            this.name = name;
+        }
+
+        @Override
+        public boolean test(final ThreadGroup threadGroup) {
+            return threadGroup != null && threadGroup.getName().equals(name);
+        }
+
+        @Override
+        public boolean test(final Thread thread) {
+            return thread != null && thread.getName().equals(name);
+        }
+    }
+
+    /**
+     * A predicate implementation which matches a thread id.
+     */
+    public static class ThreadIdPredicate implements ThreadPredicate {
+
+        private final long threadId;
+
+        /**
+         * Predicate constructor
+         *
+         * @param threadId the threadId to match
+         * @throws IllegalArgumentException if the threadId is zero or negative
+         */
+        public ThreadIdPredicate(final long threadId) {
+            super();
+            if (threadId <= 0) {
+                throw new IllegalArgumentException("The thread id must be greater than zero");
+            }
+            this.threadId = threadId;
+        }
+
+        @Override
+        public boolean test(final Thread thread) {
+            return thread != null && thread.getId() == threadId;
+        }
+    }
+
+    /**
+     * Select all active threads which match the given predicate.
+     *
+     * @param predicate the predicate
+     * @return An unmodifiable {@code Collection} of active threads matching the given predicate
+     *
+     * @throws IllegalArgumentException if the predicate is null
+     * @throws  SecurityException
+     *          if the current thread cannot access the system thread group
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static Collection<Thread> findThreads(final ThreadPredicate predicate){
+        return findThreads(getSystemThreadGroup(), true, predicate);
+    }
+
+    /**
+     * Select all active threadgroups which match the given predicate.
+     *
+     * @param predicate the predicate
+     * @return An unmodifiable {@code Collection} of active threadgroups matching the given predicate
+     * @throws IllegalArgumentException if the predicate is null
+     * @throws  SecurityException
+     *          if the current thread cannot access the system thread group
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static Collection<ThreadGroup> findThreadGroups(final ThreadGroupPredicate predicate){
+        return findThreadGroups(getSystemThreadGroup(), true, predicate);
+    }
+
+    /**
+     * Select all active threads which match the given predicate and which belongs to the given thread group (or one of its subgroups).
+     *
+     * @param group the thread group
+     * @param recurse if {@code true} then evaluate the predicate recursively on all threads in all subgroups of the given group
+     * @param predicate the predicate
+     * @return An unmodifiable {@code Collection} of active threads which match the given predicate and which belongs to the given thread group
+     * @throws IllegalArgumentException if the given group or predicate is null
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static Collection<Thread> findThreads(final ThreadGroup group, final boolean recurse, final ThreadPredicate predicate) {
+        if (group == null) {
+            throw new IllegalArgumentException("The group must not be null");
+        }
+        if (predicate == null) {
+            throw new IllegalArgumentException("The predicate must not be null");
+        }
+
+        int count = group.activeCount();
+        Thread[] threads;
+        do {
+            threads = new Thread[count + (count / 2) + 1]; //slightly grow the array size
+            count = group.enumerate(threads, recurse);
+            //return value of enumerate() must be strictly less than the array size according to javadoc
+        } while (count >= threads.length);
+
+        final List<Thread> result = new ArrayList<Thread>(count);
+        for (int i = 0; i < count; ++i) {
+            if (predicate.test(threads[i])) {
+                result.add(threads[i]);
+            }
+        }
+        return Collections.unmodifiableCollection(result);
+    }
+
+    /**
+     * Select all active threadgroups which match the given predicate and which is a subgroup of the given thread group (or one of its subgroups).
+     *
+     * @param group the thread group
+     * @param recurse if {@code true} then evaluate the predicate recursively on all threadgroups in all subgroups of the given group
+     * @param predicate the predicate
+     * @return An unmodifiable {@code Collection} of active threadgroups which match the given predicate and which is a subgroup of the given thread group
+     * @throws IllegalArgumentException if the given group or predicate is null
+     * @throws  SecurityException  if the current thread cannot modify
+     *          thread groups from this thread's thread group up to the system thread group
+     */
+    public static Collection<ThreadGroup> findThreadGroups(final ThreadGroup group, final boolean recurse, final ThreadGroupPredicate predicate){
+        if (group == null) {
+            throw new IllegalArgumentException("The group must not be null");
+        }
+        if (predicate == null) {
+            throw new IllegalArgumentException("The predicate must not be null");
+        }
+
+        int count = group.activeGroupCount();
+        ThreadGroup[] threadGroups;
+        do {
+            threadGroups = new ThreadGroup[count + (count / 2) + 1]; //slightly grow the array size
+            count = group.enumerate(threadGroups, recurse);
+            //return value of enumerate() must be strictly less than the array size according to javadoc
+        } while(count >= threadGroups.length);
+
+        final List<ThreadGroup> result = new ArrayList<ThreadGroup>(count);
+        for(int i = 0; i < count; ++i) {
+            if(predicate.test(threadGroups[i])) {
+                result.add(threadGroups[i]);
+            }
+        }
+        return Collections.unmodifiableCollection(result);
+    }
+}