Class Version

java.lang.Object
com.pnfsoftware.jeb.core.Version
All Implemented Interfaces:
Comparable<Version>

@Ser public class Version extends Object implements 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.201807140000
 
Version objects can be persisted.
  • Field Details

    • RELEASE

      public static final int RELEASE
      Release channel identifier.
      See Also:
    • BETA

      public static final int BETA
      Beta channel identifier.
      See Also:
    • ALPHA

      public static final int ALPHA
      Alpha channel identifier.
      See Also:
    • CHANNEL_STABLE

      public static final int CHANNEL_STABLE
      Alias for the most stable supported channel.
      See Also:
    • CHANNEL_MOST_UNSTABLE

      public static final int CHANNEL_MOST_UNSTABLE
      Alias for the least stable built-in channel.
      See Also:
  • Constructor Details

    • Version

      public Version(Version v)
      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 number
      minor - 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 number
      minor - zero or positive number
      buildid - 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 number
      minor - zero or positive number
      buildid - zero or positive number
      timestamp - 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 number
      minor - zero or positive number
      buildid - zero or positive number
      timestamp - zero or positive number
      channel - optional; 0=release, 1=beta, 2=alpha
  • Method Details

    • getChannelName

      public static String getChannelName(int channel)
      Get the symbolic name of a build channel.
      Parameters:
      channel - channel identifier
      Returns:
      channel name
    • getChannelInfo

      public static String getChannelInfo(int channel)
      Get a user-facing description of a build channel.
      Parameters:
      channel - channel identifier
      Returns:
      localized channel description
    • getChannelNames

      public static String[] getChannelNames()
      Get the names of the built-in channels.
      Returns:
      built-in channel names
    • create

      public static Version create(int major, int minor)
      Static builder, equivalent of Version(int, int).
      Parameters:
      major - major version number
      minor - minor version number
      Returns:
      created version object
    • create

      public static Version create(int major, int minor, int buildid)
      Static builder, equivalent of Version(int, int, int).
      Parameters:
      major - major version number
      minor - minor version number
      buildid - build identifier
      Returns:
      created version object
    • create

      public static Version create(int major, int minor, int buildid, long timestamp)
      Static builder, equivalent of Version(int, int, int, long).
      Parameters:
      major - major version number
      minor - minor version number
      buildid - build identifier
      timestamp - build timestamp
      Returns:
      created version object
    • create

      public static Version create(int major, int minor, int buildid, long timestamp, int channel)
      Static builder, equivalent of Version(int, int, int, long, int).
      Parameters:
      major - major version number
      minor - minor version number
      buildid - build identifier
      timestamp - build timestamp
      channel - 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

      public String getChannelString()
      Get the textual channel suffix used by formatted versions.
      Returns:
      channel suffix, or null for release builds
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(Version o)
      Specified by:
      compareTo in interface Comparable<Version>
    • compareToIgnoreTimestamp

      public int compareToIgnoreTimestamp(Version o)
      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

      public int compareToIgnoreChannel(Version o)
      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

      public int compareToIgnoreTimestampAndChannel(Version o)
      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 version
      minor - 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 version
      minor - expected minor version
      buildid - expected build identifier
      Returns:
      true if the major, minor, and build identifier match
    • format

      public String format(boolean useChannelString)
      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

      public String formatCompact()
      Format the version using the numeric compact representation.
      Returns:
      compact version string
    • toString

      public String toString()
      Same as format(true).
      Overrides:
      toString in class Object
    • parseFromString

      public static Version parseFromString(String s)
      Parse a version string into a Version object.
      Parameters:
      s - a string
      Returns:
      a version object, null on error
    • parseFromFile

      public static Version parseFromFile(File f)
      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

      public static Version fromInt(int val)
      Create a version object from an integer generated by toInt().
      Parameters:
      val - a version-int, as generated by toInt()
      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)