org.geotools.util
Class Version

java.lang.Object
  extended by org.geotools.util.Version
All Implemented Interfaces:
java.io.Serializable, java.lang.CharSequence, java.lang.Comparable<Version>

public class Version
extends java.lang.Object
implements java.lang.CharSequence, java.lang.Comparable<Version>, java.io.Serializable

Holds a version number. Versions are often of the form major.minor.revision, but are not required to. For example an EPSG database version is "6.11.2". The separator character is the dot.

This class provides convenience methods for fetching the major, minor and reversion numbers, and for performing comparaisons.

Since:
2.4
Version:
$Id: Version.java 30792 2008-06-23 19:19:58Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
GeoTools.getVersion(), Serialized Form

Field Summary
static char SEPARATOR
          The separator character between major, minor and revision components.
 
Constructor Summary
Version(java.lang.String version)
          Creates a new version object from the supplied string.
 
Method Summary
 char charAt(int index)
          Returns the char value at the specified index.
 int compareTo(Version other)
          Compares this version with an other version object.
 int compareTo(Version other, int limit)
          Compares this version with an other version object, up to the specified limit.
 boolean equals(java.lang.Object other)
          Compare this version string with the specified object for equality.
 java.lang.Comparable<?> getComponent(int index)
          Returns the specified components of this version string.
 java.lang.Comparable<?> getMajor()
          Returns the major version number.
 java.lang.Comparable<?> getMinor()
          Returns the minor version number.
 java.lang.Comparable<?> getRevision()
          Returns the revision number.
 int hashCode()
          Returns a hash code value for this version.
 int length()
          Returns the length of the version string.
 java.lang.CharSequence subSequence(int start, int end)
          Returns a new version string that is a subsequence of this sequence.
 java.lang.String toString()
          Returns the version string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SEPARATOR

public static final char SEPARATOR
The separator character between major, minor and revision components.

See Also:
Constant Field Values
Constructor Detail

Version

public Version(java.lang.String version)
Creates a new version object from the supplied string.

Parameters:
version - The version as a string.
Method Detail

getMajor

public java.lang.Comparable<?> getMajor()
Returns the major version number. This method returns an Integer if possible, or a String otherwise.

Returns:
The major version number.

getMinor

public java.lang.Comparable<?> getMinor()
Returns the minor version number. This method returns an Integer if possible, or a String otherwise. If there is no minor version number, then this method returns null.

Returns:
The minor version number, or null if none.

getRevision

public java.lang.Comparable<?> getRevision()
Returns the revision number. This method returns an Integer if possible, or a String otherwise. If there is no revision number, then this method returns null.

Returns:
The revision number, or null if none.

getComponent

public java.lang.Comparable<?> getComponent(int index)
Returns the specified components of this version string. For a version of the major.minor.revision form, index 0 stands for the major version number, 1 stands for the minor version number and 2 stands for the revision number.

The return value is an Integer if the component is parsable as an integer, or a String otherwise. If there is no component at the specified index, then this method returns null.

Parameters:
index - The index of the component to fetch.
Returns:
The value at the specified index, or null if none.
Throws:
java.lang.IndexOutOfBoundsException - if index is negative.

compareTo

public int compareTo(Version other,
                     int limit)
Compares this version with an other version object, up to the specified limit. A limit of 1 compares only the major version number. A limit of 2 compares the major and minor version numbers, etc. The comparaisons are performed as Integer object if possible, or as String otherwise.

Parameters:
other - The other version object to compare with.
limit - The maximum number of components to compare.
Returns:
A negative value if this version is lower than the supplied version, a positive value if it is higher, or 0 if they are equal.

compareTo

public int compareTo(Version other)
Compares this version with an other version object. This method performs the same comparaison than compareTo(Version, int) with no limit.

Specified by:
compareTo in interface java.lang.Comparable<Version>
Parameters:
other - The other version object to compare with.
Returns:
A negative value if this version is lower than the supplied version, a positive value if it is higher, or 0 if they are equal.

equals

public boolean equals(java.lang.Object other)
Compare this version string with the specified object for equality. Two version are considered equal if compareTo(other) == 0.

Overrides:
equals in class java.lang.Object
Parameters:
other - The object to compare with this version for equality.

length

public int length()
Returns the length of the version string.

Specified by:
length in interface java.lang.CharSequence

charAt

public char charAt(int index)
Returns the char value at the specified index.

Specified by:
charAt in interface java.lang.CharSequence

subSequence

public java.lang.CharSequence subSequence(int start,
                                          int end)
Returns a new version string that is a subsequence of this sequence.

Specified by:
subSequence in interface java.lang.CharSequence

toString

public java.lang.String toString()
Returns the version string. This is the string specified at construction time.

Specified by:
toString in interface java.lang.CharSequence
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Returns a hash code value for this version.

Overrides:
hashCode in class java.lang.Object


Copyright © 1996-2010 Geotools. All Rights Reserved.