gecco.util
Class VersionNumber

java.lang.Object
  |
  +--gecco.util.VersionNumber
All Implemented Interfaces:
Comparable
Direct Known Subclasses:
GeccoVersion, JavaVersion

public class VersionNumber
extends Object
implements Comparable

A utility class for holding, parsing and comparing version numbers.

Author:
Karl Hasselström

Constructor Summary
VersionNumber()
          Constructs an empty version number.
VersionNumber(int major)
          Constructs a version number with only a major number, such as "3".
VersionNumber(int major, int minor)
          Constructs a version number with a major and a minor number, such as "3.1".
VersionNumber(int major, int minor1, int minor2)
          Constructs a version number with a major and two minor numbers, such as "3.1.41".
VersionNumber(String version)
          Constructs a version number from a String, such as "3.14.15".
 
Method Summary
 boolean atLeast(VersionNumber other)
          Determines if this VersionNumber is greater than or equal to the other VersionNumber.
 int compareTo(Object o)
          Compares this object with another object.
 int compareTo(VersionNumber other)
          Compares this VersionNumber with another VersionNumber.
 boolean equals(Object o)
          Determines whether this object is equal to another object.
 boolean greaterThan(VersionNumber other)
          Determines if this VersionNumber is greater than the other VersionNumber.
 int hashCode()
          Computes the hash code of this VersionNumber.
 boolean lessThan(VersionNumber other)
          Determines if this VersionNumber is less than the other VersionNumber.
 String toString()
          Returns the String representation of this VersionNumber.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VersionNumber

public VersionNumber()
Constructs an empty version number.


VersionNumber

public VersionNumber(int major)
Constructs a version number with only a major number, such as "3".

Parameters:
major - The major version number.

VersionNumber

public VersionNumber(int major,
                     int minor)
Constructs a version number with a major and a minor number, such as "3.1".

Parameters:
major - The major version number.
minor - The minor version number.

VersionNumber

public VersionNumber(int major,
                     int minor1,
                     int minor2)
Constructs a version number with a major and two minor numbers, such as "3.1.41".

Parameters:
major - The major version number.
minor1 - The most significant minor version number.
minor2 - The least significant minor version number.

VersionNumber

public VersionNumber(String version)
              throws NumberFormatException
Constructs a version number from a String, such as "3.14.15". The String consists of a sequence of integers, separated by periods.

Parameters:
version - The String to be parsed.
Throws:
NumberFormatException - If the parts of the String separated by periods could not be parsed as integers.
Method Detail

compareTo

public int compareTo(Object o)
Compares this object with another object. Will throw a ClassCastException if the other object is not a VersionNumber.

Specified by:
compareTo in interface Comparable
Parameters:
o - The other object.
Returns:
0 if the two objects are equal, negative if this object is less than the other object, and positive if this object is greater than the other object.

compareTo

public int compareTo(VersionNumber other)
Compares this VersionNumber with another VersionNumber.

Parameters:
other - The other VersionNumber.
Returns:
0 if the two VersionNumbers are equal, negative if this VersionNumber is less than the other VersionNumber, and positive if this VersionNumber is greater than the other VersionNumber.

lessThan

public boolean lessThan(VersionNumber other)
Determines if this VersionNumber is less than the other VersionNumber.

Parameters:
other - The other VersionNumber.
Returns:
true if this VersionNumber is less than the other VersionNumber, false otherwise.

greaterThan

public boolean greaterThan(VersionNumber other)
Determines if this VersionNumber is greater than the other VersionNumber.

Parameters:
other - The other VersionNumber.
Returns:
true if this VersionNumber is greater than the other VersionNumber, false otherwise.

atLeast

public boolean atLeast(VersionNumber other)
Determines if this VersionNumber is greater than or equal to the other VersionNumber.

Parameters:
other - The other VersionNumber.
Returns:
true if this VersionNumber is greater than or equal to the other VersionNumber, false otherwise.

equals

public boolean equals(Object o)
Determines whether this object is equal to another object.

Overrides:
equals in class Object
Parameters:
o - The other object.
Returns:
true if the objects are equal, false otherwise.

hashCode

public int hashCode()
Computes the hash code of this VersionNumber.

Overrides:
hashCode in class Object
Returns:
An int suitable for use as a hash code.

toString

public String toString()
Returns the String representation of this VersionNumber.

Overrides:
toString in class Object
Returns:
The String representation of this VersionNumber.