Package org.geotools.util
Class Version
- Object
-
- Version
-
- All Implemented Interfaces:
Serializable,CharSequence,Comparable<Version>
public class Version extends Object implements CharSequence, Comparable<Version>, Serializable
Holds a version number. Versions are often of the formmajor.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
- Author:
- Martin Desruisseaux
- See Also:
GeoTools.getVersion(), Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description charcharAt(int index)Returns thecharvalue at the specified index.intcompareTo(Version other)Compares this version with an other version object.intcompareTo(Version other, int limit)Compares this version with an other version object, up to the specified limit.booleanequals(Object other)Compare this version string with the specified object for equality.Comparable<?>getComponent(int index)Returns the specified components of this version string.Comparable<?>getMajor()Returns the major version number.Comparable<?>getMinor()Returns the minor version number.Comparable<?>getRevision()Returns the revision number.inthashCode()Returns a hash code value for this version.intlength()Returns the length of the version string.CharSequencesubSequence(int start, int end)Returns a new version string that is a subsequence of this sequence.StringtoString()Returns the version string.-
Methods inherited from interface CharSequence
chars, codePoints
-
-
-
-
Constructor Detail
-
Version
public Version(String version)
Creates a new version object from the supplied string.- Parameters:
version- The version as a string.
-
-
Method Detail
-
getMajor
public Comparable<?> getMajor()
Returns the major version number. This method returns anIntegerif possible, or aStringotherwise.- Returns:
- The major version number.
-
getMinor
public Comparable<?> getMinor()
Returns the minor version number. This method returns anIntegerif possible, or aStringotherwise. If there is no minor version number, then this method returnsnull.- Returns:
- The minor version number, or
nullif none.
-
getRevision
public Comparable<?> getRevision()
Returns the revision number. This method returns anIntegerif possible, or aStringotherwise. If there is no revision number, then this method returnsnull.- Returns:
- The revision number, or
nullif none.
-
getComponent
public Comparable<?> getComponent(int index)
Returns the specified components of this version string. For a version of themajor.minor.revisionform, 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
Integerif the component is parsable as an integer, or aStringotherwise. If there is no component at the specified index, then this method returnsnull.- Parameters:
index- The index of the component to fetch.- Returns:
- The value at the specified index, or
nullif none. - Throws:
IndexOutOfBoundsException- ifindexis 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 asIntegerobject if possible, or asStringotherwise.- 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 thancompareTo(Version, int)with no limit.- Specified by:
compareToin interfaceComparable<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(Object other)
Compare this version string with the specified object for equality. Two version are considered equal ifcompareTo(other) == 0.
-
length
public int length()
Returns the length of the version string.- Specified by:
lengthin interfaceCharSequence
-
charAt
public char charAt(int index)
Returns thecharvalue at the specified index.- Specified by:
charAtin interfaceCharSequence
-
subSequence
public CharSequence subSequence(int start, int end)
Returns a new version string that is a subsequence of this sequence.- Specified by:
subSequencein interfaceCharSequence
-
toString
public String toString()
Returns the version string. This is the string specified at construction time.- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
-