Package xyz.rk0cc.josev
Class SemVer
java.lang.Object
xyz.rk0cc.josev.SemVer
- All Implemented Interfaces:
Serializable
,Comparable<SemVer>
An immutable Java object for Semantic Versioning 2.0.0.
Semantic Versioning must be followed this versioning method:
Major, minor and patch number fields are mandatory and non-negative number. It may optionally provide pre-release or build tag if needed.
In additions, it implemented
Semantic Versioning must be followed this versioning method:
Major.Minor.Patch(-Pre release)(+build tag)
Major, minor and patch number fields are mandatory and non-negative number. It may optionally provide pre-release or build tag if needed.
In additions, it implemented
Comparable
which following version ordering policy.- Since:
- 1.0.0
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
AString
of Semantic Versioning regex which will be applied onPattern.compile(String)
. -
Constructor Summary
ConstructorDescriptionSemVer
(long major) Create new versioning data without additional tag applied.SemVer
(long major, long minor) Create new versioning data without additional tag applied.SemVer
(long major, long minor, long patch) Create new versioning data without additional tag applied.Create new versioning data.Create new versioning data.Create new versioning data. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Get build tag of this versioning.int
boolean
Compare anotherSemVer
which has equals data of versioning.int
hashCode()
Calculating hash code form all provided versioning data.boolean
Check this version is greater thancompare
boolean
isGreaterOrEquals
(SemVer compare) Check this version is greater or equals withcompare
boolean
Check this version is lower thancompare
boolean
isLowerOrEquals
(SemVer compare) Check this version is lowerer or equals withcompare
boolean
Determine this versioning is still under development.boolean
isSameVersionGroup
(SemVer semVer) long
major()
Get major release of this versioning.long
minor()
Get minor release of this versioning.static SemVer
long
patch()
Get patch release of this versioning.Get pre-release tag of this versioning.toString()
Return aString
of object-like context for logging purpose.static SemVer
value()
Return aString
of version which follows Semantic Versioning standard.
-
Field Details
-
SEMVER_REGEX
AString
of Semantic Versioning regex which will be applied onPattern.compile(String)
.- See Also:
-
-
Constructor Details
-
SemVer
public SemVer(@Nonnegative long major, @Nonnegative long minor, @Nonnegative long patch, @Nullable String preRelease, @Nullable String build) throws NonStandardSemVerException Create new versioning data.- Parameters:
major
- Non-negative number of major release.minor
- Non-negative number of minor release.patch
- Non-negative number of patch release.preRelease
- Pre-release tag (if applied).build
- Build tag (if applied).- Throws:
NonStandardSemVerException
- If anyThrowable
thrown when callingvalue()
that does not meetthe regex of Semantic Versioning
.NumberFormatException
- When parsingmajor
,minor
andpatch
with exceedingLong
's maximum (signed) value even it valid to parse.
-
SemVer
public SemVer(@Nonnegative long major, @Nonnegative long minor, @Nonnegative long patch) Create new versioning data without additional tag applied.- Parameters:
major
- Non-negative number of major release.minor
- Non-negative number of minor release.patch
- Non-negative number of patch release.- Throws:
NumberFormatException
- When parsingmajor
,minor
andpatch
with exceedingLong
's maximum (signed) value even it valid to parse.
-
SemVer
public SemVer(@Nonnegative long major, @Nonnegative long minor, @Nullable String preRelease, @Nullable String build) throws NonStandardSemVerException Create new versioning data.- Parameters:
major
- Non-negative number of major release.minor
- Non-negative number of minor release.preRelease
- Pre-release tag (if applied).build
- Build tag (if applied).- Throws:
NonStandardSemVerException
- If anyThrowable
thrown when callingvalue()
that does not meetthe regex of Semantic Versioning
.NumberFormatException
- When parsingmajor
,minor
andpatch
with exceedingLong
's maximum (signed) value even it valid to parse.
-
SemVer
public SemVer(@Nonnegative long major, @Nonnegative long minor) Create new versioning data without additional tag applied.- Parameters:
major
- Non-negative number of major release.minor
- Non-negative number of minor release.- Throws:
NumberFormatException
- When parsingmajor
,minor
andpatch
with exceedingLong
's maximum (signed) value even it valid to parse.
-
SemVer
public SemVer(@Nonnegative long major, @Nullable String preRelease, @Nullable String build) throws NonStandardSemVerException Create new versioning data.- Parameters:
major
- Non-negative number of major release.preRelease
- Pre-release tag (if applied).build
- Build tag (if applied).- Throws:
NonStandardSemVerException
- If anyThrowable
thrown when callingvalue()
that does not meetthe regex of Semantic Versioning
.NumberFormatException
- When parsingmajor
,minor
andpatch
with exceedingLong
's maximum (signed) value even it valid to parse.
-
SemVer
public SemVer(@Nonnegative long major) Create new versioning data without additional tag applied.- Parameters:
major
- Non-negative number of major release.- Throws:
NumberFormatException
- When parsingmajor
,minor
andpatch
with exceedingLong
's maximum (signed) value even it valid to parse.
-
-
Method Details
-
major
@Nonnegative public long major()Get major release of this versioning.- Returns:
- Non-negative
Long
value that representing major release.
-
minor
@Nonnegative public long minor()Get minor release of this versioning.- Returns:
- Non-negative
Long
value that representing minor release.
-
patch
@Nonnegative public long patch()Get patch release of this versioning.- Returns:
- Non-negative
Long
value that representing patch release.
-
preRelease
Get pre-release tag of this versioning.- Returns:
- A
String
of pre-release,null
if not applied.
-
build
Get build tag of this versioning.- Returns:
- A
String
of build,null
if not applied.
-
isPreRelease
public boolean isPreRelease()Determine this versioning is still under development.- Returns:
- Check this versioning is applied non-null
preRelease()
or setmajor()
as0
.
-
isGreater
Check this version is greater thancompare
- Parameters:
compare
- AnotherSemVer
which using to compare with this.- Returns:
true
ifcompareTo(SemVer)
return greater than0
.
-
isLower
Check this version is lower thancompare
- Parameters:
compare
- AnotherSemVer
which using to compare with this.- Returns:
true
ifcompareTo(SemVer)
return lowerer than0
.
-
isGreaterOrEquals
Check this version is greater or equals withcompare
- Parameters:
compare
- AnotherSemVer
which using to compare with this.- Returns:
true
ifcompareTo(SemVer)
return greater or equals with0
.
-
isLowerOrEquals
Check this version is lowerer or equals withcompare
- Parameters:
compare
- AnotherSemVer
which using to compare with this.- Returns:
true
ifcompareTo(SemVer)
return lower or equals with0
.
-
isSameVersionGroup
- Parameters:
semVer
- ASemVer
that to determine has same version group.- Returns:
true
if it is.
-
value
Return aString
of version which follows Semantic Versioning standard.- Returns:
- An assembled
String
of Semantic Versioning.
-
compareTo
- Specified by:
compareTo
in interfaceComparable<SemVer>
-
equals
Compare anotherSemVer
which has equals data of versioning. -
hashCode
public int hashCode()Calculating hash code form all provided versioning data. -
toString
Return aString
of object-like context for logging purpose. -
parse
- Parameters:
version
- AString
of Semantic Versioning. If it contains 'v
' at the firstCharacter
ofString.charAt(int)
, it will be omitted automatically.- Returns:
- A Java object of
Semantic Versioning
. - Throws:
NonStandardSemVerException
- Ifversion
does not follows the standard of Semantic Versioning. Or encounter a problem when handling data in JVM.- See Also:
-
tryParse
Generating a newSemVer
object by aString
. However, whenNonStandardSemVerException
throw onparse(String)
, it returnsnull
.- Parameters:
version
- AString
of version.- Returns:
- A Java object of
Semantic Versioning
. Ornull
ifversion
causesparse(String)
throwsNonStandardSemVerException
.
-