edu.mit.jverbnet.data
Class Version

java.lang.Object
  extended by edu.mit.jverbnet.data.Version
All Implemented Interfaces:
IVersion, java.lang.Comparable<IVersion>

public class Version
extends java.lang.Object
implements IVersion

Default, concrete implementation of the IVersion interface. This class, much like the Integer class, caches instances, which should be created via the createVersion methods.

This version object takes an optional bugfix version number and string qualifier. The qualifier may only contain characters are that are valid Java

Since:
JVerbnet 1.0.0
Version:
1.2.0
Author:
Mark A. Finlayson

Field Summary
static java.util.regex.Pattern regex
          Regular expression pattern for matching a version string.
static Version ver31
           
static Version ver32
           
 
Fields inherited from interface edu.mit.jverbnet.data.IVersion
UNKNOWN
 
Constructor Summary
Version(int major, int minor, int bugfix)
          Creates a new version object with the specified version numbers.
Version(int major, int minor, int bugfix, java.lang.String qualifier)
          Creates a new version object with the specified version numbers.
 
Method Summary
static java.lang.String checkQualifier(java.lang.String qualifier)
          Checks the specified qualifier for legality.
static java.lang.String checkVersion(int major, int minor, int bugfix, java.lang.String qualifier)
          Checks the supplied version numbers.
static void checkVersionNumber(int major, int minor, int bugfix)
          Checks the supplied version numbers.
static int compare(IVersion one, IVersion two)
          Compares the versions for order.
 int compareTo(IVersion o)
           
 boolean equals(java.lang.Object obj)
           
 int getBugfixVersion()
          Returns the bugfix version number, i.e., the '2' in '1.7.2'.
 int getMajorVersion()
          Returns the major version number, i.e., the '1' in '1.7.2'.
 int getMinorVersion()
          Returns the minor version number, i.e., the '7' in '1.7.2'.
 java.lang.String getQualifier()
          Returns the version qualifier, i.e., the 'abc' in '1.7.2.abc'.
static Version getVersion(int major, int minor, int bugfix)
          Creates and caches, or retrieves from the cache, a version object corresponding to the specified numbers.
static Version getVersion(int major, int minor, int bugfix, java.lang.String qualifier)
          Creates and caches, or retrieves from the cache, a version object corresponding to the specified numbers.
 int hashCode()
           
static int hashCode(int major, int minor, int bugfix, java.lang.String qualifier)
          Calculates the hash code for a version object with the specified version numbers.
static boolean isIllegalQualifier(java.lang.String qualifier)
          Returns falseif the specified qualifier is legal, namely, if the string is either the empty string, or contains only characters that are found in valid java identifiers.
static boolean isIllegalVersion(int major, int minor, int bugfix, java.lang.String qualifier)
          Returns true if the arguments identify a legal version; false otherwise.
static boolean isIllegalVersionNumber(int major, int minor, int bugfix)
          Returns true if any of three numbers are negative
static java.lang.String makeVersionString(int major, int minor, int bugfix, java.lang.String qualifier)
          Creates a version string for the specified version numbers.
static Version parseVersion(java.lang.CharSequence verStr)
          Tries to transform the specified character sequence into a version object.
static Version parseVersionProtected(java.lang.CharSequence verStr)
          Tries to transform the specified character sequence into a version object.
 java.lang.String toString()
           
static java.util.List<Version> values()
          Emulates the Enum.values() function.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ver31

public static final Version ver31

ver32

public static final Version ver32

regex

public static final java.util.regex.Pattern regex
Regular expression pattern for matching a version string.

Since:
JVerbnet 1.1.0
Constructor Detail

Version

public Version(int major,
               int minor,
               int bugfix)
Creates a new version object with the specified version numbers.

Clients should normally obtain instances of this class via the static getVersion methods.

Parameters:
major - the major version number, i.e., the '1' in 1.2.3
minor - the minor version number, i.e., the '2' in 1.2.3
bugfix - the bugfix version number, i.e., the '3' in 1.2.3
Throws:
java.lang.IllegalArgumentException - if any of the version numbers are negative
Since:
JVerbnet 1.0.0

