mirror of
https://github.com/apache/commons-lang.git
synced 2025-02-09 19:45:01 +00:00
Javadoc and add toString()
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1077967 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e4671b466d
commit
30c4689bca
@ -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.
|
||||
* <p>Whether this version of Java is at least the version of Java passed in.</p>
|
||||
*
|
||||
* For example:
|
||||
* myVersion.atLeast(JavaVersion.JAVA_1_4)
|
||||
* <p>For example:<br />
|
||||
* {@code myVersion.atLeast(JavaVersion.JAVA_1_4)}<p>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* <p>The string value is overridden to return the standard name.</p>
|
||||
*
|
||||
* <p>For example, '1.5'.</p>
|
||||
*
|
||||
* @return the name, not null
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user