commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benedikt Ritter <brit...@apache.org>
Subject Re: [lang] LANG-1289" type="fix" dev="ggregory">JavaVersion class depends on Apache Commons Math class NumberUtils.
Date Fri, 18 Nov 2016 21:29:58 GMT
Hello Gary,

I don't understand this change. The NumberUtils import you removed was from
lang itself. Doesn't this change introduce code duplication within Lang?

Benedikt

<ggregory@apache.org> schrieb am Fr. 18. Nov. 2016 um 21:30:

> Repository: commons-lang
> Updated Branches:
>   refs/heads/master 429c847b2 -> 9dcd87f9c
>
>
> LANG-1289" type="fix" dev="ggregory">JavaVersion class depends on Apache
> Commons Math class NumberUtils.
>
> Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
> Commit:
> http://git-wip-us.apache.org/repos/asf/commons-lang/commit/9dcd87f9
> Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/9dcd87f9
> Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/9dcd87f9
>
> Branch: refs/heads/master
> Commit: 9dcd87f9c46786f3da54af7ac1ba4696840dffa8
> Parents: 429c847
> Author: Gary Gregory <ggregory@apache.org>
> Authored: Fri Nov 18 12:30:22 2016 -0800
> Committer: Gary Gregory <ggregory@apache.org>
> Committed: Fri Nov 18 12:30:22 2016 -0800
>
> ----------------------------------------------------------------------
>  src/changes/changes.xml                         |  1 +
>  .../org/apache/commons/lang3/JavaVersion.java   | 40 ++++++++++++++++++--
>  2 files changed, 37 insertions(+), 4 deletions(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/commons-lang/blob/9dcd87f9/src/changes/changes.xml
> ----------------------------------------------------------------------
> diff --git a/src/changes/changes.xml b/src/changes/changes.xml
> index 63a94a3..092d4c5 100644
> --- a/src/changes/changes.xml
> +++ b/src/changes/changes.xml
> @@ -57,6 +57,7 @@ The <action> type attribute can be add,update,fix,remove.
>      <action issue="LANG-1070" type="fix" dev="pschumacher" due-to="Paul
> Pogonyshev">ArrayUtils#add confusing example in javadoc</action>
>      <action issue="LANG-1271" type="fix" dev="pschumacher" due-to="Pierre
> Templier">StringUtils#isAnyEmpty and #isAnyBlank should return false for an
> empty array</action>
>      <action issue="LANG-1155" type="fix" dev="pschumacher" due-to="Saif
> Asif, Thiago Andrade">Add StringUtils#unwrap</action>
> +    <action issue="LANG-1289" type="fix" dev="ggregory">JavaVersion class
> depends on Apache Commons Math class NumberUtils</action>
>      <action issue="LANG-1034" type="add" dev="pschumacher" due-to="Yathos
> UG">Add support for recursive comparison to
> EqualsBuilder#reflectionEquals</action>
>      <action issue="LANG-740" type="add" dev="pschumacher" due-to="James
> Sawle">Implementation of a Memomizer</action>
>      <action issue="LANG-1258" type="add" dev="pschumacher" due-to="IG,
> Grzegorz Ro┼╝niecki">Add ArrayUtils#toStringArray method</action>
>
>
> http://git-wip-us.apache.org/repos/asf/commons-lang/blob/9dcd87f9/src/main/java/org/apache/commons/lang3/JavaVersion.java
> ----------------------------------------------------------------------
> diff --git a/src/main/java/org/apache/commons/lang3/JavaVersion.java
> b/src/main/java/org/apache/commons/lang3/JavaVersion.java
> index 8c992f2..964ec4a 100644
> --- a/src/main/java/org/apache/commons/lang3/JavaVersion.java
> +++ b/src/main/java/org/apache/commons/lang3/JavaVersion.java
> @@ -16,8 +16,6 @@
>   */
>  package org.apache.commons.lang3;
>
> -import org.apache.commons.lang3.math.NumberUtils;
> -
>  /**
>   * <p>An enum representing all the versions of the Java specification.
>   * This is intended to mirror available values from the
> @@ -220,11 +218,45 @@ public enum JavaVersion {
>          if (value.contains(".")) {
>              final String[] toParse = value.split("\\.");
>              if (toParse.length >= 2) {
> -                return NumberUtils.toFloat(toParse[0] + '.' + toParse[1],
> defaultReturnValue);
> +                return toFloat(toParse[0] + '.' + toParse[1],
> defaultReturnValue);
>              }
>          } else {
> -            return NumberUtils.toFloat(value, defaultReturnValue);
> +            return toFloat(value, defaultReturnValue);
>          }
>          return defaultReturnValue;
>      }
> +
> +    /**
> +     * <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
> +     *
> +     *  <p>
> +     *  Copied from Apache Commons Math.
> +     *  </p>
> +     */
> +    private 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;
> +      }
> +    }
> +
>  }
>
>

Mime
View raw message