at.spardat.xma.boot.cache
Class VersionNumber

java.lang.Object
  extended byat.spardat.xma.boot.cache.VersionNumber
All Implemented Interfaces:
java.lang.Comparable

public class VersionNumber
extends java.lang.Object
implements java.lang.Comparable

Support for version numbers in resource file names. It supports parsing of version numbers, insertion of version number for delta files, insertion of hash values into the filename and matching of file names that differ only in version numbers or hash values.

Since:
1.3.0

Constructor Summary
VersionNumber(int major, int minor, int bugfix)
          Constructs a VersionNumber with the given major, minor and bugfix number.
 
Method Summary
 int compareTo(java.lang.Object other)
          Compares this VersionNumber to an other.
 boolean equals(java.lang.Object other)
          Tests if this VersionNumber is equal to an other
 int hashCode()
          Gives a hash code value of this object.
 java.net.URL insertAsDelta(java.net.URL url)
          Insert this version number into the given url to make it specifie the delta file to the file given in the url.
static java.lang.String insertHash(java.lang.String filename, java.lang.String hash)
          Inserts the given hash value into the given filename.
static java.util.regex.Pattern matchWithoutHashPattern(java.lang.String filename)
          Creates a search pattern that matches all file defined by the given filename regardless of any included hash value.
static VersionNumber parse(java.lang.String filename)
          Parses the version number out of the given filename.
static java.util.regex.Pattern searchPattern(java.lang.String filename)
          Creates a search pattern that matches all other versions of the file defined by the given filename.
 java.lang.String toString()
          Gives this version number as string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VersionNumber

public VersionNumber(int major,
                     int minor,
                     int bugfix)
Constructs a VersionNumber with the given major, minor and bugfix number.

Parameters:
major - part of the version
minor - part of the version
bugfix - part of the version
Method Detail

parse

public static VersionNumber parse(java.lang.String filename)
Parses the version number out of the given filename.

Parameters:
filename - the filename to parse
Returns:
the parsed version number or null if no version number is contained in the filename

searchPattern

public static java.util.regex.Pattern searchPattern(java.lang.String filename)
Creates a search pattern that matches all other versions of the file defined by the given filename. Files with and without contained hash value in its name are matched. The filename must not contain any path (/ or \ charchters)

Parameters:
filename - to generate the search pattern for
Returns:
a pattern matching all other versions of the given file

insertAsDelta

public java.net.URL insertAsDelta(java.net.URL url)
Insert this version number into the given url to make it specifie the delta file to the file given in the url. e.g. http://localhost/myapp/test_1.2.0.jar -> http://localhost/myapp/test_1.1.0-1.2.0.xdelta.jar

Parameters:
url - to convert into a delta download url
Returns:
the modified url

insertHash

public static java.lang.String insertHash(java.lang.String filename,
                                          java.lang.String hash)
Inserts the given hash value into the given filename. The hash value is inserted just bevor the last file extention. If the file has no extention the hash value is appended.

Parameters:
filename - to insert the hash value into
hash - to insert into the filename
Returns:
the modified filename

matchWithoutHashPattern

public static java.util.regex.Pattern matchWithoutHashPattern(java.lang.String filename)
Creates a search pattern that matches all file defined by the given filename regardless of any included hash value. The filename must not contain any path (/ or \ charchters)

Parameters:
filename - to generate the search pattern for
Returns:
a pattern matching all other versions of the given file

toString

public java.lang.String toString()
Gives this version number as string.

Returns:
major.minor.bugfix

compareTo

public int compareTo(java.lang.Object other)
Compares this VersionNumber to an other.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
other - the VersionNumber to compare to.
Returns:
-1 if this VersionNumber is less than the other
0 if this VersionNumber is equal to the other
1 if this VersionNumber is greater than the other
Throws:
java.lang.ClassCastException - if the parameter is not a VersionNumber.

equals

public boolean equals(java.lang.Object other)
Tests if this VersionNumber is equal to an other

Parameters:
other - the VersionNumber to compare to.
Returns:
true if major, minor and bugfix are equal to the respective fields of the other VersionNumber.

hashCode

public int hashCode()
Gives a hash code value of this object. The hash value is determined by the values of major, minor and bugfix. If two VersionNumbers are equal, they have the same hash code value.