org.homeunix.thecave.moss.util
Class Version

java.lang.Object
  extended by org.homeunix.thecave.moss.util.Version
All Implemented Interfaces:
java.lang.Comparable<Version>

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

Author:
wyatt A simple class which allows you to define the current version. This implements Comparable for comparison between versions.

Constructor Summary
Version(java.io.InputStream is)
          Creates a new Version object, parsing the given input stream for the first occurence of a version pattern.
Version(int major, int minor, int release, int patch)
          Specifies the version number using four integers.
Version(java.lang.String version)
          Returns a new Version object using the specified string as a version number.
 
Method Summary
 int compareTo(Version o)
           
 boolean equals(java.lang.Object obj)
           
 java.lang.Integer getMajor()
           
 java.lang.Integer getMinor()
           
 java.lang.Integer getPatch()
           
 java.lang.Integer getRelease()
           
static Version getVersionResource(java.lang.String resourceName)
          Returns a Version object obtained from a file resource.
 boolean isGreaterMajor(Version compareTo)
           
 boolean isGreaterMinor(Version compareTo)
           
 boolean isGreaterPatch(Version compareTo)
           
 boolean isGreaterRelease(Version compareTo)
           
 boolean isSameMajor(Version compareTo)
           
 boolean isSameMinor(Version compareTo)
           
 boolean isSamePatch(Version compareTo)
           
 boolean isSameRelease(Version compareTo)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Version

public Version(java.io.InputStream is)
Creates a new Version object, parsing the given input stream for the first occurence of a version pattern. We define a version pattern as something which matches the regex "\d+\.\d+\.\d+\.\d+" (not including quotes). If there is an I/O error, or the string is not found, we return 0.0.0.0 as the version.

Parameters:
is -

Version

public Version(java.lang.String version)
Returns a new Version object using the specified string as a version number. The string should be in the form "X.Y.R.P", where X is the Major version, Y is the minor version, R is the release number, and P is the Patch number - for instance, "2.6.12.0". You can also include fewer numbers in the string - this will result in the less signifigant digits being set to zero. For instance, the string "2.6" is functionally equivalent to "2.6.0.0".

Parameters:
version -

Version

public Version(int major,
               int minor,
               int release,
               int patch)
Specifies the version number using four integers.

Parameters:
major -
minor -
release -
patch -
Method Detail

getVersionResource

public static Version getVersionResource(java.lang.String resourceName)
Returns a Version object obtained from a file resource. This file can either be on the file system itself, or within the main .jar file. This is a convenience method to call the InputStream constructor of Version twice; first we try to load from the .jar file by prepending a / to the resourceNam, and if that does not work, we try to load from a FileInputStream, relative to the current working directory. This resource should be just the name and (optionally) leading relative path. For instance, if you were loading this file from the root of your project, and the file is called 'version.txt', just pass the string 'version.txt'.

Parameters:
resourceName -
Returns:

getMajor

public java.lang.Integer getMajor()

getMinor

public java.lang.Integer getMinor()

getPatch

public java.lang.Integer getPatch()

getRelease

public java.lang.Integer getRelease()

toString

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

compareTo

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

equals

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

isSameMajor

public boolean isSameMajor(Version compareTo)

isSameMinor

public boolean isSameMinor(Version compareTo)

isSameRelease

public boolean isSameRelease(Version compareTo)

isSamePatch

public boolean isSamePatch(Version compareTo)

isGreaterMajor

public boolean isGreaterMajor(Version compareTo)

isGreaterMinor

public boolean isGreaterMinor(Version compareTo)

isGreaterRelease

public boolean isGreaterRelease(Version compareTo)

isGreaterPatch

public boolean isGreaterPatch(Version compareTo)