com.partnersoft.system
Class Version

java.lang.Object
  extended by com.partnersoft.system.Version
All Implemented Interfaces:
Immutable, java.lang.Comparable<Version>

public class Version
extends java.lang.Object
implements Immutable, java.lang.Comparable<Version>

A software version identifier.

This follows the more-or-less classic form of major.minor.release (e.g. 1.2.3). In general major versions indicate substantial platform changes, generally with incompatibilities between them. Minor versions indicate branches of the software. Often odd numbers are used to indicate unstable branches, while even numbers indicate stable branches. The release number is incremented for each release.

Note that these aren't ordinary decimal numbers. They are independent integers separated by periods. Thus versions are ordered 1.1, 1.2... 1.10, 1.11 - 1.1 is different from 1.10 and 1.2 comes before 1.19.

Missing pieces are represented by -1. This is only valid in the trailing versions - you can't have a version with no major version, and you can't have a version with major and release versions and no minor version.

A build property is also provided; this can store optional build or revision data.

There are a variety of interesting comparisons you can make between versions.

Copyright 2007 Partner Software, Inc.

Version:
$Id: Version.java 1390 2008-07-04 15:25:31Z paul $
Author:
Brad Gray, Paul Reavis

Constructor Summary
Version(int major)
          Creates a new version with the given major version, no minor or release versions.
Version(int major, int minor)
          Creates a new version with the given major version, minor version, and no release version.
Version(int major, int minor, int release)
          Creates a new version with the given major, minor and release versions.
Version(java.lang.String versionNumber)
          Creates a version from the provided String.
Version(java.lang.String versionNumber, java.lang.String build)
          Creates a version from the provided version and build strings.
 
Method Summary
 int compareTo(Version nother)
           
 boolean equals(java.lang.Object nother)
           
 java.lang.String getBuild()
          Returns the build info, which is an arbitrarily-formatted string.
 int getMajor()
          Returns the major version number.
 int getMinor()
          Returns the minor version number, or -1 if there is none.
 int getRelease()
          Returns the release version number, or -1 if there is none.
 java.lang.String getVersionString()
          Returns this version as a string in major.minor.release (e.g.
 int hashCode()
           
 boolean majorMatches(Version nother)
          Returns true if the version given matches this one's major version.
 boolean minorMatches(Version nother)
          Returns true if the version given matches this one's major and minor versions.
 boolean releaseMatches(Version nother)
          Returns true if the version given matches this one's major, minor, and release versions.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Version

public Version(java.lang.String versionNumber,
               java.lang.String build)
Creates a version from the provided version and build strings. The version string must be in the correct format - 1-3 integers separated by periods (e.g. "1", "1.2", "1.2.3", etc.). Incorrect formats will reward you with an IllegalArgumentException.


Version

public Version(java.lang.String versionNumber)
Creates a version from the provided String. It must be in the correct format - 1-3 integers separated by periods (e.g. "1", "1.2", "1.2.3", etc.). Incorrect formats will reward you with an IllegalArgumentException.


Version

public Version(int major)
Creates a new version with the given major version, no minor or release versions.


Version

public Version(int major,
               int minor)
Creates a new version with the given major version, minor version, and no release version.


Version

public Version(int major,
               int minor,
               int release)
Creates a new version with the given major, minor and release versions.

Method Detail

majorMatches

public boolean majorMatches(Version nother)
Returns true if the version given matches this one's major version.


minorMatches

public boolean minorMatches(Version nother)
Returns true if the version given matches this one's major and minor versions. Also returns true if the major versions match and this version has no minor version (minor == -1).


releaseMatches

public boolean releaseMatches(Version nother)
Returns true if the version given matches this one's major, minor, and release versions. Also returns true if the major versions match and this version has no minor version, or if the major and minor versions match and this version has no release version.


compareTo

public int compareTo(Version nother)
Specified by:
compareTo in interface java.lang.Comparable<Version>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object nother)
Overrides:
equals in class java.lang.Object

getVersionString

public java.lang.String getVersionString()
Returns this version as a string in major.minor.release (e.g. 1.2.3) format.


getMajor

public int getMajor()
Returns the major version number.

Returns:
major version

getMinor

public int getMinor()
Returns the minor version number, or -1 if there is none.

Returns:
minor version

getRelease

public int getRelease()
Returns the release version number, or -1 if there is none.

Returns:
release version

getBuild

public java.lang.String getBuild()
Returns the build info, which is an arbitrarily-formatted string.