com.sibvisions.util
Class Version

java.lang.Object
  extended by com.sibvisions.util.Version
All Implemented Interfaces:
Comparable<Version>

public class Version
extends Object
implements Comparable<Version>

The Version class is a simple representation for version numbers. It supports major, minor, build and revision sequences, e.g. 2.0.0.1. The class supports parsing version strings.


Nested Class Summary
static class Version.Level
          the supported version levels.
 
Constructor Summary
Version(int pMajor)
          Creates a new instance of Version with given major number.
Version(int pMajor, int pMinor)
          Creates a new instance of Version with given major and minor numbers.A negative number means ignore.
Version(int pMajor, int pMinor, int pBuild)
          Creates a new instance of Version with given numbers.
Version(int pMajor, int pMinor, int pBuild, int pRevision)
          Creates a new instance of Version with given numbers.
 
Method Summary
 int compareTo(Version pVersion)
          
 int compareTo(Version pVersion, Version.Level pLevel)
          Compares this version with another version.
 boolean equals(Object pObject)
          
 int getBuild()
          Gets the build number (x.x.3.x).
 Version.Level getLevel()
          Gets the level of the last significant sequence, e.g. 2.0.1 will return Version.Level.Build.
 int getMajor()
          Gets the major number (1.x.x.x).
 int getMinor()
          Gets the minor number (x.2.x.x).
 int getRevision()
          Gets the revision number (x.x.x.4).
 int hashCode()
          
 boolean isGreater(Version pVersion)
          Gets whether the current (this) version is greater than the given version.
 boolean isGreaterOrEqual(Version pVersion)
          Gets whether the current (this) version is greater or equal than the given version.
 boolean isSmaller(Version pVersion)
          Gets whether the current (this) version is smaller than the given version.
 boolean isSmallerOrEqual(Version pVersion)
          Gets whether the current (this) version is smaller or equal than the given version.
 boolean isUndefined()
          Gets whether the version is undefined.
static Version parse(String pVersion)
          Parses a version number.
 int toNumber()
          Gets the full version number.
 int toNumber(Version.Level pLevel)
          Gets the number representation of the version.
 String toString()
          Gets the version number as full string wih all sequences (major, minor, build, revision).
 String toString(boolean pShort)
          Gets a version for given level.
 String toString(Version.Level pLevel)
          Gets a version for given level.
 String toString(Version.Level pLevel, boolean pShort)
          Gets a version string with all sequences up-to the given level.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Version

public Version(int pMajor)
Creates a new instance of Version with given major number. A negative number means ignore.

Parameters:
pMajor - the major number

Version

public Version(int pMajor,
               int pMinor)
Creates a new instance of Version with given major and minor numbers.A negative number means ignore.

Parameters:
pMajor - the major number
pMinor - the minor number

Version

public Version(int pMajor,
               int pMinor,
               int pBuild)
Creates a new instance of Version with given numbers. A negative number means ignore.

Parameters:
pMajor - the major number
pMinor - the minor number
pBuild - the build number

Version

public Version(int pMajor,
               int pMinor,
               int pBuild,
               int pRevision)
Creates a new instance of Version with given numbers. A negative number means ignore.

Parameters:
pMajor - the major number
pMinor - the minor number
pBuild - the build number
pRevision - the revision number
Method Detail

toString

public String toString()
Gets the version number as full string wih all sequences (major, minor, build, revision).

Overrides:
toString in class Object
Returns:
the version string

hashCode

public int hashCode()

Overrides:
hashCode in class Object

equals

public boolean equals(Object pObject)

Overrides:
equals in class Object

compareTo

public int compareTo(Version pVersion)

Specified by:
compareTo in interface Comparable<Version>

parse

public static Version parse(String pVersion)
Parses a version number. Only number parts are allowed, e.g. 2.0.0.1. If the version contains more than 4 parts, all other parts will be ignored. If a part isn't a number, it will be ignored (set to -1).

Parameters:
pVersion - the version string
Returns:
the version

toString

public String toString(Version.Level pLevel,
                       boolean pShort)
Gets a version string with all sequences up-to the given level.

Parameters:
pLevel - the version level
pShort - true to stop after the last sequence that contains a valid number (> 0).
Returns:
the version string

toString

public String toString(Version.Level pLevel)
Gets a version for given level. All sequences will be used even if they are invalid. No sequences will be ignored.

Parameters:
pLevel - the level
Returns:
the version string

toString

public String toString(boolean pShort)
Gets a version for given level.

Parameters:
pShort - true to stop after the last sequence that contains a valid number (> 0).
Returns:
the version string

getLevel

public Version.Level getLevel()
Gets the level of the last significant sequence, e.g. 2.0.1 will return Version.Level.Build.

Returns:
the level

isUndefined

public boolean isUndefined()
Gets whether the version is undefined. A version is undefined if all version parts contain negative numbers.

Returns:
true if version is undefined, false otherwise

toNumber

public int toNumber()
Gets the full version number.

Returns:
the version number

toNumber

public int toNumber(Version.Level pLevel)
Gets the number representation of the version.

Parameters:
pLevel - the expected depth/level
Returns:
the number e.g. 2.1.0.2 = 2102

compareTo

public int compareTo(Version pVersion,
                     Version.Level pLevel)
Compares this version with another version.

Parameters:
pVersion - the to compare
pLevel - the check depth/level
Returns:
-1 if this version is lower than the other version, 0 if both versions are equal, 1 if this version is larger than the other version

getMajor

public int getMajor()
Gets the major number (1.x.x.x).

Returns:
the number (e.g. 1)

getMinor

public int getMinor()
Gets the minor number (x.2.x.x).

Returns:
the minor number (e.g. 2)

getBuild

public int getBuild()
Gets the build number (x.x.3.x).

Returns:
the build number (e.g. 3)

getRevision

public int getRevision()
Gets the revision number (x.x.x.4).

Returns:
the revision number (e.g. 4)

isSmaller

public boolean isSmaller(Version pVersion)
Gets whether the current (this) version is smaller than the given version.

Parameters:
pVersion - the "greater" version
Returns:
true if this version is smaller than the given, false otherwise

isSmallerOrEqual

public boolean isSmallerOrEqual(Version pVersion)
Gets whether the current (this) version is smaller or equal than the given version.

Parameters:
pVersion - the smaller or equal version
Returns:
true if this version is smaller than the given, false otherwise

isGreater

public boolean isGreater(Version pVersion)
Gets whether the current (this) version is greater than the given version.

Parameters:
pVersion - the "smaller" version
Returns:
true if this version is greater than the given, false otherwise

isGreaterOrEqual

public boolean isGreaterOrEqual(Version pVersion)
Gets whether the current (this) version is greater or equal than the given version.

Parameters:
pVersion - the greater or equal version
Returns:
true if this version is greater than the given, false otherwise


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.