Version

public Version(int major,
               int minor,
               int bugfix,
               java.lang.String qualifier)
Creates a new version object with the specified version numbers.

Clients should normally obtain instances of this class via the static getVersion methods.

Parameters:
major - the major version number, i.e., the '1' in 1.2.3.q
minor - the minor version number, i.e., the '2' in 1.2.3.q
bugfix - the bugfix version number, i.e., the '3' in 1.2.3.q
qualifier - the version qualifier, i.e., the 'q' in 1.2.3.q
Throws:
java.lang.IllegalArgumentException - if any of the version numbers are negative, or the qualifier is not a legal qualifier
Since:
JVerbnet 1.0.0
Method Detail

getMajorVersion

public int getMajorVersion()
Description copied from interface: IVersion
Returns the major version number, i.e., the '1' in '1.7.2'.

Specified by:
getMajorVersion in interface IVersion
Returns:
the major version number, never negative

getMinorVersion

public int getMinorVersion()
Description copied from interface: IVersion
Returns the minor version number, i.e., the '7' in '1.7.2'.

Specified by:
getMinorVersion in interface IVersion
Returns:
the minor version number, never negative

getBugfixVersion

public int getBugfixVersion()
Description copied from interface: IVersion
Returns the bugfix version number, i.e., the '2' in '1.7.2'.

Specified by:
getBugfixVersion in interface IVersion
Returns:
the bugfix version number, never negative

getQualifier

public java.lang.String getQualifier()
Description copied from interface: IVersion
Returns the version qualifier, i.e., the 'abc' in '1.7.2.abc'. The qualifer is never null, but may be empty.

Specified by:
getQualifier in interface IVersion
Returns:
the version qualifier, non-null, potentially empty

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

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

toString

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

compareTo

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

compare

public static int compare(IVersion one,
                          IVersion two)
Compares the versions for order. Returns a negative integer, zero, or a positive integer as the first version is less than, equal to, or greater than the second version.

Returns:
a negative integer, zero, or a positive integer as the first version is less than, equal to, or greater than the second version
Since:
JVerbnet 1.0.0

checkVersion

public static java.lang.String checkVersion(int major,
                                            int minor,
                                            int bugfix,
                                            java.lang.String qualifier)
Checks the supplied version numbers. Throws an IllegalArgumentException if they do not define a legal version.,

Parameters:
major - the major version number
minor - the minor version number
bugfix - the bugfix version number
qualifier - the qualifier to check
Returns:
the null-masked qualifier
Throws:
java.lang.IllegalArgumentException - if the supplied arguments do not identify a legal version
Since:
JVerbnet 1.0.0

checkVersionNumber

public static void checkVersionNumber(int major,
                                      int minor,
                                      int bugfix)
Checks the supplied version numbers. Throws an IllegalArgumentException if the version numbers are not valid (that is, any are below zero).

Parameters:
major - the major version number
minor - the minor version number
bugfix - the bugfix version number
Throws:
java.lang.IllegalArgumentException - if any of the supplied numbers are negative
Since:
JVerbnet 1.0.0

checkQualifier

public static java.lang.String checkQualifier(java.lang.String qualifier)
Checks the specified qualifier for legality. Throws an IllegalArgumentException if it is not a legal qualifier.

Parameters:
qualifier - the qualifier to check
Returns:
the null-masked qualifier
Since:
JVerbnet 1.0.0
See Also:
isIllegalQualifier(String)

isIllegalVersion

public static boolean isIllegalVersion(int major,
                                       int minor,
                                       int bugfix,
                                       java.lang.String qualifier)
Returns true if the arguments identify a legal version; false otherwise.

Parameters:
major - the major version number
minor - the minor version number
bugfix - the bugfix version number
qualifier - the version qualifier
Returns:
true if the arguments identify a legal version; false otherwise.
Since:
JVerbnet 1.0.0

isIllegalVersionNumber

