Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 51957 invoked from network); 31 Jan 2011 01:35:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 31 Jan 2011 01:35:51 -0000 Received: (qmail 35425 invoked by uid 500); 31 Jan 2011 01:35:50 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 35294 invoked by uid 500); 31 Jan 2011 01:35:50 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 35286 invoked by uid 99); 31 Jan 2011 01:35:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Jan 2011 01:35:50 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of paulus.benedictus@gmail.com designates 209.85.212.43 as permitted sender) Received: from [209.85.212.43] (HELO mail-vw0-f43.google.com) (209.85.212.43) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Jan 2011 01:35:41 +0000 Received: by vws17 with SMTP id 17so1771979vws.30 for ; Sun, 30 Jan 2011 17:35:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=Wc033oPR4DT/G8alI/hUskOUr3dIs+GMHrT1isOmgeU=; b=g9HPG9EC52cHfHOFz6X4cniJ8iXIhh0/ZJKTpNSDqnZiO4f8r2qCQstxKcDEQb8Hzb 9o/I3jFbeWUVrjsJ14AKB5HHBxKaY1rY1G5pWTC3qRMn+M5WnswcpKS8T2g+yrvTB6/w +8frcFnEF1srYxjRsjoeOZX0pxL6ZW/mmAxRs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; b=iNR8hnfsrQvNQieloauecdbK9g7II++UIyRfV88GPuX5kh7jlTiXGpm7ypnUa/l3jO /bM3xrhmbOo5XttlERUKx6QW+JKu4zLBedVvzi/z0r/tES6rb4fR/Q4k3x0mhD5x3MX0 i2tvx2eIH5rnZhwu1glzTDIaotZq0Ksx3vI9E= MIME-Version: 1.0 Received: by 10.220.187.13 with SMTP id cu13mr1391294vcb.172.1296437719876; Sun, 30 Jan 2011 17:35:19 -0800 (PST) Sender: paulus.benedictus@gmail.com Received: by 10.220.180.202 with HTTP; Sun, 30 Jan 2011 17:35:19 -0800 (PST) In-Reply-To: References: Date: Sun, 30 Jan 2011 19:35:19 -0600 X-Google-Sender-Auth: TwraUiNU9-SiYkgHvhVZ9mmGwgE Message-ID: Subject: Re: [lang] enum for Java Version [was svn commit: r1065174 - ...] From: Paul Benedict To: Commons Developers List Content-Type: multipart/alternative; boundary=90e6ba4fc350c44a36049b1a6d79 X-Virus-Checked: Checked by ClamAV on apache.org --90e6ba4fc350c44a36049b1a6d79 Content-Type: text/plain; charset=ISO-8859-1 I like this the best: http://api.dpml.net/openjdk/module/20070627/java/module/Version.html On Sun, Jan 30, 2011 at 5:43 PM, Henri Yandell wrote: > The enum is less to do with Android and more to do with the float and > int APIs being bizarre. The enum is to have something more useable. > > We could drop the enum and just go with String values. > > Hen > > On Sun, Jan 30, 2011 at 1:34 PM, Stephen Colebourne > wrote: > > I have no philosophical problem with adding to an enum in a later > > release, its designed to be compatible (don't persist the ordinal). > > However, I'm unconvinced that an enum is the right solution here. I > > should probably study the details, but if Android is broken perhaps > > thats just how it is. > > Stephen > > > > > > On 30 January 2011 21:29, Niall Pemberton > wrote: > >> IMO this is a really bad idea. Enum's shouldn't ever change, since > >> changing them can break code that use them. Clearly this enum will > >> need to change every time a new version of Java is released. I'm > >> against this. > >> > >> Niall > >> > >> On Sun, Jan 30, 2011 at 3:48 AM, wrote: > >>> Author: bayard > >>> Date: Sun Jan 30 03:48:40 2011 > >>> New Revision: 1065174 > >>> > >>> URL: http://svn.apache.org/viewvc?rev=1065174&view=rev > >>> Log: > >>> Removed isJavaVersionAtLeast(float) and (int), and added an enum > variant with the new JavaVersion enum. Updated the rest of the code, > switched isJavaVersionAtLeast over to using java.specification.version and > not java.version (the vendor code) and dropped JAVA_VERSION_TRIMMED, > JAVA_VERSION_FLOAT and JAVA_VERSION_INT. See: LANG-624 > >>> > >>> Added: > >>> > commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/JavaVersion.java > (with props) > >>> Modified: > >>> > commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java > >>> > commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/SystemUtils.java > >>> > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/CharEncodingTest.java > >>> > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java > >>> > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java > >>> > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java > >>> > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java > >>> > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java > >>> > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java > >>> > >>> Modified: > commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java > >>> URL: > http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java?rev=1065174&r1=1065173&r2=1065174&view=diff > >>> > ============================================================================== > >>> --- > commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java > (original) > >>> +++ > commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ClassUtils.java > Sun Jan 30 03:48:40 2011 > >>> @@ -436,7 +436,7 @@ public class ClassUtils { > >>> * @return true if assignment possible > >>> */ > >>> public static boolean isAssignable(Class[] classArray, > Class[] toClassArray) { > >>> - return isAssignable(classArray, toClassArray, > SystemUtils.isJavaVersionAtLeast(1.5f)); > >>> + return isAssignable(classArray, toClassArray, > SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5)); > >>> } > >>> > >>> /** > >>> @@ -521,7 +521,7 @@ public class ClassUtils { > >>> * @return true if assignment possible > >>> */ > >>> public static boolean isAssignable(Class cls, Class toClass) > { > >>> - return isAssignable(cls, toClass, > SystemUtils.isJavaVersionAtLeast(1.5f)); > >>> + return isAssignable(cls, toClass, > SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5)); > >>> } > >>> > >>> /** > >>> > >>> Added: > commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/JavaVersion.java > >>> URL: > http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/JavaVersion.java?rev=1065174&view=auto > >>> > ============================================================================== > >>> --- > commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/JavaVersion.java > (added) > >>> +++ > commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/JavaVersion.java > Sun Jan 30 03:48:40 2011 > >>> @@ -0,0 +1,82 @@ > >>> +/* > >>> + * 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; > >>> + > >>> +/** > >>> + *

