org.schmant.support
Class JdkVersion

java.lang.Object
  extended by org.schmant.support.JdkVersion

public final class JdkVersion
extends Object

An object of this type represents the version of a JDK.

Instances of this class are immutable. An instance may be created by using the constructor or (preferably) by using the static parseVersion(String) method.

JdkUtil has methods for determining the version of a Java installation.

Since:
0.7.1
Author:
Karl Gustafsson
See Also:
JdkUtil

Field Summary
static int SUPER_VERSION
          The super version number (1).
static JdkVersion VERSION_1_4
          JDK version 1.4.0.0.
static JdkVersion VERSION_1_5
          JDK version 1.5.0.0.
static JdkVersion VERSION_1_6
          JDK version 1.6.0.0.
static JdkVersion VERSION_1_7
          JDK version 1.7.0.0.
 
Constructor Summary
JdkVersion(int sup, int major, int minor, int update)
          Create a Java version object.
JdkVersion(String s)
          Parse the Java version string into a version object.
 
Method Summary
 boolean equals(Object o)
           
 int getMajor()
          Get the major version number, i.e.
 int getMinor()
          Get the minor version number, i.e.
 int getSuper()
          Get the super version number, i.e.
 int getUpdate()
          Get the update version number, i.e.
 int hashCode()
           
 boolean isNewerThan(JdkVersion v)
          Is this JDK version newer than the supplied version?
 boolean isOlderThan(JdkVersion v)
          Is this JDK version older than the supplied version?
 boolean isSameMajorAndMinorVersion(JdkVersion v)
          Does this JDK version object have the same major and minor version numbers as the supplied object? For instance, JDK 1.4.1_05 has the same major and minor version as JDK 1.4.1_04, but not the same minor version as JDK 1.4.2.
 boolean isSameMajorVersion(JdkVersion v)
          Does this JDK version object have the same major version as the supplied object? For instance, JDK 1.4.1 has the same major version as JDK 1.4.2, but not the same major version as JDK 1.5.
 boolean isSameOrNewerThan(JdkVersion v)
          Is this JDK version the same or newer than the supplied version?
 boolean isSameOrOlderThan(JdkVersion v)
          Is this JDK version the same or older than the supplied version?
static JdkVersion parseVersion(String s)
          Parse the version string into a JDK version object.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION_1_7

public static final JdkVersion VERSION_1_7
JDK version 1.7.0.0.


VERSION_1_6

public static final JdkVersion VERSION_1_6
JDK version 1.6.0.0.


VERSION_1_5

public static final JdkVersion VERSION_1_5
JDK version 1.5.0.0.


VERSION_1_4

public static final JdkVersion VERSION_1_4
JDK version 1.4.0.0.


SUPER_VERSION

public static final int SUPER_VERSION
The super version number (1).

See Also:
Constant Field Values
Constructor Detail

JdkVersion

public JdkVersion(String s)
           throws IllegalArgumentException
Parse the Java version string into a version object. The version string is formatted like the version string that running java -version returns, e.g. 1.5.0_14 for JDK 1.5.0_14 or 1.6.0_02 for JDK 1.6.0_02.

Partial version strings can be used to. For instance, "1" means JDK 1.0.0_0 and "1.6" means JDK 1.6.0_0.

Use the parseVersion(String) instead of calling this constructor directly.

Parameters:
s - The Java version string.
Throws:
IllegalArgumentException - If the version string cannot be parsed.
See Also:
parseVersion(String)

JdkVersion

public JdkVersion(int sup,
                  int major,
                  int minor,
                  int update)
           throws IllegalArgumentException
Create a Java version object.

Parameters:
sup - The super version number. Must be 1.
major - The major version number, for instance 6. Must be zero or greater.
minor - The minor version number, for instance 0. Must be zero or greater.
update - The update version number, for instance 22. Must be zero or greater.
Throws:
IllegalArgumentException - If any version number has an invalid value.
Method Detail

parseVersion

public static JdkVersion parseVersion(String s)
                               throws IllegalArgumentException
Parse the version string into a JDK version object.

Parameters:
s - The string to parse.
Returns:
The JDK version object.
Throws:
IllegalArgumentException - If the version string is invalid.
See Also:
JdkVersion(String)

getSuper

public int getSuper()
Get the super version number, i.e. 1.

Returns:
1.

getMajor

public int getMajor()
Get the major version number, i.e. 6 for JDK 1.6.

Returns:
The major version number.

getMinor

public int getMinor()
Get the minor version number, i.e. 2 for JDK 1.4.2 or 0 for JDK 1.6.

Returns:
The minor version number.

getUpdate

public int getUpdate()
Get the update version number, i.e. 14 for JDK 1.5.0_14.

Returns:
The update version number.

isNewerThan

public boolean isNewerThan(JdkVersion v)
Is this JDK version newer than the supplied version?

Parameters:
v - The JDK version to test against.
Returns:
true if this JDK version is newer than the supplied version.
See Also:
isSameOrNewerThan(JdkVersion), isOlderThan(JdkVersion)

isSameOrNewerThan

public boolean isSameOrNewerThan(JdkVersion v)
Is this JDK version the same or newer than the supplied version?

Parameters:
v - The JDK version to test against.
Returns:
true if this JDK version is the same or newer than the supplied version.
See Also:
isNewerThan(JdkVersion), isSameOrOlderThan(JdkVersion)

isOlderThan

public boolean isOlderThan(JdkVersion v)
Is this JDK version older than the supplied version?

Parameters:
v - The JDK version to test against.
Returns:
true if this JDK version is older than the supplied version.
See Also:
isSameOrOlderThan(JdkVersion), isNewerThan(JdkVersion)

isSameOrOlderThan

public boolean isSameOrOlderThan(JdkVersion v)
Is this JDK version the same or older than the supplied version?

Parameters:
v - The JDK version to test against.
Returns:
true if this JDK version is the same or older than the supplied version.
See Also:
isOlderThan(JdkVersion), isSameOrNewerThan(JdkVersion)

isSameMajorVersion

public boolean isSameMajorVersion(JdkVersion v)
Does this JDK version object have the same major version as the supplied object? For instance, JDK 1.4.1 has the same major version as JDK 1.4.2, but not the same major version as JDK 1.5.

Parameters:
v - The other JDK version object.
Returns:
true if the supplied JDK version object has the same major version as this object.
Since:
1.1
See Also:
isSameMajorAndMinorVersion(JdkVersion)

isSameMajorAndMinorVersion

public boolean isSameMajorAndMinorVersion(JdkVersion v)
Does this JDK version object have the same major and minor version numbers as the supplied object? For instance, JDK 1.4.1_05 has the same major and minor version as JDK 1.4.1_04, but not the same minor version as JDK 1.4.2.

Parameters:
v - The other JDK version object.
Returns:
true if the supplied JDK version object has the same major and minor version numbers as this object.
Since:
1.1
See Also:
isSameMajorVersion(JdkVersion)

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object