Package com.pnfsoftware.jeb.core
Class Version
java.lang.Object
com.pnfsoftware.jeb.core.Version
- All Implemented Interfaces:
Comparable<Version>
Version number object. The syntax is as follows:
major.minor.buildid.timestamp.channel or
major.minor-channelString.buildid.timestamp.
Details:
- A valid version string must contain the fields major, minor and
buildid
- Timestamp format: YYYYMMDDhhmm
- Allowed channels: RELEASE(0,""), BETA(1,"beta"), ALPHA(2,"alpha")
Examples of valid version strings:
1.0.0 1.0.2.201801021400 1.0.2.201801021400.0 1.0.2.201801021400.1 1.0.2.201801021400.2 1.2.123 1.2-beta.123 1.2-alpha.123 1.2-beta.123.201807140000Version objects can be persisted.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intAlpha channel identifier.static final intBeta channel identifier.static final intAlias for the least stable built-in channel.static final intAlias for the most stable supported channel.static final intRelease channel identifier. -
Constructor Summary
ConstructorsConstructorDescriptionVersion(int major, int minor) Create a new version object "major.minor.0.0".Version(int major, int minor, int buildid) Create a new version object "major.minor.buildid.0".Version(int major, int minor, int buildid, long timestamp) Create a new version object "major.minor.buildid.timestamp".Version(int major, int minor, int buildid, long timestamp, int channel) Create a new version object "major.minor.buildid.timestamp".Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionintintCompare two versions while ignoring their channels.intCompare two versions while ignoring their timestamps.intCompare two versions while ignoring both their timestamps and channels.static Versioncreate(int major, int minor) Static builder, equivalent ofVersion(int, int).static Versioncreate(int major, int minor, int buildid) Static builder, equivalent ofVersion(int, int, int).static Versioncreate(int major, int minor, int buildid, long timestamp) Static builder, equivalent ofVersion(int, int, int, long).static Versioncreate(int major, int minor, int buildid, long timestamp, int channel) Static builder, equivalent ofVersion(int, int, int, long, int).booleanformat(boolean useChannelString) Format the version using the numeric compact representation.static VersionfromInt(int val) Create a version object from an integer generated bytoInt().intGet the build id number.intGet the channel.static StringgetChannelInfo(int channel) Get a user-facing description of a build channel.static StringgetChannelName(int channel) Get the symbolic name of a build channel.static String[]Get the names of the built-in channels.Get the textual channel suffix used by formatted versions.intgetMajor()Get the major number.intgetMinor()Get the minor number.longGet the timestamp.inthashCode()booleanlike(int major) Determine if the version is like "major.?.?.?"booleanlike(int major, int minor) Determine if the version is like "major.minor.?.?"booleanlike(int major, int minor, int buildid) Determine if the version is like "major.minor.buildid.?"static VersionRead a file which should contain a single string containing a version number.static VersionParse a version string into a Version object.voidsetBuildid(int buildid) voidsetChannel(int channel) voidsetMajor(int major) voidsetMinor(int minor) voidsetTimestamp(long timestamp) inttoInt()Generate a 4-byte integer representing the three most relevant components of this version object.toString()Same asformat(true).
-
Field Details
-
RELEASE
public static final int RELEASERelease channel identifier.- See Also:
-
BETA
public static final int BETABeta channel identifier.- See Also:
-
ALPHA
public static final int ALPHAAlpha channel identifier.- See Also:
-
CHANNEL_STABLE
public static final int CHANNEL_STABLEAlias for the most stable supported channel.- See Also:
-
CHANNEL_MOST_UNSTABLE
public static final int CHANNEL_MOST_UNSTABLEAlias for the least stable built-in channel.- See Also:
-
-
Constructor Details
-
Version
Copy constructor.- Parameters:
v- a version object
-
Version
public Version(int major, int minor) Create a new version object "major.minor.0.0".- Parameters:
major- zero or positive numberminor- zero or positive number
-
Version
public Version(int major, int minor, int buildid) Create a new version object "major.minor.buildid.0".- Parameters:
major- zero or positive numberminor- zero or positive numberbuildid- zero or positive number
-
Version
public Version(int major, int minor, int buildid, long timestamp) Create a new version object "major.minor.buildid.timestamp".- Parameters:
major- zero or positive numberminor- zero or positive numberbuildid- zero or positive numbertimestamp- zero or positive number
-
Version
public Version(int major, int minor, int buildid, long timestamp, int channel) Create a new version object "major.minor.buildid.timestamp".- Parameters:
major- zero or positive numberminor- zero or positive numberbuildid- zero or positive numbertimestamp- zero or positive numberchannel- optional; 0=release, 1=beta, 2=alpha
-
-
Method Details
-
getChannelName
Get the symbolic name of a build channel.- Parameters:
channel- channel identifier- Returns:
- channel name
-
getChannelInfo
Get a user-facing description of a build channel.- Parameters:
channel- channel identifier- Returns:
- localized channel description
-
getChannelNames
Get the names of the built-in channels.- Returns:
- built-in channel names
-
create
Static builder, equivalent ofVersion(int, int).- Parameters:
major- major version numberminor- minor version number- Returns:
- created version object
-
create
Static builder, equivalent ofVersion(int, int, int).- Parameters:
major- major version numberminor- minor version numberbuildid- build identifier- Returns:
- created version object
-
create
Static builder, equivalent ofVersion(int, int, int, long).- Parameters:
major- major version numberminor- minor version numberbuildid- build identifiertimestamp- build timestamp- Returns:
- created version object
-
create
Static builder, equivalent ofVersion(int, int, int, long, int).- Parameters:
major- major version numberminor- minor version numberbuildid- build identifiertimestamp- build timestampchannel- channel identifier- Returns:
- created version object
-
getMajor
public int getMajor()Get the major number.- Returns:
- major version number
-
getMinor
public int getMinor()Get the minor number.- Returns:
- minor version number
-
getBuildid
public int getBuildid()Get the build id number.- Returns:
- build identifier
-
getTimestamp
public long getTimestamp()Get the timestamp.- Returns:
- build timestamp
-
getChannel
public int getChannel()Get the channel.- Returns:
- channel identifier
-
getChannelString
Get the textual channel suffix used by formatted versions.- Returns:
- channel suffix, or null for release builds
-
hashCode
public int hashCode() -
equals
-
compareTo
- Specified by:
compareToin interfaceComparable<Version>
-
compareToIgnoreTimestamp
Compare two versions while ignoring their timestamps.- Parameters:
o- other version- Returns:
- a negative integer, zero, or a positive integer as this version is less than, equal to, or greater than the other version under that comparison mode
-
compareToIgnoreChannel
Compare two versions while ignoring their channels.- Parameters:
o- other version- Returns:
- a negative integer, zero, or a positive integer as this version is less than, equal to, or greater than the other version under that comparison mode
-
compareToIgnoreTimestampAndChannel
Compare two versions while ignoring both their timestamps and channels.- Parameters:
o- other version- Returns:
- a negative integer, zero, or a positive integer as this version is less than, equal to, or greater than the other version under that comparison mode
-
like
public boolean like(int major) Determine if the version is like "major.?.?.?"- Parameters:
major- expected major version- Returns:
- true if the major version matches
-
like
public boolean like(int major, int minor) Determine if the version is like "major.minor.?.?"- Parameters:
major- expected major versionminor- expected minor version- Returns:
- true if the major and minor versions match
-
like
public boolean like(int major, int minor, int buildid) Determine if the version is like "major.minor.buildid.?"- Parameters:
major- expected major versionminor- expected minor versionbuildid- expected build identifier- Returns:
- true if the major, minor, and build identifier match
-
format
- Parameters:
useChannelString- true to format the channel (if present) as a string appended to the Minor version number; else, the channel value, if non 0, will be appended to the version Timestamp- Returns:
- formatted version string
-
formatCompact
Format the version using the numeric compact representation.- Returns:
- compact version string
-
toString
Same asformat(true). -
parseFromString
Parse a version string into a Version object.- Parameters:
s- a string- Returns:
- a version object, null on error
-
parseFromFile
Read a file which should contain a single string containing a version number.- Parameters:
f- a file- Returns:
- the version object, null on error
-
toInt
public int toInt()Generate a 4-byte integer representing the three most relevant components of this version object. The resulting int is as such: {00AABBCC} where AA=getMajor(), BB=getMinor(), CC=getBuildid(). If any of AA, BB, CC exceeds 255, it is truncated to 255.- Returns:
- a version-int
-
fromInt
Create a version object from an integer generated bytoInt().- Parameters:
val- a version-int, as generated bytoInt()- Returns:
- a version Object
-
setMajor
public void setMajor(int major) -
setMinor
public void setMinor(int minor) -
setBuildid
public void setBuildid(int buildid) -
setTimestamp
public void setTimestamp(long timestamp) -
setChannel
public void setChannel(int channel)
-