diff --git a/src/main/java/org/apache/commons/lang3/JavaVersion.java b/src/main/java/org/apache/commons/lang3/JavaVersion.java index b7c033ef4..35bf74eaa 100644 --- a/src/main/java/org/apache/commons/lang3/JavaVersion.java +++ b/src/main/java/org/apache/commons/lang3/JavaVersion.java @@ -36,24 +36,35 @@ public enum JavaVersion { JAVA_1_7(1.7f, "1.7"), JAVA_1_8(1.8f, "1.8"); + /** + * The float value. + */ private float value; + /** + * The standard name. + */ private String name; + /** + * Constructor. + * + * @param value the float value + * @param name the standard name, not null + */ JavaVersion(final float value, final String name) { this.value = value; this.name = name; } + //----------------------------------------------------------------------- /** - * Whether this version of Java is at least the version - * of Java passed in. + *

Whether this version of Java is at least the version of Java passed in.

* - * For example: - * myVersion.atLeast(JavaVersion.JAVA_1_4) + *

For example:
+ * {@code myVersion.atLeast(JavaVersion.JAVA_1_4)}

* - * @param requiredVersion to check this version is at least equivalent to - * - * @return Whether this version is at least the passed in version + * @param requiredVersion the version to check against, not null + * @return true if this version is equal to or greater than the specified version */ public boolean atLeast(JavaVersion requiredVersion) { return this.value >= requiredVersion.value; @@ -63,35 +74,42 @@ public boolean atLeast(JavaVersion requiredVersion) { static JavaVersion getJavaVersion(final String nom) { return get(nom); } + static JavaVersion get(final String nom) { - if("0.9".equals(nom)) { + if ("0.9".equals(nom)) { return JAVA_0_9; - } else - if("1.1".equals(nom)) { + } else if ("1.1".equals(nom)) { return JAVA_1_1; - } else - if("1.2".equals(nom)) { + } else if ("1.2".equals(nom)) { return JAVA_1_2; - } else - if("1.3".equals(nom)) { + } else if ("1.3".equals(nom)) { return JAVA_1_3; - } else - if("1.4".equals(nom)) { + } else if ("1.4".equals(nom)) { return JAVA_1_4; - } else - if("1.5".equals(nom)) { + } else if ("1.5".equals(nom)) { return JAVA_1_5; - } else - if("1.6".equals(nom)) { + } else if ("1.6".equals(nom)) { return JAVA_1_6; - } else - if("1.7".equals(nom)) { + } else if ("1.7".equals(nom)) { return JAVA_1_7; - } else - if("1.8".equals(nom)) { + } else if ("1.8".equals(nom)) { return JAVA_1_8; } else { return null; } } + + //----------------------------------------------------------------------- + /** + *

The string value is overridden to return the standard name.

+ * + *

For example, '1.5'.

+ * + * @return the name, not null + */ + @Override + public String toString() { + return name; + } + } diff --git a/src/test/java/org/apache/commons/lang3/JavaVersionTest.java b/src/test/java/org/apache/commons/lang3/JavaVersionTest.java index 66ad1fcee..36e9d09a3 100644 --- a/src/test/java/org/apache/commons/lang3/JavaVersionTest.java +++ b/src/test/java/org/apache/commons/lang3/JavaVersionTest.java @@ -18,8 +18,17 @@ */ package org.apache.commons.lang3; -import static org.apache.commons.lang3.JavaVersion.*; - +import static org.apache.commons.lang3.JavaVersion.JAVA_0_9; +import static org.apache.commons.lang3.JavaVersion.JAVA_1_1; +import static org.apache.commons.lang3.JavaVersion.JAVA_1_2; +import static org.apache.commons.lang3.JavaVersion.JAVA_1_3; +import static org.apache.commons.lang3.JavaVersion.JAVA_1_4; +import static org.apache.commons.lang3.JavaVersion.JAVA_1_5; +import static org.apache.commons.lang3.JavaVersion.JAVA_1_6; +import static org.apache.commons.lang3.JavaVersion.JAVA_1_7; +import static org.apache.commons.lang3.JavaVersion.JAVA_1_8; +import static org.apache.commons.lang3.JavaVersion.get; +import static org.apache.commons.lang3.JavaVersion.getJavaVersion; import junit.framework.TestCase; /** @@ -53,4 +62,8 @@ public void testAtLeast() { assertFalse("0.9 at least 1.6 passed", JAVA_0_9.atLeast(JAVA_1_6)); } + public void testToString() { + assertEquals("1.2", JAVA_1_2.toString()); + } + }