com.gridsystems.utils
Class Version

java.lang.Object
  extended by com.gridsystems.utils.Version
All Implemented Interfaces:
java.lang.Comparable<Version>
Direct Known Subclasses:
JavaVersion

public class Version
extends java.lang.Object
implements java.lang.Comparable<Version>

General Utilities.

Version:
1.0
Author:
nporcel

Constructor Summary
Version(int... values)
          Creates an instance.
Version(java.lang.String version)
          Constructor.
 
Method Summary
 int compareTo(Version v)
          Compares this object to another JavaVersion.
 boolean equals(java.lang.Object obj)
          
static double getDoubleRepresentation(java.lang.String version)
          Deprecated. For comparisons, use #compare(Object)
 int getMajorVersion()
          Deprecated. Use #getValue(int) instead.
 int getMinorVersion()
          Deprecated. Use #getValue(int) instead.
 int getRelease()
          Deprecated. Use #getValue(int) instead.
 int getSize()
          Get the size (number of elements) of the version.
static java.lang.String getStringRepresentation(double version)
          Deprecated. Use #toString()
static java.lang.String getStringRepresentation(double version, int fields)
          Deprecated. Use #toString()
 int getValue(int i)
          Gets a slice of the version numbers.
 int hashCode()
          
 java.lang.String toString()
          Returns a String representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Version

public Version(java.lang.String version)
Constructor.

Parameters:
version - the String from which the version information is obtained. It is interpreted as an arbitrarily long series of integers separated by non-digit characters.

Version

public Version(int... values)
Creates an instance.

Parameters:
values - version numbers (major, minor, release, build, etc.)
Method Detail

getValue

public int getValue(int i)
Gets a slice of the version numbers.

Parameters:
i - an int with the position (ranging from 0 to this.getSize() - 1 of the part of the version number wanted; 0 means the major version number; 1 the minor version number and so on.
Returns:
an int with the value of that part of the version number or, if the index is out of the valid range, 0.

getSize

public int getSize()
Get the size (number of elements) of the version.

Returns:
an int with the size (number of elements) of the version.

compareTo

public int compareTo(Version v)
Compares this object to another JavaVersion. Compares this object to another JavaVersion. Objects related to older versions are minor that objects related to newer versions.

Specified by:
compareTo in interface java.lang.Comparable<Version>
Parameters:
v - the instance to compare to
Returns:
an int that is -1 if this is minor than obj, 0 if both objects represent the same version and 1 otherwise.

equals

public boolean equals(java.lang.Object obj)

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

getMajorVersion

public int getMajorVersion()
Deprecated. Use #getValue(int) instead.

Gets the major version.

Returns:
an int with the major number of the version.

getMinorVersion

public int getMinorVersion()
Deprecated. Use #getValue(int) instead.

Gets the minor version.

Returns:
an int with the the minor number of the version.

getRelease

public int getRelease()
Deprecated. Use #getValue(int) instead.

Gets the release version.

Returns:
an int with the release number of the minor version.

toString

public java.lang.String toString()
Returns a String representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of this version number as a series of integers separated with dots ".".

getDoubleRepresentation

public static double getDoubleRepresentation(java.lang.String version)
Deprecated. For comparisons, use #compare(Object)

Gets the representation as a double of a version String. Gets the representation as a double of a version String. The String is parsed in the same way it is when invoking #Version(String). The return value is in the form of {d0}.{d1}{d2}{d3}..., being d0 the value of the first part of the version number and d1, d2 and remainders are two-digits representation of the other parts of the version number. If any of the later is greater than 99 (and thus, it cannot be written with two digits) it is converted to 99. Examples

Parameters:
version - the String with the version description.
Returns:
a double with a representation of version.
See Also:
Version(String)

getStringRepresentation

public static java.lang.String getStringRepresentation(double version,
                                                       int fields)
Deprecated. Use #toString()

Gets the representation as a string of a version double. Gets the representation as a string of a version double. This is the opposite process to #getDoubleRepresentation(String), splicing the double value in groups of two digits and using the values as parts of the version number. Parts are separated using an underscore "_" character. Examples:

Parameters:
version - a double with the version data.
fields - an int with the number of fields that the resulting String is expected to have. Setting this value properly allows avoiding rounding errors due to the use of double.
Returns:
a String with a representation of version.

getStringRepresentation

public static java.lang.String getStringRepresentation(double version)
Deprecated. Use #toString()

Gets the representation as a string (three fields) of a version double. Gets the representation as a string of a version double. This is the opposite process to #getDoubleRepresentation(String), splicing the double value in groups of two digits and using the values as parts of the version number. Parts are separated using an underscore "_" character. Examples:
This method always return a String representation that contains the three first fields.

Parameters:
version - a double with the version data.
Returns:
a String with a representation of version.
See Also:
getStringRepresentation(double, int)


Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.