rebuild.util
Class Version

java.lang.Object
  extended by rebuild.util.Version
All Implemented Interfaces:
java.lang.Comparable

public final class Version
extends java.lang.Object
implements java.lang.Comparable

Represents the version number.

Since:
BBX 1.0.1

Constructor Summary
Version()
          Initializes a new instance of the Version class.
Version(int major, int minor)
          Initializes a new instance of the Version class using the specified major and minor values.
Version(int major, int minor, int build)
          Initializes a new instance of the Version class using the specified major, minor, and build values.
Version(int major, int minor, int build, int revision)
          Initializes a new instance of the Version class with the specified major, minor, build, and revision numbers.
Version(java.lang.String version)
          Initializes a new instance of the Version class using the specified string.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares the current Version object to a specified object and returns an indication of their relative values.
 int compareTo(Version o)
          Compares the current Version object to a specified Version object and returns an indication of their relative values.
 boolean equals(java.lang.Object obj)
          Returns a value indicating whether the current Version object is equal to a specified object.
 boolean equals(Version obj)
          Returns a value indicating whether the current Version object and a specified Version object represent the same value.
 int getBuild()
          Gets the value of the build component of the version number for the current Version object.
 int getMajor()
          Gets the value of the major component of the version number for the current Version object.
 short getMajorRevision()
          Gets the high 16 bits of the revision number.
 int getMinor()
          Gets the value of the minor component of the version number for the current Version object.
 short getMinorRevision()
          Gets the low 16 bits of the revision number.
 int getRevision()
          Gets the value of the revision component of the version number for the current Version object.
static boolean greaterThan(Version v1, Version v2)
          Determines whether the first specified Version object is greater than the second specified Version object.
static boolean greaterThanOrEqual(Version v1, Version v2)
          Determines whether the first specified Version object is greater than or equal to the second specified Version object.
 int hashCode()
          Returns a hash code for the current Version object.
static boolean lessThan(Version v1, Version v2)
          Determines whether the first specified Version object is less than the second specified Version object.
static boolean lessThanOrEqual(Version v1, Version v2)
          Determines whether the first specified Version object is less than or equal to the second specified Version object.
 java.lang.String toString()
          Converts the value of the current Version object to its equivalent String representation.
 java.lang.String toString(int fieldCount)
          Converts the value of the current Version object to its equivalent String representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Version

public Version()
Initializes a new instance of the Version class.


Version

public Version(java.lang.String version)
Initializes a new instance of the Version class using the specified string.

Parameters:
version - A string containing the major, minor, build, and revision numbers, where each number is delimited with a period character ('.').
Throws:
java.lang.NullPointerException - version is null.
java.lang.IllegalArgumentException -
  • version has fewer than two components or more than four components
  • A major, minor, build, or revision component is less than zero.

Version

public Version(int major,
               int minor)
Initializes a new instance of the Version class using the specified major and minor values.

Parameters:
major - The major version number.
minor - The minor version number.
Throws:
java.lang.IllegalArgumentException - major or minor is less than zero.

Version

public Version(int major,
               int minor,
               int build)
Initializes a new instance of the Version class using the specified major, minor, and build values.

Parameters:
major - The major version number.
minor - The minor version number.
build - The build number.
Throws:
java.lang.IllegalArgumentException - major, minor, or build is less than zero.

Version

public Version(int major,
               int minor,
               int build,
               int revision)
Initializes a new instance of the Version class with the specified major, minor, build, and revision numbers.

Parameters:
major - The major version number.
minor - The minor version number.
build - The build number.
revision - The revision number.
Throws:
java.lang.IllegalArgumentException - major, minor, build, or revision is less than zero.
Method Detail

compareTo

public int compareTo(java.lang.Object o)
Compares the current Version object to a specified object and returns an indication of their relative values.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - An object to compare, or null.
Returns:
Return ValueDescription
Less than zeroThe current Version object is a version before o.
ZeroThe current Version object is the same version as o.
Greater than zero

The current Version object is a version subsequent to o.

-or-

o is null.

Throws:
java.lang.IllegalArgumentException - version is not of type Version.

compareTo

public int compareTo(Version o)
Compares the current Version object to a specified Version object and returns an indication of their relative values.

