Class SemanticVersion
java.lang.Object
com.norconex.commons.lang.version.SemanticVersion
- All Implemented Interfaces:
Comparable<SemanticVersion>
Immutable semantic version representation, conforming to https://semver.org/ specifications.
- Since:
- 3.0.0
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SemanticVersionA special instance that represents a non-versioned entity. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()protected booleanintbooleanOptional metadata associated with a build.intgetMajor()Major version number.intgetMinor()Minor version number.intgetPatch()Patch version number.Optional pre-release indicator (M1, RC1, etc.).inthashCode()booleanisEquivalentTo(SemanticVersion other) Gets whether this version is semantically equivalent to the other one.booleanGets whether this version is semantically greater or equivalent to the other one.booleanisGreaterThan(SemanticVersion other) Gets whether this version is semantically greater than the other one.booleanGets whether this version is semantically lower or equivalent to the other one.booleanisLowerThan(SemanticVersion other) Gets whether this version is semantically lower than the other one.booleanGets whether this semantic version is representing something non-versioned.static SemanticVersionof(int major) Create a new semantic version with the minor and patch numbers set to zero (0).static SemanticVersionof(int major, int minor) Create a new semantic version with the patch number set to zero (0).static SemanticVersionof(int major, int minor, int patch) Create a new semantic version.static SemanticVersionCreate a new semantic version.static SemanticVersionCreate a new semantic version.toString()A friendly representation of this semantic version.
-
Field Details
-
UNVERSIONED
A special instance that represents a non-versioned entity. This is an alternative to using anullvalue when there is no version. Sets major, minor, and patch values to -1.
-
-
Method Details
-
of
Create a new semantic version with the minor and patch numbers set to zero (0).- Parameters:
major- major number- Returns:
- a semantic version
-
of
Create a new semantic version with the patch number set to zero (0).- Parameters:
major- major numberminor- minor number- Returns:
- a semantic version
-
of
Create a new semantic version.- Parameters:
major- major numberminor- minor numberpatch- patch number- Returns:
- a semantic version
-
of
Create a new semantic version.- Parameters:
major- major numberminor- minor numberpatch- patch numberpreRelease- pre-release qualifier (can benull)- Returns:
- a semantic version
-
of
public static SemanticVersion of(int major, int minor, int patch, String preRelease, String buildMetadata) Create a new semantic version.- Parameters:
major- major numberminor- minor numberpatch- patch numberpreRelease- pre-release qualifier (can benull)buildMetadata- build metadata (can benull)- Returns:
- a semantic version
-
isVersioned
public boolean isVersioned()Gets whether this semantic version is representing something non-versioned. Creating an instance with any of major, minor, and patch values being less than zero is considered non-versioned. A non-versioned instance will always compare lower than a versioned one.- Returns:
trueif versioned
-
compareTo
- Specified by:
compareToin interfaceComparable<SemanticVersion>
-
isEquivalentTo
Gets whether this version is semantically equivalent to the other one.- Parameters:
other- other version we are comparing to- Returns:
trueif this version is equivalent to the other
-
isGreaterThan
Gets whether this version is semantically greater than the other one.- Parameters:
other- other version we are comparing to- Returns:
trueif this version is greater than the other
-
isGreaterOrEquivalentTo
Gets whether this version is semantically greater or equivalent to the other one.- Parameters:
other- other version we are comparing to- Returns:
trueif this version is greater or equivalent to the other
-
isLowerThan
Gets whether this version is semantically lower than the other one.- Parameters:
other- other version we are comparing to- Returns:
trueif this version is lower than the other
-
isLowerOrEquivalentTo
Gets whether this version is semantically lower or equivalent to the other one.- Parameters:
other- other version we are comparing to- Returns:
trueif this version is lower or equivalent to the other
-
toString
A friendly representation of this semantic version. -
builder
-
getMajor
public int getMajor()Major version number. The first number of a semantic version. -
getMinor
public int getMinor()Minor version number. The second number of a semantic version. -
getPatch
public int getPatch()Patch version number. The third number of a semantic version. -
getPreRelease
Optional pre-release indicator (M1, RC1, etc.). -
getBuildMetadata
Optional metadata associated with a build. -
equals
-
canEqual
-
hashCode
public int hashCode()
-