com.xmlmind.util
Class VersionNumber

java.lang.Object
  extended by com.xmlmind.util.VersionNumber
All Implemented Interfaces:
java.lang.Comparable<VersionNumber>

public final class VersionNumber
extends java.lang.Object
implements java.lang.Comparable<VersionNumber>

Structured version numbers similar to those used for the JavaTM runtime (example: 1.5.0_06).


Nested Class Summary
static class VersionNumber.LevelType
          Type of the release: alpha, beta or patch.
 
Field Summary
 int level
          Alpha, beta or patch level.
 VersionNumber.LevelType levelType
          Type of the release: alpha, beta or patch.
 int major
          Major version number.
 int micro
          Micro version number.
static VersionNumber MIN_VERSION_NUMBER
          Minimal version number: 0.0.0-alpha00.
 int minor
          Minor version number.
 
Constructor Summary
VersionNumber()
          Constructs a minimal version number: 0.0.0-alpha00.
VersionNumber(int major, int minor, int micro)
          Constructs version number major.minor.micro.
VersionNumber(int major, int minor, int micro, int patch)
          Constructs version number major.minor.micro_patch.
VersionNumber(int major, int minor, int micro, VersionNumber.LevelType levelType, int level)
          Constructs version number major.minor.micro (-alpha|-beta|_)level.
 
Method Summary
 int compareTo(VersionNumber other)
           
 boolean equals(java.lang.Object other)
           
static VersionNumber fromString(java.lang.String s)
          Equivalent to fromString(s, false).
static VersionNumber fromString(java.lang.String s, boolean lenient)
          Parses specified string as a version number.
 int hashCode()
           
 VersionNumber noLevel()
          Returns a copy of this VersionNumber but with all level info (alpha, beta, patch) cleared.
static void parse(java.lang.String s, VersionNumber version)
          Parses specified string and returns the result in the specified version number object.
 java.lang.String toString()
          Returns a string having the following format: major.minor.micro if this version number is not an alpha, beta or patch release.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

major

public int major
Major version number. Example: 1 in 1.5.0_06.


minor

public int minor
Minor version number. Example: 5 in 1.5.0_06.


micro

public int micro
Micro version number. Example: 0 in 1.5.0_06.


levelType

public VersionNumber.LevelType levelType
Type of the release: alpha, beta or patch.


level

public int level
Alpha, beta or patch level. Example: 6 in 1.5.0_06.


MIN_VERSION_NUMBER

public static final VersionNumber MIN_VERSION_NUMBER
Minimal version number: 0.0.0-alpha00.

Constructor Detail

VersionNumber

public VersionNumber()
Constructs a minimal version number: 0.0.0-alpha00.

See Also:
MIN_VERSION_NUMBER

VersionNumber

public VersionNumber(int major,
                     int minor,
                     int micro)
Constructs version number major.minor.micro. Example: 1.1.2.


VersionNumber

public VersionNumber(int major,
                     int minor,
                     int micro,
                     int patch)
Constructs version number major.minor.micro_patch. Example: 3.1.0_01.


VersionNumber

public VersionNumber(int major,
                     int minor,
                     int micro,
                     VersionNumber.LevelType levelType,
                     int level)
Constructs version number major.minor.micro (-alpha|-beta|_)level. Example: 3.1.0-beta02.

Method Detail

fromString

public static VersionNumber fromString(java.lang.String s)
Equivalent to fromString(s, false).


fromString

public static VersionNumber fromString(java.lang.String s,
                                       boolean lenient)
Parses specified string as a version number.

Parameters:
s - string to be parsed
lenient - if true, any string starting with "\d+(\.\d+)?(\.\d+)?(_\d+)?" will be successfully parsed.
Returns:
parsed version number or null if it cannot be parsed.

parse

public static void parse(java.lang.String s,
                         VersionNumber version)
                  throws java.lang.IllegalArgumentException
Parses specified string and returns the result in the specified version number object.

Parameters:
s - string to be parsed
version - the parsed version number is stored in this object
Throws:
java.lang.IllegalArgumentException - if s cannot be parsed

hashCode

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

equals

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

noLevel

public VersionNumber noLevel()
Returns a copy of this VersionNumber but with all level info (alpha, beta, patch) cleared.


compareTo

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

toString

public java.lang.String toString()
Returns a string having the following format: major.minor.micro if this version number is not an alpha, beta or patch release. Otherwise, returns a string having the following format: major.minor.micro (-alpha|-beta|_)level.

Overrides:
toString in class java.lang.Object