Package io.microsphere.util
Class Version
- java.lang.Object
-
- io.microsphere.util.Version
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<Version>
public class Version extends java.lang.Object implements java.lang.Comparable<Version>, java.io.Serializable
Represents a version number composed of major, minor, and patch components.This class provides methods to compare versions using standard comparison operators such as greater than, less than, and equal to. It also supports parsing version strings in the format "major.minor.patch".
Example Usage
Version v1 = new Version(1, 2, 3); Version v2 = Version.of("1.2.3"); // Comparison boolean isEqual = v1.equals(v2); // true boolean isGreaterThan = v1.isGreaterThan(Version.of("1.2.2")); // true boolean isLessThan = v1.lt(Version.of("1.3.0")); // true // Parsing from string Version v3 = Version.of("2.0.0"); // Getting version from a class's manifest Version versionFromManifest = Version.getVersion(MyClass.class);
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Version.Operator
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(Version that)
boolean
eq(Version that)
CurrentVersion
is equal to thatboolean
equals(Version that)
CurrentVersion
is equal to thatboolean
equals(java.lang.Object o)
CurrentVersion
is equal to thatboolean
ge(Version that)
CurrentVersion
is greater than or equal to thatint
getMajor()
The major versionint
getMinor()
The minor versionint
getPatch()
The patchstatic Version
getVersion(java.lang.Class<?> targetClass)
Class that exposes the version.boolean
gt(Version that)
CurrentVersion
is greater than thatint
hashCode()
boolean
isGreaterOrEqual(Version that)
CurrentVersion
is greater than or equal to thatboolean
isGreaterThan(Version that)
CurrentVersion
is greater than thatboolean
isLessOrEqual(Version that)
CurrentVersion
is less than or equal to thatboolean
isLessThan(Version that)
CurrentVersion
is less than thatboolean
le(Version that)
CurrentVersion
is less than or equal to thatboolean
lt(Version that)
CurrentVersion
is less than thatstatic Version
of(int major)
static Version
of(int major, int minor)
static Version
of(int major, int minor, int patch)
static Version
of(java.lang.String version)
static Version
ofVersion(int major)
static Version
ofVersion(int major, int minor)
static Version
ofVersion(int major, int minor, int patch)
static Version
ofVersion(java.lang.String version)
java.lang.String
toString()
-
-
-
Method Detail
-
getMajor
public int getMajor()
The major version- Returns:
- major version
-
getMinor
public int getMinor()
The minor version- Returns:
- minor version
-
getPatch
public int getPatch()
The patch- Returns:
- patch
-
gt
public boolean gt(Version that)
CurrentVersion
is greater than that- Parameters:
that
- the version to be compared- Returns:
true
if greater than, orfalse
- See Also:
isGreaterThan(Version)
-
isGreaterThan
public boolean isGreaterThan(Version that)
CurrentVersion
is greater than that- Parameters:
that
- the version to be compared- Returns:
true
if greater than, orfalse
- See Also:
gt(Version)
-
ge
public boolean ge(Version that)
CurrentVersion
is greater than or equal to that- Parameters:
that
- the version to be compared- Returns:
true
if greater than, orfalse
- See Also:
isGreaterOrEqual(Version)
-
isGreaterOrEqual
public boolean isGreaterOrEqual(Version that)
CurrentVersion
is greater than or equal to that- Parameters:
that
- the version to be compared- Returns:
true
if greater than, orfalse
- See Also:
ge(Version)
-
lt
public boolean lt(Version that)
CurrentVersion
is less than that- Parameters:
that
- the version to be compared- Returns:
true
if less than, orfalse
-
isLessThan
public boolean isLessThan(Version that)
CurrentVersion
is less than that- Parameters:
that
- the version to be compared- Returns:
true
if less than, orfalse
-
le
public boolean le(Version that)
CurrentVersion
is less than or equal to that- Parameters:
that
- the version to be compared- Returns:
true
if less than, orfalse
- See Also:
isLessOrEqual(Version)
-
isLessOrEqual
public boolean isLessOrEqual(Version that)
CurrentVersion
is less than or equal to that- Parameters:
that
- the version to be compared- Returns:
true
if less than, orfalse
- See Also:
le(Version)
-
eq
public boolean eq(Version that)
CurrentVersion
is equal to that- Parameters:
that
- the version to be compared- Returns:
true
if equals, orfalse
-
equals
public boolean equals(Version that)
CurrentVersion
is equal to that- Parameters:
that
- the version to be compared- Returns:
true
if equals, orfalse
-
equals
public boolean equals(java.lang.Object o)
CurrentVersion
is equal to that- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- the version to be compared- Returns:
true
if equals, orfalse
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
compareTo
public int compareTo(Version that)
- Specified by:
compareTo
in interfacejava.lang.Comparable<Version>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
of
public static Version of(int major)
-
of
public static Version of(int major, int minor)
-
of
public static Version of(int major, int minor, int patch)
-
of
public static Version of(java.lang.String version)
-
ofVersion
public static Version ofVersion(int major)
-
ofVersion
public static Version ofVersion(int major, int minor)
-
ofVersion
public static Version ofVersion(int major, int minor, int patch)
-
ofVersion
public static Version ofVersion(java.lang.String version)
-
getVersion
@Nonnull public static Version getVersion(java.lang.Class<?> targetClass) throws java.lang.IllegalArgumentException
Class that exposes the version. Fetches the "Implementation-Version" manifest attribute from the jar file.- Parameters:
targetClass
- the class to exposes the version- Returns:
- non-null
- Throws:
java.lang.IllegalArgumentException
- if the "Implementation-Version" manifest attribute can't be fetched from the jar file.
-
-