edu.rice.cs.plt.reflect
Enum JavaVersion

java.lang.Object
  extended by java.lang.Enum<JavaVersion>
      extended by edu.rice.cs.plt.reflect.JavaVersion
All Implemented Interfaces:
Serializable, Comparable<JavaVersion>

public enum JavaVersion
extends Enum<JavaVersion>

A representation of a major Java version, with methods for parsing version number strings.


Nested Class Summary
static class JavaVersion.FullVersion
          A full Java version, implemented for the sake of comparison between version numbers.
static class JavaVersion.VendorType
          The vendor of this version.
 
Enum Constant Summary
FUTURE
           
JAVA_1_1
           
JAVA_1_2
           
JAVA_1_3
           
JAVA_1_4
           
JAVA_5
           
JAVA_6
           
JAVA_7
           
UNRECOGNIZED
           
 
Field Summary
static JavaVersion CURRENT
          The currently-available Java version, based on the "java.class.version" property.
static JavaVersion.FullVersion CURRENT_FULL
          The currently-available Java version, based on the "java.version" property.
 
Method Summary
 JavaVersion.FullVersion fullVersion()
          Returns a FullVersion that corresponds to this JavaVersion, e.g.
static JavaVersion parseClassVersion(File classFile)
          Produce the JavaVersion corresponding to the given class file.
static JavaVersion parseClassVersion(InputStream is)
          Produce the JavaVersion corresponding to the given class file.
static JavaVersion parseClassVersion(int major, int minor)
          Produce the JavaVersion corresponding to the given class version pair.
static JavaVersion parseClassVersion(String text)
          Produce the JavaVersion corresponding to the given class version string.
static JavaVersion.FullVersion parseFullVersion(String text)
          Produce the JavaVersion.FullVersion corresponding to the given version string.
static JavaVersion.FullVersion parseFullVersion(String java_version, String java_runtime_name, String java_vm_vendor)
          Produce the JavaVersion.FullVersion corresponding to the given version string.
static JavaVersion.FullVersion parseFullVersion(String java_version, String java_runtime_name, String java_vm_vendor, File location)
          Produce the JavaVersion.FullVersion corresponding to the given version string.
 boolean supports(JavaVersion v)
          true iff this version is at least as recent as v, and thus can be expected to support v's APIs (as long as the required features are backwards-compatible)
 String toString()
          Prepend "Java " to the version number string
static JavaVersion valueOf(String name)
          Returns the enum constant of this type with the specified name.
static JavaVersion[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
abstract  String versionString()
          Produce the version number as a string
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

UNRECOGNIZED

public static final JavaVersion UNRECOGNIZED

JAVA_1_1

public static final JavaVersion JAVA_1_1

JAVA_1_2

public static final JavaVersion JAVA_1_2

JAVA_1_3

public static final JavaVersion JAVA_1_3

JAVA_1_4

public static final JavaVersion JAVA_1_4

JAVA_5

public static final JavaVersion JAVA_5

JAVA_6

public static final JavaVersion JAVA_6

JAVA_7

public static final JavaVersion JAVA_7

FUTURE

public static final JavaVersion FUTURE
Field Detail

CURRENT

public static final JavaVersion CURRENT
The currently-available Java version, based on the "java.class.version" property. Ideally, a true result for JavaVersion.CURRENT.supports(v) implies that all APIs associated with that version are available at runtime. However, we do not attempt to (and cannot, in general) guarantee that the boot class path or Java installation have not been modified to only support certain API classes.


CURRENT_FULL

public static final JavaVersion.FullVersion CURRENT_FULL
The currently-available Java version, based on the "java.version" property.

Method Detail

values

public static JavaVersion[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (JavaVersion c : JavaVersion.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static JavaVersion valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

supports

public boolean supports(JavaVersion v)
true iff this version is at least as recent as v, and thus can be expected to support v's APIs (as long as the required features are backwards-compatible)


versionString

public abstract String versionString()
Produce the version number as a string


toString

public String toString()
Prepend "Java " to the version number string

Overrides:
toString in class Enum<JavaVersion>

fullVersion

public JavaVersion.FullVersion fullVersion()
Returns a FullVersion that corresponds to this JavaVersion, e.g. JAVA_6 will return a FullVersion 1.6.0_0.


parseClassVersion

public static JavaVersion parseClassVersion(String text)
Produce the JavaVersion corresponding to the given class version string. For example, "49.0" maps to JAVA_5. If the text cannot be parsed, UNRECOGNIZED will be returned.


parseClassVersion

public static JavaVersion parseClassVersion(int major,
                                            int minor)
Produce the JavaVersion corresponding to the given class version pair. For example, 49,0 maps to JAVA_5. If the pair cannot be matched, UNRECOGNIZED will be returned.


parseClassVersion

public static JavaVersion parseClassVersion(File classFile)
Produce the JavaVersion corresponding to the given class file.


parseClassVersion

public static JavaVersion parseClassVersion(InputStream is)
Produce the JavaVersion corresponding to the given class file.


parseFullVersion

public static JavaVersion.FullVersion parseFullVersion(String java_version,
                                                       String java_runtime_name,
                                                       String java_vm_vendor,
                                                       File location)
Produce the JavaVersion.FullVersion corresponding to the given version string. Accepts input of the form "1.6.0", "1.4.2_10", or "1.5.0_05-ea". The underscore may be replaced by a dot. If the text cannot be parsed, a trivial version with major version UNRECOGNIZED is returned. The location of the JDK, which may be null, will be stored in the version.

See Also:
The Sun version specification

parseFullVersion

public static JavaVersion.FullVersion parseFullVersion(String java_version,
                                                       String java_runtime_name,
                                                       String java_vm_vendor)
Produce the JavaVersion.FullVersion corresponding to the given version string. Accepts input of the form "1.6.0", "1.4.2_10", or "1.5.0_05-ea". The underscore may be replaced by a dot. If the text cannot be parsed, a trivial version with major version UNRECOGNIZED is returned. The location of the JDK is null and will be stored in the version.

See Also:
The Sun version specification

parseFullVersion

public static JavaVersion.FullVersion parseFullVersion(String text)
Produce the JavaVersion.FullVersion corresponding to the given version string. Accepts input of the form "1.6.0", "1.4.2_10", or "1.5.0_05-ea". The underscore may be replaced by a dot. If the text cannot be parsed, a trivial version with major version UNRECOGNIZED is returned.

See Also:
The Sun version specification