org.crosswire.common.util
Class Version

java.lang.Object
  extended by org.crosswire.common.util.Version
All Implemented Interfaces:
Comparable<Version>

public class Version
extends Object
implements Comparable<Version>

Version is an immutable representation of dotted "number" consisting of 1 to 4 parts.

Here is the grammar for version strings:

 version ::= major('.'minor('.'micro('.'nano)?)?)?
 major ::= [0-9]+
 minor ::= [0-9]+
 micro ::= [0-9]+
 nano  ::= [0-9]+
 

Author:
DM Smith
See Also:
The GNU Lesser General Public License for details.

Field Summary
private  String original
           
private  int[] parts
           
static Pattern VERSION_PATTERN
           
 
Constructor Summary
Version(String version)
          Created a version identifier from the specified string.
 
Method Summary
 int compareTo(Version object)
          Compares this Version object to another object.
 boolean equals(Object object)
          Compares this Version object to another object.
 int hashCode()
           
 String toString()
          Returns the original string representation of this version identifier.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION_PATTERN

public static final Pattern VERSION_PATTERN

original

private final String original

parts

private final int[] parts
Constructor Detail

Version

public Version(String version)
Created a version identifier from the specified string.

Parameters:
version - String representation of the version identifier.
Throws:
IllegalArgumentException - If version is improperly formatted.
Method Detail

toString

public String toString()
Returns the original string representation of this version identifier.

Overrides:
toString in class Object
Returns:
The original string representation of this version identifier.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object object)
Compares this Version object to another object.

A version is considered to be equal to another version if all the parts are equal.

Overrides:
equals in class Object
Parameters:
object - The Version object to be compared.
Returns:
true if the two objects are equal.

compareTo

public int compareTo(Version object)
Compares this Version object to another object.

The comparison considers each of the parts (major, minor, micro, nano) in turn, comparing like with like. At any point the comparison is not equal, a result is known.

Specified by:
compareTo in interface Comparable<Version>
Parameters:
object - The Version object to be compared.
Returns:
A negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified Version object.
Throws:
ClassCastException - If the specified object is not a Version.

Copyright ยจ 2003-2015