TUM CCSM Commons

edu.tum.cs.commons.version
Class Version

java.lang.Object
  extended by edu.tum.cs.commons.version.Version
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Version>

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

A class to describe versions of software (or other) artifacts. A version has a major and a minor version number. Version are ordered. This class is immutable.

Version:
$Rev: 26283 $
Author:
Florian Deissenboeck, $Author: juergens $
See Also:
Serialized Form
Rating:
GREEN Hash: 9B19160CC477DC98C73F68A0DCD4C759

Constructor Summary
Version(int major, int minor)
          Create a new version.
 
Method Summary
 int compareTo(Version other)
          Compares to version numbers by their major and minor numbers.
 boolean equals(java.lang.Object other)
          Two version are equal if their major and minor version numbers are equal.
 int getMajor()
          Get major version number.
 int getMinor()
          Get minor version number.
 int hashCode()
          Hashcode is (major << 7) | minor;
 boolean isSatisfied(Version currentVersion, Version compatibleVersion)
          This method is used to check version compatibility in dependency management.
static Version parseVersion(java.lang.String s)
          Parses a version from a string.
 java.lang.String toString()
          String representation: major.minor
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Version

public Version(int major,
               int minor)
Create a new version.

Parameters:
major - major version number.
minor - minor version number.
Throws:
java.lang.IllegalArgumentException - if one of the version numbers is less than 0.
Method Detail

parseVersion

public static Version parseVersion(java.lang.String s)
                            throws FormatException
Parses a version from a string. The format has to be "major.minor".

Throws:
FormatException - if the string does not follow the expected pattern.

compareTo

public int compareTo(Version other)
Compares to version numbers by their major and minor numbers.

Specified by:
compareTo in interface java.lang.Comparable<Version>

equals

public boolean equals(java.lang.Object other)
Two version are equal if their major and minor version numbers are equal.

Overrides:
equals in class java.lang.Object

getMajor

public int getMajor()
Get major version number.


getMinor

public int getMinor()
Get minor version number.


hashCode

public int hashCode()
Hashcode is (major << 7) | minor;

Overrides:
hashCode in class java.lang.Object

isSatisfied

public boolean isSatisfied(Version currentVersion,
                           Version compatibleVersion)
This method is used to check version compatibility in dependency management.

Consider the following situation and artefact A (the depender) depends on another artefact B (the dependee). A claims that it requires B in version 1.3. B states that it has version 1.5 but is downward compatible to version 1.1.

Using this method one can find out if the version provided by B satisfies A's requirement. It is satisfied iff

 requiredVersion <= currentVersion && requiredVersion >= compatibleVersion
 
where requiredVersion is this instance and the other two are provided as method parameters.

Throws:
java.lang.IllegalArgumentException - if compatibleVersion is greater than currentVersion.

toString

public java.lang.String toString()
String representation: major.minor

Overrides:
toString in class java.lang.Object

TUM CCSM Commons

TUM CCSM Commons - 2.7