An enum representing all the versions of the Java specification. > >>> + * This is intended to mirror available values from the > >>> + * java.specification.version System property.

> >>> + * > >>> + * @author Apache Software Foundation > >>> + * @since 3.0 > >>> + * @version $Id: $ > >>> + */ > >>> +public enum JavaVersion { > >>> + JAVA_0_9(1.5f, "0.9"), // Android > >>> + JAVA_1_1(1.1f, "1.1"), > >>> + JAVA_1_2(1.2f, "1.2"), > >>> + JAVA_1_3(1.3f, "1.3"), > >>> + JAVA_1_4(1.4f, "1.4"), > >>> + JAVA_1_5(1.5f, "1.5"), > >>> + JAVA_1_6(1.6f, "1.6"), > >>> + JAVA_1_7(1.7f, "1.7"); > >>> + > >>> + private float value; > >>> + private String name; > >>> + > >>> + JavaVersion(final float value, final String name) { > >>> + this.value = value; > >>> + this.name = name; > >>> + } > >>> + > >>> + public boolean atLeast(JavaVersion requiredVersion) { > >>> + return this.value >= requiredVersion.value; > >>> + } > >>> + > >>> + // helper for static importing > >>> + static JavaVersion getJavaVersion(final String nom) { > >>> + return getJavaVersion(nom); > >>> + } > >>> + static JavaVersion get(final String nom) { > >>> + if("0.9".equals(nom)) { > >>> + return JAVA_0_9; > >>> + } else > >>> + if("1.1".equals(nom)) { > >>> + return JAVA_1_1; > >>> + } else > >>> + if("1.2".equals(nom)) { > >>> + return JAVA_1_2; > >>> + } else > >>> + if("1.3".equals(nom)) { > >>> + return JAVA_1_3; > >>> + } else > >>> + if("1.4".equals(nom)) { > >>> + return JAVA_1_4; > >>> + } else > >>> + if("1.5".equals(nom)) { > >>> + return JAVA_1_5; > >>> + } else > >>> + if("1.6".equals(nom)) { > >>> + return JAVA_1_6; > >>> + } else > >>> + if("1.7".equals(nom)) { > >>> + return JAVA_1_7; > >>> + } else { > >>> + return null; > >>> + } > >>> + } > >>> +} > >>> > >>> Propchange: > commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/JavaVersion.java > >>> > ------------------------------------------------------------------------------ > >>> svn:eol-style = native > >>> > >>> Modified: > commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/SystemUtils.java > >>> URL: > http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/SystemUtils.java?rev=1065174&r1=1065173&r2=1065174&view=diff > >>> > ============================================================================== > >>> --- > commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/SystemUtils.java > (original) > >>> +++ > commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/SystemUtils.java > Sun Jan 30 03:48:40 2011 > >>> @@ -473,6 +473,7 @@ public class SystemUtils { > >>> * @since Java 1.3 > >>> */ > >>> public static final String JAVA_SPECIFICATION_VERSION = > getSystemProperty("java.specification.version"); > >>> + private static final JavaVersion > JAVA_SPECIFICATION_VERSION_AS_ENUM = > JavaVersion.get(JAVA_SPECIFICATION_VERSION); > >>> > >>> /** > >>> *

> >>> @@ -898,71 +899,6 @@ public class SystemUtils { > >>> */ > >>> public static final String USER_TIMEZONE = > getSystemProperty("user.timezone"); > >>> > >>> - // Java version > >>> - // > ----------------------------------------------------------------------- > >>> - // This MUST be declared after those above as it depends on the > >>> - // values being set up > >>> - > >>> - /** > >>> - *

> >>> - * Gets the Java version as a String trimming leading > letters. > >>> - *

> >>> - * > >>> - *

> >>> - * The field will return null if {@link > #JAVA_VERSION} is null. > >>> - *

> >>> - * > >>> - * @since 2.1 > >>> - */ > >>> - public static final String JAVA_VERSION_TRIMMED = > getJavaVersionTrimmed(); > >>> - > >>> - // Java version values > >>> - // > ----------------------------------------------------------------------- > >>> - // These MUST be declared after the trim above as they depend on > the > >>> - // value being set up > >>> - > >>> - /** > >>> - *

> >>> - * Gets the Java version as a float. > >>> - *

> >>> - * > >>> - *

> >>> - * Example return values: > >>> - *

> >>> - *
    > >>> - *
  • 1.2f for Java 1.2 > >>> - *
  • 1.31f for Java 1.3.1 > >>> - *
> >>> - * > >>> - *

> >>> - * The field will return zero if {@link #JAVA_VERSION} is > null. > >>> - *

> >>> - * > >>> - * @since 2.0 > >>> - */ > >>> - public static final float JAVA_VERSION_FLOAT = > getJavaVersionAsFloat(); > >>> - > >>> - /** > >>> - *

> >>> - * Gets the Java version as an int. > >>> - *

> >>> - * > >>> - *

> >>> - * Example return values: > >>> - *

> >>> - *
    > >>> - *
  • 120 for Java 1.2 > >>> - *
  • 131 for Java 1.3.1 > >>> - *
> >>> - * > >>> - *

> >>> - * The field will return zero if {@link #JAVA_VERSION} is > null. > >>> - *

> >>> - * > >>> - * @since 2.0 > >>> - */ > >>> - public static final int JAVA_VERSION_INT = getJavaVersionAsInt(); > >>> - > >>> // Java version checks > >>> // > ----------------------------------------------------------------------- > >>> // These MUST be declared after those above as they depend on the > >>> @@ -1342,54 +1278,6 @@ public class SystemUtils { > >>> > >>> /** > >>> *

> >>> - * Gets the Java version number as a float. > >>> - *

> >>> - * > >>> - *

> >>> - * Example return values: > >>> - *

> >>> - *
    > >>> - *
  • 1.2f for Java 1.2
  • > >>> - *
  • 1.31f for Java 1.3.1
  • > >>> - *
  • 1.6f for Java 1.6.0_20
  • > >>> - *
> >>> - * > >>> - *

> >>> - * Patch releases are not reported. > >>> - *

> >>> - * > >>> - * @return the version, for example 1.31f for Java 1.3.1 > >>> - */ > >>> - private static float getJavaVersionAsFloat() { > >>> - return > toVersionFloat(toJavaVersionIntArray(SystemUtils.JAVA_VERSION, > JAVA_VERSION_TRIM_SIZE)); > >>> - } > >>> - > >>> - /** > >>> - *

> >>> - * Gets the Java version number as an int. > >>> - *

> >>> - * > >>> - *

> >>> - * Example return values: > >>> - *

> >>> - *
    > >>> - *
  • 120 for Java 1.2
  • > >>> - *
  • 131 for Java 1.3.1
  • > >>> - *
  • 160 for Java 1.6.0_20
  • > >>> - *
> >>> - * > >>> - *

> >>> - * Patch releases are not reported. > >>> - *

> >>> - * > >>> - * @return the version, for example 131 for Java 1.3.1 > >>> - */ > >>> - private static int getJavaVersionAsInt() { > >>> - return > toVersionInt(toJavaVersionIntArray(SystemUtils.JAVA_VERSION, > JAVA_VERSION_TRIM_SIZE)); > >>> - } > >>> - > >>> - /** > >>> - *

> >>> * Decides if the Java version matches. > >>> *

> >>> * > >>> @@ -1398,24 +1286,7 @@ public class SystemUtils { > >>> * @return true if matches, or false if not or can't determine > >>> */ > >>> private static boolean getJavaVersionMatches(String versionPrefix) > { > >>> - return isJavaVersionMatch(JAVA_VERSION_TRIMMED, > versionPrefix); > >>> - } > >>> - > >>> - /** > >>> - * Trims the text of the java version to start with numbers. > >>> - * > >>> - * @return the trimmed java version > >>> - */ > >>> - private static String getJavaVersionTrimmed() { > >>> - if (JAVA_VERSION != null) { > >>> - for (int i = 0; i < JAVA_VERSION.length(); i++) { > >>> - char ch = JAVA_VERSION.charAt(i); > >>> - if (ch >= '0' && ch <= '9') { > >>> - return JAVA_VERSION.substring(i); > >>> - } > >>> - } > >>> - } > >>> - return null; > >>> + return isJavaVersionMatch(JAVA_SPECIFICATION_VERSION, > versionPrefix); > >>> } > >>> > >>> /** > >>> @@ -1530,30 +1401,8 @@ public class SystemUtils { > >>> * the required version, for example 1.31f > >>> * @return true if the actual version is equal or > greater than the required version > >>> */ > >>> - public static boolean isJavaVersionAtLeast(float requiredVersion) > { > >>> - return JAVA_VERSION_FLOAT >= requiredVersion; > >>> - } > >>> - > >>> - /** > >>> - *

> >>> - * Is the Java version at least the requested version. > >>> - *

> >>> - * > >>> - *

> >>> - * Example input: > >>> - *

> >>> - *
    > >>> - *
  • 120 to test for Java 1.2 or greater
  • > >>> - *
  • 131 to test for Java 1.3.1 or greater
  • > >>> - *
> >>> - * > >>> - * @param requiredVersion > >>> - * the required version, for example 131 > >>> - * @return true if the actual version is equal or > greater than the required version > >>> - * @since 2.0 > >>> - */ > >>> - public static boolean isJavaVersionAtLeast(int requiredVersion) { > >>> - return JAVA_VERSION_INT >= requiredVersion; > >>> + public static boolean isJavaVersionAtLeast(JavaVersion > requiredVersion) { > >>> + return > JAVA_SPECIFICATION_VERSION_AS_ENUM.atLeast(requiredVersion); > >>> } > >>> > >>> /** > >>> @@ -1619,193 +1468,6 @@ public class SystemUtils { > >>> return osName.startsWith(osNamePrefix); > >>> } > >>> > >>> - /** > >>> - *

> >>> - * Converts the given Java version string to a float. > >>> - *

> >>> - * > >>> - *

> >>> - * Example return values: > >>> - *

> >>> - *
    > >>> - *
  • 1.2f for Java 1.2
  • > >>> - *
  • 1.31f for Java 1.3.1
  • > >>> - *
  • 1.6f for Java 1.6.0_20
  • > >>> - *
> >>> - * > >>> - *

> >>> - * Patch releases are not reported. > >>> - *

> >>> - *

> >>> - * This method is package private instead of private to support > unit test invocation. > >>> - *

> >>> - * > >>> - * @return the version, for example 1.31f for Java 1.3.1 > >>> - */ > >>> - static float toJavaVersionFloat(String version) { > >>> - return toVersionFloat(toJavaVersionIntArray(version, > JAVA_VERSION_TRIM_SIZE)); > >>> - } > >>> - > >>> - /** > >>> - *

> >>> - * Converts the given Java version string to an int. > >>> - *

> >>> - * > >>> - *

> >>> - * Example return values: > >>> - *

> >>> - *
    > >>> - *
  • 120 for Java 1.2
  • > >>> - *
  • 131 for Java 1.3.1
  • > >>> - *
  • 160 for Java 1.6.0_20
  • > >>> - *
> >>> - * > >>> - *

> >>> - * Patch releases are not reported. > >>> - *

> >>> - *

> >>> - * This method is package private instead of private to support > unit test invocation. > >>> - *

> >>> - * > >>> - * @return the version, for example 131 for Java 1.3.1 > >>> - */ > >>> - static int toJavaVersionInt(String version) { > >>> - return toVersionInt(toJavaVersionIntArray(version, > JAVA_VERSION_TRIM_SIZE)); > >>> - } > >>> - > >>> - /** > >>> - *

> >>> - * Converts the given Java version string to an int[] > of maximum size 3. > >>> - *

> >>> - * > >>> - *

> >>> - * Example return values: > >>> - *

> >>> - *
    > >>> - *
  • [1, 2, 0] for Java 1.2
  • > >>> - *
  • [1, 3, 1] for Java 1.3.1
  • > >>> - *
  • [1, 5, 0] for Java 1.5.0_21
  • > >>> - *
> >>> - *

> >>> - * This method is package private instead of private to support > unit test invocation. > >>> - *

> >>> - * > >>> - * @return the version, for example [1, 5, 0] for Java 1.5.0_21 > >>> - */ > >>> - static int[] toJavaVersionIntArray(String version) { > >>> - return toJavaVersionIntArray(version, Integer.MAX_VALUE); > >>> - } > >>> - > >>> - /** > >>> - *

> >>> - * Converts the given Java version string to an int[] > of maximum size limit. > >>> - *

> >>> - * > >>> - *

> >>> - * Example return values: > >>> - *

> >>> - *
    > >>> - *
  • [1, 2, 0] for Java 1.2
  • > >>> - *
  • [1, 3, 1] for Java 1.3.1
  • > >>> - *
  • [1, 5, 0, 21] for Java 1.5.0_21
  • > >>> - *
> >>> - * > >>> - * @return the version, for example [1, 5, 0, 21] for Java > 1.5.0_21 > >>> - */ > >>> - private static int[] toJavaVersionIntArray(String version, int > limit) { > >>> - if (version == null) { > >>> - return ArrayUtils.EMPTY_INT_ARRAY; > >>> - } > >>> - String[] strings = Pattern.compile("[^\\d]").split(version); > >>> - int[] ints = new int[Math.min(limit, strings.length)]; > >>> - int j = 0; > >>> - for (int i = 0; i < strings.length && j < limit; i++) { > >>> - String s = strings[i]; > >>> - if (s.length() > 0) { > >>> - ints[j++] = Integer.parseInt(s); > >>> - } > >>> - } > >>> - return ints; > >>> - } > >>> - > >>> - /** > >>> - *

> >>> - * Converts given the Java version array to a float. > >>> - *

> >>> - * > >>> - *

> >>> - * Example return values: > >>> - *

> >>> - *
    > >>> - *
  • 1.2f for Java 1.2
  • > >>> - *
  • 1.31f for Java 1.3.1
  • > >>> - *
  • 1.6f for Java 1.6.0_20
  • > >>> - *
> >>> - * > >>> - *

> >>> - * Patch releases are not reported. > >>> - *

> >>> - * > >>> - * @return the version, for example 1.31f for Java 1.3.1 > >>> - */ > >>> - private static float toVersionFloat(int[] javaVersions) { > >>> - if (javaVersions == null || javaVersions.length == 0) { > >>> - return 0f; > >>> - } > >>> - if (javaVersions.length == 1) { > >>> - return javaVersions[0]; > >>> - } > >>> - StringBuilder builder = new StringBuilder(); > >>> - builder.append(javaVersions[0]); > >>> - builder.append('.'); > >>> - for (int i = 1; i < javaVersions.length; i++) { > >>> - builder.append(javaVersions[i]); > >>> - } > >>> - try { > >>> - return Float.parseFloat(builder.toString()); > >>> - } catch (Exception ex) { > >>> - return 0f; > >>> - } > >>> - } > >>> - > >>> - /** > >>> - *

> >>> - * Converts given the Java version array to an int. > >>> - *

> >>> - * > >>> - *

> >>> - * Example return values: > >>> - *

> >>> - *
    > >>> - *
  • 120 for Java 1.2
  • > >>> - *
  • 131 for Java 1.3.1
  • > >>> - *
  • 160 for Java 1.6.0_20
  • > >>> - *
> >>> - * > >>> - *

> >>> - * Patch releases are not reported. > >>> - *

> >>> - * > >>> - * @return the version, for example 1.31f for Java 1.3.1 > >>> - */ > >>> - private static int toVersionInt(int[] javaVersions) { > >>> - if (javaVersions == null) { > >>> - return 0; > >>> - } > >>> - int intVersion = 0; > >>> - int len = javaVersions.length; > >>> - if (len >= 1) { > >>> - intVersion = javaVersions[0] * 100; > >>> - } > >>> - if (len >= 2) { > >>> - intVersion += javaVersions[1] * 10; > >>> - } > >>> - if (len >= 3) { > >>> - intVersion += javaVersions[2]; > >>> - } > >>> - return intVersion; > >>> - } > >>> - > >>> // > ----------------------------------------------------------------------- > >>> /** > >>> *

> >>> > >>> Modified: > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/CharEncodingTest.java > >>> URL: > http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/CharEncodingTest.java?rev=1065174&r1=1065173&r2=1065174&view=diff > >>> > ============================================================================== > >>> --- > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/CharEncodingTest.java > (original) > >>> +++ > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/CharEncodingTest.java > Sun Jan 30 03:48:40 2011 > >>> @@ -19,6 +19,8 @@ package org.apache.commons.lang3; > >>> > >>> import junit.framework.TestCase; > >>> > >>> +import static org.apache.commons.lang3.JavaVersion.*; > >>> + > >>> /** > >>> * Tests CharEncoding. > >>> * > >>> @@ -40,7 +42,7 @@ public class CharEncodingTest extends Te > >>> } > >>> > >>> public void testMustBeSupportedJava1_3_1() { > >>> - if (SystemUtils.isJavaVersionAtLeast(1.3f)) { > >>> + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_3)) { > >>> this.assertSupportedEncoding(CharEncoding.ISO_8859_1); > >>> this.assertSupportedEncoding(CharEncoding.US_ASCII); > >>> this.assertSupportedEncoding(CharEncoding.UTF_16); > >>> @@ -48,7 +50,7 @@ public class CharEncodingTest extends Te > >>> this.assertSupportedEncoding(CharEncoding.UTF_16LE); > >>> this.assertSupportedEncoding(CharEncoding.UTF_8); > >>> } else { > >>> - this.warn("Java 1.3 tests not run since the current > version is " + SystemUtils.JAVA_VERSION); > >>> + this.warn("Java 1.3 tests not run since the current > version is " + SystemUtils.JAVA_SPECIFICATION_VERSION); > >>> } > >>> } > >>> > >>> @@ -66,12 +68,12 @@ public class CharEncodingTest extends Te > >>> // In this test, I simply deleted the encodings from the 1.3.1 > list. > >>> // The Javadoc do not specify which encodings are required. > >>> // > >>> - if (SystemUtils.isJavaVersionAtLeast(1.1f)) { > >>> + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_1)) { > >>> this.assertSupportedEncoding(CharEncoding.ISO_8859_1); > >>> this.assertSupportedEncoding(CharEncoding.US_ASCII); > >>> this.assertSupportedEncoding(CharEncoding.UTF_8); > >>> } else { > >>> - this.warn("Java 1.1 tests not run since the current > version is " + SystemUtils.JAVA_VERSION); > >>> + this.warn("Java 1.1 tests not run since the current > version is " + SystemUtils.JAVA_SPECIFICATION_VERSION); > >>> } > >>> } > >>> > >>> @@ -80,12 +82,12 @@ public class CharEncodingTest extends Te > >>> // In this test, I simply deleted the encodings from the 1.3.1 > list. > >>> // The Javadoc do not specify which encodings are required. > >>> // > >>> - if (SystemUtils.isJavaVersionAtLeast(1.2f)) { > >>> + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_2)) { > >>> this.assertSupportedEncoding(CharEncoding.ISO_8859_1); > >>> this.assertSupportedEncoding(CharEncoding.US_ASCII); > >>> this.assertSupportedEncoding(CharEncoding.UTF_8); > >>> } else { > >>> - this.warn("Java 1.2 tests not run since the current > version is " + SystemUtils.JAVA_VERSION); > >>> + this.warn("Java 1.2 tests not run since the current > version is " + SystemUtils.JAVA_SPECIFICATION_VERSION); > >>> } > >>> } > >>> > >>> > >>> Modified: > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java > >>> URL: > http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java?rev=1065174&r1=1065173&r2=1065174&view=diff > >>> > ============================================================================== > >>> --- > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java > (original) > >>> +++ > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java > Sun Jan 30 03:48:40 2011 > >>> @@ -27,6 +27,8 @@ import java.util.List; > >>> import java.util.Map; > >>> import java.util.Set; > >>> > >>> +import static org.apache.commons.lang3.JavaVersion.*; > >>> + > >>> import junit.framework.TestCase; > >>> > >>> /** > >>> @@ -265,7 +267,7 @@ public class ClassUtilsTest extends Test > >>> assertTrue(ClassUtils.isAssignable(array1s, array1s)); > >>> assertTrue(ClassUtils.isAssignable(array1s, array1)); > >>> > >>> - boolean autoboxing = SystemUtils.isJavaVersionAtLeast(1.5f); > >>> + boolean autoboxing = > SystemUtils.isJavaVersionAtLeast(JAVA_1_5); > >>> > >>> assertEquals(autoboxing, > ClassUtils.isAssignable(arrayPrimitives, arrayWrappers)); > >>> assertEquals(autoboxing, ClassUtils.isAssignable(arrayWrappers, > arrayPrimitives)); > >>> @@ -340,7 +342,7 @@ public class ClassUtilsTest extends Test > >>> assertTrue(ClassUtils.isAssignable(String.class, > String.class)); > >>> assertFalse(ClassUtils.isAssignable(Object.class, > String.class)); > >>> > >>> - boolean autoboxing = SystemUtils.isJavaVersionAtLeast(1.5f); > >>> + boolean autoboxing = > SystemUtils.isJavaVersionAtLeast(JAVA_1_5); > >>> > >>> assertEquals(autoboxing, ClassUtils.isAssignable(Integer.TYPE, > Integer.class)); > >>> assertEquals(autoboxing, ClassUtils.isAssignable(Integer.TYPE, > Object.class)); > >>> @@ -485,7 +487,7 @@ public class ClassUtilsTest extends Test > >>> } > >>> > >>> public void test_isAssignable_DefaultUnboxing_Widening() throws > Exception { > >>> - boolean autoboxing = SystemUtils.isJavaVersionAtLeast(1.5f); > >>> + boolean autoboxing = > SystemUtils.isJavaVersionAtLeast(JAVA_1_5); > >>> > >>> // test byte conversions > >>> assertFalse("byte -> char", ClassUtils.isAssignable(Byte.class, > Character.TYPE)); > >>> > >>> Modified: > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java > >>> URL: > http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java?rev=1065174&r1=1065173&r2=1065174&view=diff > >>> > ============================================================================== > >>> --- > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java > (original) > >>> +++ > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java > Sun Jan 30 03:48:40 2011 > >>> @@ -26,6 +26,8 @@ import java.util.List; > >>> import java.util.Locale; > >>> import java.util.Set; > >>> > >>> +import static org.apache.commons.lang3.JavaVersion.*; > >>> + > >>> import junit.framework.TestCase; > >>> > >>> /** > >>> @@ -212,7 +214,7 @@ public class LocaleUtilsTest extends Tes > >>> assertValidToLocale("us_EN_A", "us", "EN", "A"); > >>> // this isn't pretty, but was caused by a jdk bug it seems > >>> // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4210525 > >>> - if (SystemUtils.isJavaVersionAtLeast(1.4f)) { > >>> + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_4)) { > >>> assertValidToLocale("us_EN_a", "us", "EN", "a"); > >>> assertValidToLocale("us_EN_SFsafdFDsdfF", "us", "EN", > "SFsafdFDsdfF"); > >>> } else { > >>> > >>> Modified: > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java > >>> URL: > http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java?rev=1065174&r1=1065173&r2=1065174&view=diff > >>> > ============================================================================== > >>> --- > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java > (original) > >>> +++ > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java > Sun Jan 30 03:48:40 2011 > >>> @@ -27,6 +27,8 @@ import java.util.Locale; > >>> import junit.framework.Assert; > >>> import junit.framework.TestCase; > >>> > >>> +import static org.apache.commons.lang3.JavaVersion.*; > >>> + > >>> /** > >>> * Unit tests {@link org.apache.commons.lang3.SystemUtils}. > >>> * > >>> @@ -187,62 +189,6 @@ public class SystemUtilsTest extends Tes > >>> } > >>> } > >>> > >>> - public void testJavaVersionAsFloat() { > >>> - assertEquals(0f, SystemUtils.toJavaVersionFloat(null), > 0.000001f); > >>> - assertEquals(0f, SystemUtils.toJavaVersionFloat(""), > 0.000001f); > >>> - assertEquals(0f, SystemUtils.toJavaVersionFloat("0"), > 0.000001f); > >>> - assertEquals(1.1f, SystemUtils.toJavaVersionFloat("1.1"), > 0.000001f); > >>> - assertEquals(1.2f, SystemUtils.toJavaVersionFloat("1.2"), > 0.000001f); > >>> - assertEquals(1.3f, SystemUtils.toJavaVersionFloat("1.3.0"), > 0.000001f); > >>> - assertEquals(1.31f, SystemUtils.toJavaVersionFloat("1.3.1"), > 0.000001f); > >>> - assertEquals(1.4f, SystemUtils.toJavaVersionFloat("1.4.0"), > 0.000001f); > >>> - assertEquals(1.41f, SystemUtils.toJavaVersionFloat("1.4.1"), > 0.000001f); > >>> - assertEquals(1.42f, SystemUtils.toJavaVersionFloat("1.4.2"), > 0.000001f); > >>> - assertEquals(1.5f, SystemUtils.toJavaVersionFloat("1.5.0"), > 0.000001f); > >>> - assertEquals(1.6f, SystemUtils.toJavaVersionFloat("1.6.0"), > 0.000001f); > >>> - assertEquals(1.31f, > SystemUtils.toJavaVersionFloat("JavaVM-1.3.1"), 0.000001f); > >>> - assertEquals(1.3f, SystemUtils.toJavaVersionFloat("1.3.0 > subset"), 0.000001f); > >>> - // This used to return 0f in [lang] version 2.5: > >>> - assertEquals(1.3f, > SystemUtils.toJavaVersionFloat("XXX-1.3.x"), 0.000001f); > >>> - } > >>> - > >>> - public void testJavaVersionAsInt() { > >>> - assertEquals(0, SystemUtils.toJavaVersionInt(null)); > >>> - assertEquals(0, SystemUtils.toJavaVersionInt("")); > >>> - assertEquals(0, SystemUtils.toJavaVersionInt("0")); > >>> - assertEquals(110, SystemUtils.toJavaVersionInt("1.1")); > >>> - assertEquals(120, SystemUtils.toJavaVersionInt("1.2")); > >>> - assertEquals(130, SystemUtils.toJavaVersionInt("1.3.0")); > >>> - assertEquals(131, SystemUtils.toJavaVersionInt("1.3.1")); > >>> - assertEquals(140, SystemUtils.toJavaVersionInt("1.4.0")); > >>> - assertEquals(141, SystemUtils.toJavaVersionInt("1.4.1")); > >>> - assertEquals(142, SystemUtils.toJavaVersionInt("1.4.2")); > >>> - assertEquals(150, SystemUtils.toJavaVersionInt("1.5.0")); > >>> - assertEquals(160, SystemUtils.toJavaVersionInt("1.6.0")); > >>> - assertEquals(131, > SystemUtils.toJavaVersionInt("JavaVM-1.3.1")); > >>> - assertEquals(131, SystemUtils.toJavaVersionInt("1.3.1 > subset")); > >>> - // This used to return 0f in [lang] version 2.5: > >>> - assertEquals(130, SystemUtils.toJavaVersionInt("XXX-1.3.x")); > >>> - } > >>> - > >>> - public void testJavaVersionAtLeastFloat() { > >>> - float version = SystemUtils.JAVA_VERSION_FLOAT; > >>> - assertEquals(true, SystemUtils.isJavaVersionAtLeast(version)); > >>> - version -= 0.1f; > >>> - assertEquals(true, SystemUtils.isJavaVersionAtLeast(version)); > >>> - version += 0.2f; > >>> - assertEquals(false, > SystemUtils.isJavaVersionAtLeast(version)); > >>> - } > >>> - > >>> - public void testJavaVersionAtLeastInt() { > >>> - int version = SystemUtils.JAVA_VERSION_INT; > >>> - assertEquals(true, SystemUtils.isJavaVersionAtLeast(version)); > >>> - version -= 10; > >>> - assertEquals(true, SystemUtils.isJavaVersionAtLeast(version)); > >>> - version += 20; > >>> - assertEquals(false, > SystemUtils.isJavaVersionAtLeast(version)); > >>> - } > >>> - > >>> public void testJavaVersionMatches() { > >>> String javaVersion = null; > >>> assertEquals(false, SystemUtils.isJavaVersionMatch(javaVersion, > "1.0")); > >>> @@ -401,7 +347,7 @@ public class SystemUtilsTest extends Tes > >>> } > >>> > >>> public void testJavaAwtHeadless() { > >>> - boolean atLeastJava14 = SystemUtils.isJavaVersionAtLeast(140); > >>> + boolean atLeastJava14 = > SystemUtils.isJavaVersionAtLeast(JAVA_1_4); > >>> String expectedStringValue = > System.getProperty("java.awt.headless"); > >>> String expectedStringValueWithDefault = > System.getProperty("java.awt.headless", "false"); > >>> assertNotNull(expectedStringValueWithDefault); > >>> > >>> Modified: > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java > >>> URL: > http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java?rev=1065174&r1=1065173&r2=1065174&view=diff > >>> > ============================================================================== > >>> --- > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java > (original) > >>> +++ > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java > Sun Jan 30 03:48:40 2011 > >>> @@ -23,6 +23,7 @@ import java.math.BigInteger; > >>> > >>> import junit.framework.TestCase; > >>> > >>> +import static org.apache.commons.lang3.JavaVersion.*; > >>> import org.apache.commons.lang3.SystemUtils; > >>> > >>> /** > >>> @@ -198,7 +199,7 @@ public class NumberUtilsTest extends Tes > >>> .createNumber("12345678901234567890L")); > >>> > >>> // jdk 1.2 doesn't support this. unsure about jdk 1.2.2 > >>> - if (SystemUtils.isJavaVersionAtLeast(1.3f)) { > >>> + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_3)) { > >>> assertEquals("createNumber(String) 15 failed", new > BigDecimal("1.1E-700"), NumberUtils > >>> .createNumber("1.1E-700F")); > >>> } > >>> > >>> Modified: > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java > >>> URL: > http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java?rev=1065174&r1=1065173&r2=1065174&view=diff > >>> > ============================================================================== > >>> --- > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java > (original) > >>> +++ > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java > Sun Jan 30 03:48:40 2011 > >>> @@ -34,6 +34,7 @@ import java.util.Map; > >>> > >>> import junit.framework.TestCase; > >>> > >>> +import static org.apache.commons.lang3.JavaVersion.*; > >>> import org.apache.commons.lang3.SystemUtils; > >>> > >>> /** > >>> @@ -359,7 +360,7 @@ public class ExtendedMessageFormatTest e > >>> > >>> //can't trust what MessageFormat does with toPattern() pre 1.4: > >>> private void assertPatternsEqual(String message, String expected, > String actual) { > >>> - if (SystemUtils.isJavaVersionAtLeast(1.4f)) { > >>> + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_4)) { > >>> assertEquals(message, expected, actual); > >>> } > >>> } > >>> > >>> Modified: > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java > >>> URL: > http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java?rev=1065174&r1=1065173&r2=1065174&view=diff > >>> > ============================================================================== > >>> --- > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java > (original) > >>> +++ > commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java > Sun Jan 30 03:48:40 2011 > >>> @@ -32,6 +32,7 @@ import java.util.TimeZone; > >>> import junit.framework.AssertionFailedError; > >>> import junit.framework.TestCase; > >>> > >>> +import static org.apache.commons.lang3.JavaVersion.*; > >>> import org.apache.commons.lang3.SystemUtils; > >>> > >>> /** > >>> @@ -805,7 +806,7 @@ public class DateUtilsTest extends TestC > >>> assertEquals("round MET date across DST change-over", > >>> dateTimeParser.parse("March 30, 2003 01:00:00.000"), > >>> DateUtils.round((Object) cal4, Calendar.HOUR_OF_DAY)); > >>> - if (SystemUtils.isJavaVersionAtLeast(1.4f)) { > >>> + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_4)) { > >>> assertEquals("round MET date across DST change-over", > >>> dateTimeParser.parse("March 30, 2003 > 03:00:00.000"), > >>> DateUtils.round(date5, Calendar.HOUR_OF_DAY)); > >>> @@ -825,7 +826,7 @@ public class DateUtilsTest extends TestC > >>> dateTimeParser.parse("March 30, 2003 > 04:00:00.000"), > >>> DateUtils.round((Object) cal7, > Calendar.HOUR_OF_DAY)); > >>> } else { > >>> - this.warn("WARNING: Some date rounding tests not run since > the current version is " + SystemUtils.JAVA_VERSION); > >>> + this.warn("WARNING: Some date rounding tests not run since > the current version is " + SystemUtils.JAVA_SPECIFICATION_VERSION); > >>> } > >>> TimeZone.setDefault(defaultZone); > >>> dateTimeParser.setTimeZone(defaultZone); > >>> @@ -1091,8 +1092,8 @@ public class DateUtilsTest extends TestC > >>> * see http://issues.apache.org/jira/browse/LANG-59 > >>> */ > >>> public void testTruncateLang59() throws Exception { > >>> - if (!SystemUtils.isJavaVersionAtLeast(1.4f)) { > >>> - this.warn("WARNING: Test for LANG-59 not run since the > current version is " + SystemUtils.JAVA_VERSION); > >>> + if (!SystemUtils.isJavaVersionAtLeast(JAVA_1_4)) { > >>> + this.warn("WARNING: Test for LANG-59 not run since the > current version is " + SystemUtils.JAVA_SPECIFICATION_VERSION); > >>> return; > >>> } > >>> > >>> @@ -1379,7 +1380,7 @@ public class DateUtilsTest extends TestC > >>> assertEquals("ceiling MET date across DST change-over", > >>> dateTimeParser.parse("March 30, 2003 03:00:00.000"), > >>> DateUtils.ceiling((Object) cal4, > Calendar.HOUR_OF_DAY)); > >>> - if (SystemUtils.isJavaVersionAtLeast(1.4f)) { > >>> + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_4)) { > >>> assertEquals("ceiling MET date across DST change-over", > >>> dateTimeParser.parse("March 30, 2003 > 03:00:00.000"), > >>> DateUtils.ceiling(date5, Calendar.HOUR_OF_DAY)); > >>> @@ -1399,7 +1400,7 @@ public class DateUtilsTest extends TestC > >>> dateTimeParser.parse("March 30, 2003 > 04:00:00.000"), > >>> DateUtils.ceiling((Object) cal7, > Calendar.HOUR_OF_DAY)); > >>> } else { > >>> - this.warn("WARNING: Some date ceiling tests not run since > the current version is " + SystemUtils.JAVA_VERSION); > >>> + this.warn("WARNING: Some date ceiling tests not run since > the current version is " + SystemUtils.JAVA_SPECIFICATION_VERSION); > >>> } > >>> TimeZone.setDefault(defaultZone); > >>> dateTimeParser.setTimeZone(defaultZone); > >>> > >>> > >>> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > >> For additional commands, e-mail: dev-help@commons.apache.org > >> > >> > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > > For additional commands, e-mail: dev-help@commons.apache.org > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > --90e6ba4fc350c44a36049b1a6d79--