Parameters:
o - A Version object to compare to the current Version object, or null.
Returns:
Return ValueDescription
Less than zeroThe current Version object is a version before o.
ZeroThe current Version object is the same version as o.
Greater than zero

The current Version object is a version subsequent to o.

-or-

o is null.


equals

public boolean equals(java.lang.Object obj)
Returns a value indicating whether the current Version object is equal to a specified object.

Overrides:
equals in class java.lang.Object
Parameters:
obj - An object to compare with the current Version object, or null.
Returns:
true if the current Version object and obj are both Version objects, and every component of the current Version object matches the corresponding component of obj; otherwise, false.

equals

public boolean equals(Version obj)
Returns a value indicating whether the current Version object and a specified Version object represent the same value.

Parameters:
obj - A Version object to compare to the current Version object, or null.
Returns:
true if every component of the current Version object matches the corresponding component of the obj parameter; otherwise, false.

hashCode

public int hashCode()
Returns a hash code for the current Version object.

Overrides:
hashCode in class java.lang.Object
Returns:
A 32-bit signed integer hash code.

greaterThan

public static boolean greaterThan(Version v1,
                                  Version v2)
Determines whether the first specified Version object is greater than the second specified Version object.

Parameters:
v1 - The first Version object.
v2 - The second Version object.
Returns:
true if v1 is greater than v2; otherwise, false.

greaterThanOrEqual

public static boolean greaterThanOrEqual(Version v1,
                                         Version v2)
Determines whether the first specified Version object is greater than or equal to the second specified Version object.

Parameters:
v1 - The first Version object.
v2 - The second Version object.
Returns:
true if v1 is greater than or equal to v2; otherwise, false.

lessThan

public static boolean lessThan(Version v1,
                               Version v2)
Determines whether the first specified Version object is less than the second specified Version object.

Parameters:
v1 - The first Version object.
v2 - The second Version object.
Returns:
true if v1 is less than v2; otherwise, false.

lessThanOrEqual

public static boolean lessThanOrEqual(Version v1,
                                      Version v2)
Determines whether the first specified Version object is less than or equal to the second specified Version object.

Parameters:
v1 - The first Version object.
v2 - The second Version object.
Returns:
true if v1 is less than or equal to v2; otherwise, false.

toString

public java.lang.String toString()
Converts the value of the current Version object to its equivalent String representation.

Overrides:
toString in class java.lang.Object
Returns:
The String representation of the values of the major, minor, build, and revision components of the current Version object, as depicted in the following format. Each component is separated by a period character ('.'). Square brackets ('[' and ']') indicate a component that will not appear in the return value if the component is not defined: major.minor[.build[.revision]] For example, if you create a Version object using the constructor Version(1,1), the returned string is "1.1". If you create a Version object using the constructor Version(1,3,4,2), the returned string is "1.3.4.2".

toString

public java.lang.String toString(int fieldCount)
Converts the value of the current Version object to its equivalent String representation. A specified count indicates the number of components to return.

Parameters:
fieldCount - The number of components to return. The fieldCount ranges from 0 to 4.
Returns:

The String representation of the values of the major, minor, build, and revision components of the current Version object, each separated by a period character ('.'). The fieldCount parameter determines how many components are returned.

fieldCountReturn Value
0An empty string ("").
1major
2major.minor
3major.minor.build
4major.minor.build.revision

For example, if you create Version object using the constructor Version(1,3,5), ToString(2) returns "1.3" and ToString(4) throws an exception.

Throws:
java.lang.IllegalArgumentException -

fieldCount is less than 0, or more than 4.

-or-

fieldCount is more than the number of components defined in the current Version object.


getBuild

public int getBuild()
Gets the value of the build component of the version number for the current Version object.

Returns:
The build number, or -1 if the build number is undefined.

getMajor

public int getMajor()
Gets the value of the major component of the version number for the current Version object.

Returns:
The major version number.

getMajorRevision

public short getMajorRevision()
Gets the high 16 bits of the revision number.

Returns:
A 16-bit signed integer.

getMinor

public int getMinor()
Gets the value of the minor component of the version number for the current Version object.

Returns:
The minor version number.

getMinorRevision

public short getMinorRevision()
Gets the low 16 bits of the revision number.

Returns:
A 16-bit signed integer.

getRevision

public int getRevision()
Gets the value of the revision component of the version number for the current Version object.

Returns:
The revision number, or -1 if the revision number is undefined.