Package org.apache.sis.util
Class Version
java.lang.Object
org.apache.sis.util.Version
- All Implemented Interfaces:
Serializable
,CharSequence
,Comparable<Version>
Holds a version number as a sequence of strings separated by either a dot or a dash.
The first three strings, usually numbers, are called respectively major,
minor and revision.
For example, a version code such as
"6.11.2"
will have major number 6, minor
number 11 and revision number 2. Alternatively, a version code such as "3.18-SNAPSHOT"
will have major version number 3, minor version number 18 and revision string "SNAPSHOT".
This class provides methods for performing comparisons of Version
objects where major,
minor and revision parts are compared as numbers when possible, or as strings otherwise.
Immutability and thread safety
This class is immutable and thus inherently thread-safe. Subclasses may or may not be immutable, at implementation choice. But implementers are encouraged to make sure that subclasses remain immutable for more predictable behavior.- Since:
- 0.3
- Version:
- 0.4
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String[]
The components of the version string.private static final Version[]
A few commonly used version numbers.private int
The hash code value.private Comparable<?>[]
The parsed components of the version string.private static final String
private static final long
For cross-version compatibility.static final Version
The version of this Apache SIS distribution.private final String
The version in string form, with leading and trailing spaces removed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchar
charAt
(int index) Returns thechar
value at the specified index.int
Compares this version with another version object.int
Compares this version with another version object, up to the specified limit.boolean
Compare this version string with the specified object for equality.(package private) final 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
<?> Returns the revision number.private static int
getTypeRank
(Object value) Get the rank of the specified object according this type.int
hashCode()
Returns a hash code value for this version.int
length()
Returns the length of the version string.subSequence
(int start, int end) Returns a new version string that is a subsequence of this sequence.toString()
Returns the version string.static Version
valueOf
(int... components) Returns an instance for the given integer values.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
SEPARATORS
The separator characters between major, minor and revision components. Any character in this string fits.- See Also:
-
SIS
The version of this Apache SIS distribution. -
CONSTANTS
A few commonly used version numbers. This list is based on SIS needs, e.g. inDataStore
implementations. New constants are likely to be added in any future SIS versions.- See Also:
-
version
The version in string form, with leading and trailing spaces removed. -
components
The components of the version string. Will be created when first needed. -
parsed
The parsed components of the version string. Will be created when first needed. -
hashCode
private transient int hashCodeThe hash code value. Will be computed when first needed.
-
-
Constructor Details
-
Version
Creates a new version object from the supplied string.- Parameters:
version
- the version as a string.
-
-
Method Details
-
valueOf
Returns an instance for the given integer values. Thecomponents
array must contain at least 1 element, where:- The first element is the major number.
- The second element (if any) is the minor number.
- The third element (if any) is the revision number.
- Other elements (if any) will be appended to the
string value
.
- Parameters:
components
- the major number, optionally followed by minor, revision or other numbers.- Returns:
- a new or existing instance of
Version
for the given numbers. - Since:
- 0.4
-
getMajor
Returns the major version number. This method returns anInteger
if possible, or aString
otherwise.- Returns:
- the major version number.
-
getMinor
Returns the minor version number. This method returns anInteger
if possible, or aString
otherwise. If there is no minor version number, then this method returnsnull
.- Returns:
- the minor version number, or
null
if none.
-
getRevision
Returns the revision number. This method returns anInteger
if possible, or aString
otherwise. If there is no revision number, then this method returnsnull
.- Returns:
- the revision number, or
null
if none.
-
getComponent
Returns the specified components of this version string. For a version of themajor.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 aString
otherwise. 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
null
if none. - Throws:
IndexOutOfBoundsException
- ifindex
is negative.
-
getTypeRank
Get the rank of the specified object according this type. This is forcompareTo(Version, int)
internal only. -
compareTo
Compares this version with another 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 comparisons are performed asInteger
object if possible, or asString
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
Compares this version with another version object. This method performs the same comparison thancompareTo(Version, int)
with no limit.- Specified by:
compareTo
in 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
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:
length
in interfaceCharSequence
-
charAt
public char charAt(int index) Returns thechar
value at the specified index.- Specified by:
charAt
in interfaceCharSequence
-
subSequence
Returns a new version string that is a subsequence of this sequence.- Specified by:
subSequence
in interfaceCharSequence
-
toString
Returns the version string. This is the string specified at construction time.- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
hashCode
public int hashCode()Returns a hash code value for this version.
-