org.pf.text
Class Version

java.lang.Object
  extended by org.pf.text.Version

public class Version
extends java.lang.Object

This class provides a representation of version identifiers of pattern "x.y.z" in a way that they can be compared and sorted according to their real meaning and not just by simple string comparison.

Examples:
3.1 > 3.0
3.1.1 > 3.1
2.4 < 10.0
0.11.2 > 0.1.22

Version:
1.1
Author:
Manfred Duchrow

Field Summary
static java.lang.String SEPARATOR
          Contains the seperator between the version elements. (".")
 
Constructor Summary
Version(java.lang.String versionString)
          Initialize the new instance with a version string of type "x.y.z".
 
Method Summary
 int compareTo(java.lang.Object obj)
          Compares this object with the specified object for order.
 boolean equals(java.lang.Object obj)
          Returns true if this version is equal to the given object.
 int hashCode()
          Returns a hash code
 boolean isGreaterThan(java.lang.String version)
          Returns if this version is greater than the specified version.
 boolean isGreaterThan(Version version)
          Returns if this version is greater than the specified version.
 boolean isLessThan(java.lang.String version)
          Returns if this version is greater than the specified version.
 boolean isLessThan(Version version)
          Returns if this version is greater than the specified version.
 boolean isNumeric()
          Returns true if this version contains only positive numeric sub parts.
 boolean isValid()
          Returns true if this version contains only valid sub parts.
static boolean isValidVersion(java.lang.String str)
          Returns true if the given string represents a valid version.
 java.lang.String toString()
          Returns the version as string
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SEPARATOR

public static final java.lang.String SEPARATOR
Contains the seperator between the version elements. (".")

See Also:
Constant Field Values
Constructor Detail

Version

public Version(java.lang.String versionString)
Initialize the new instance with a version string of type "x.y.z". The elements in the string separated by dots is not limited!

Method Detail

isValidVersion

public static boolean isValidVersion(java.lang.String str)
Returns true if the given string represents a valid version.

Parameters:
str - The string to be checked if it is a valid version

isGreaterThan

public boolean isGreaterThan(Version version)
Returns if this version is greater than the specified version.


isLessThan

public boolean isLessThan(Version version)
Returns if this version is greater than the specified version.


isGreaterThan

public boolean isGreaterThan(java.lang.String version)
Returns if this version is greater than the specified version.


isLessThan

public boolean isLessThan(java.lang.String version)
Returns if this version is greater than the specified version.


equals

public boolean equals(java.lang.Object obj)
Returns true if this version is equal to the given object. The object must be of type Version or String.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns a hash code

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns the version as string

Overrides:
toString in class java.lang.Object

compareTo

public int compareTo(java.lang.Object obj)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Throws:
java.lang.IllegalArgumentException - if the specified object is not a Version

isNumeric

public boolean isNumeric()
Returns true if this version contains only positive numeric sub parts.


isValid

public boolean isValid()
Returns true if this version contains only valid sub parts.