public static boolean isIllegalVersionNumber(int major,
                                             int minor,
                                             int bugfix)
Returns true if any of three numbers are negative

Parameters:
major - the major version number
minor - the minor version number
bugfix - the bugfix version number
Returns:
true if all the numbers are non-negative; false otherwise
Since:
JVerbnet 1.0.0

isIllegalQualifier

public static boolean isIllegalQualifier(java.lang.String qualifier)
Returns falseif the specified qualifier is legal, namely, if the string is either the empty string, or contains only characters that are found in valid java identifiers.

Parameters:
qualifier - the qualifier to check
Returns:
true if not a legal qualifier; false otherwise
Throws:
java.lang.NullPointerException - if the specified string is null
Since:
JVerbnet 1.0.0
See Also:
Character.isJavaIdentifierPart(char)

getVersion

public static Version getVersion(int major,
                                 int minor,
                                 int bugfix)
Creates and caches, or retrieves from the cache, a version object corresponding to the specified numbers.

Parameters:
major - the major version number
minor - the minor version number
bugfix - the bugfix version number
Returns:
the cached version object corresponding to these numbers
Since:
JVerbnet 1.0.0

getVersion

public static Version getVersion(int major,
                                 int minor,
                                 int bugfix,
                                 java.lang.String qualifier)
Creates and caches, or retrieves from the cache, a version object corresponding to the specified numbers.

Parameters:
major - the major version number
minor - the minor version number
bugfix - the bugfix version number
qualifier - the version qualifier
Returns:
the cached version object corresponding to these numbers
Throws:
java.lang.IllegalArgumentException - if the version numbers and qualifier are not legal
Since:
JVerbnet 1.0.0

makeVersionString

public static java.lang.String makeVersionString(int major,
                                                 int minor,
                                                 int bugfix,
                                                 java.lang.String qualifier)
Creates a version string for the specified version numbers. If a version's bugfix number is 0, and if the qualifier is null or empty, the string produced is of the form "x.y". I

Parameters:
major - the major version number, i.e., the '1' in 1.2.3.q
minor - the minor version number, i.e., the '2' in 1.2.3.q
bugfix - the bugfix version number, i.e., the '3' in 1.2.3.q
qualifier - the version qualifier, i.e., the 'q' in 1.2.3.q
Returns:
a string representing the specified version
Throws:
java.lang.IllegalArgumentException
Since:
JVerbnet 1.0.0

hashCode

public static int hashCode(int major,
                           int minor,
                           int bugfix,
                           java.lang.String qualifier)
Calculates the hash code for a version object with the specified version numbers.

Parameters:
major - the major version number, i.e., the '1' in 1.2.3.q
minor - the minor version number, i.e., the '2' in 1.2.3.q
bugfix - the bugfix version number, i.e., the '3' in 1.2.3.q
qualifier - the version qualifier, i.e., the 'q' in 1.2.3.q
Returns:
the hash code for the specified version
Throws:
java.lang.IllegalArgumentException - if the specified parameters do not identify a legal version
Since:
JVerbnet 1.0.0

parseVersionProtected

public static Version parseVersionProtected(java.lang.CharSequence verStr)
Tries to transform the specified character sequence into a version object. If it cannot, returns null

Parameters:
verStr - the sequence of characters to be transformed
Returns:
the version, or null if the character sequence is not a valid version
Since:
JVerbnet 1.0.0

parseVersion

public static Version parseVersion(java.lang.CharSequence verStr)
Tries to transform the specified character sequence into a version object.

Parameters:
verStr - the sequence of characters to be transformed
Returns:
the version
Throws:
java.lang.NullPointerException - if the character sequence is null
java.lang.IllegalArgumentException - if the character sequence does not correspond to a legal version
Since:
JVerbnet 1.0.0

values

public static java.util.List<Version> values()
Emulates the Enum.values() function.

Returns:
all the static data type instances listed in the class, in the order they are declared.
Since:
JVerbnet 1.0.0


Copyright © 2012 ${project.organization.name}. All Rights Reserved.