QJCC homepage

biz.chitec.quarterback.util
Class VersionUtilities

java.lang.Object
  extended bybiz.chitec.quarterback.util.VersionUtilities

public final class VersionUtilities
extends java.lang.Object

Tools for comparing version strings. Version strings are assumed to contain up to three numeric values: main version, subversion and patchlevel. The comparation methods feature a lexicographical comparation of these number in natural manner.

Version:
$Id: c00a85423ccfd8e92fbdf7dfe6548262f003a22f $
Author:
chitec/Dirk Hillbrecht 2001-2003, cantamen/Dirk Hillbrecht 2005

Constructor Summary
private VersionUtilities()
          Static class
 
Method Summary
static int compareVersions(int[] v1, int[] v2)
          Compare two version numbers and return value for result.
static int compareVersions(int v1, int s1, int p1, int v2, int s2, int p2)
          Compare two version numbers and return value for result.
static int compareVersions(java.lang.String v1, java.lang.String v2)
          Compare two version numbers and return value for result.
private static int[] evalVersion(java.lang.String v)
          Internal helper method for splitting a version number given as String.
static boolean firstLessThanOrEqualsSecond(int[] v1, int[] v2)
          Check difference between first and second version number.
static boolean firstLessThanOrEqualsSecond(int v1, int s1, int p1, int v2, int s2, int p2)
          Check difference between first and second version number.
static boolean firstLessThanOrEqualsSecond(java.lang.String v1, java.lang.String v2)
          Check difference between first and second version number.
static boolean firstLessThanSecond(int[] v1, int[] v2)
          Check difference between first and second version number.
static boolean firstLessThanSecond(int v1, int s1, int p1, int v2, int s2, int p2)
          Check difference between first and second version number.
static boolean firstLessThanSecond(java.lang.String v1, java.lang.String v2)
          Check difference between first and second version number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VersionUtilities

private VersionUtilities()
Static class

Method Detail

compareVersions

public static final int compareVersions(int v1,
                                        int s1,
                                        int p1,
                                        int v2,
                                        int s2,
                                        int p2)
Compare two version numbers and return value for result.

Parameters:
v1 - Main version of first version number
s1 - Subversion of first version number
p1 - Patch level of first version number
v2 - Main version of second version number
s2 - Subversion of second version number
p2 - Patch level of second version number
Returns:
-1 if first version number is smaller than second, 0 if both are equal, 1 if first if larger than second

firstLessThanSecond

public static final boolean firstLessThanSecond(int v1,
                                                int s1,
                                                int p1,
                                                int v2,
                                                int s2,
                                                int p2)
Check difference between first and second version number.

Parameters:
v1 - Main version of first version number
s1 - Subversion of first version number
p1 - Patch level of first version number
v2 - Main version of second version number
s2 - Subversion of second version number
p2 - Patch level of second version number
Returns:
true if first version number is smaller than second, false otherwise

firstLessThanOrEqualsSecond

public static final boolean firstLessThanOrEqualsSecond(int v1,
                                                        int s1,
                                                        int p1,
                                                        int v2,
                                                        int s2,
                                                        int p2)
Check difference between first and second version number.

Parameters:
v1 - Main version of first version number
s1 - Subversion of first version number
p1 - Patch level of first version number
v2 - Main version of second version number
s2 - Subversion of second version number
p2 - Patch level of second version number
Returns:
true if first version number is smaller than or equal to second, false otherwise

evalVersion

private static final int[] evalVersion(java.lang.String v)
Internal helper method for splitting a version number given as String.


compareVersions

public static final int compareVersions(java.lang.String v1,
                                        java.lang.String v2)
Compare two version numbers and return value for result. The version numbers are given as Strings containing a numerical main version, a subversion, and a patch level, e.g. "1.4.2". Seperating character can be ".", "_", or " ". Missing parts of the number are handled as "0".

Parameters:
v1 - First version as String
v2 - Second version as String
Returns:
-1 if first version number is smaller than second, 0 if both are equal, 1 if first if larger than second

compareVersions

public static final int compareVersions(int[] v1,
                                        int[] v2)
Compare two version numbers and return value for result. The version numbers are given as arrays of integer numbers. The lower the array index, the more important the corresponding number. Non-existant numbers are handled as "0".

Parameters:
v1 - First version as array of ints.
v2 - Second version as array of ints.
Returns:
-1 if first version number is smaller than second, 0 if both are equal, 1 if first if larger than second

firstLessThanSecond

public static final boolean firstLessThanSecond(java.lang.String v1,
                                                java.lang.String v2)
Check difference between first and second version number. The version numbers are given as Strings containing a numerical main version, a subversion, and a patch level, e.g. "1.4.2". Seperating character can be ".", "_", or " ". Missing parts of the number are handled as "0".

Parameters:
v1 - First version as String
v2 - Second version as String
Returns:
true if first version number is smaller than second, false otherwise

firstLessThanSecond

public static final boolean firstLessThanSecond(int[] v1,
                                                int[] v2)
Check difference between first and second version number. The version numbers are given as arrays of integer numbers. The lower the array index, the more important the corresponding number. Non-existant numbers are handled as "0".

Parameters:
v1 - First version as array of ints.
v2 - Second version as array of ints.
Returns:
true if first version number is smaller than second, false otherwise

firstLessThanOrEqualsSecond

public static final boolean firstLessThanOrEqualsSecond(java.lang.String v1,
                                                        java.lang.String v2)
Check difference between first and second version number. The version numbers are given as Strings containing a numerical main version, a subversion, and a patch level, e.g. "1.4.2". Seperating character can be ".", "_", or " ". Missing parts of the number are handled as "0".

Parameters:
v1 - First version as String
v2 - Second version as String
Returns:
true if first version number is smaller than or equal to second, false otherwise

firstLessThanOrEqualsSecond

public static final boolean firstLessThanOrEqualsSecond(int[] v1,
                                                        int[] v2)
Check difference between first and second version number. The version numbers are given as Strings containing a numerical main version, a subversion, and a patch level, e.g. "1.4.2". Seperating character can be ".", "_", or " ". Missing parts of the number are handled as "0".

Parameters:
v1 - First version as array of ints.
v2 - Second version as array of ints.
Returns:
true if first version number is smaller than or equal to second, false otherwise

QJCC homepage