Class Version

  • All Implemented Interfaces:
    java.lang.Comparable<Version>

    public class Version
    extends java.lang.Object
    implements java.lang.Comparable<Version>
    Container for Version information in the form of major.minor.revision-tag.
    Since:
    1.0-beta-1
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int major
      The version major number.
      private int minor
      The version minor number.
      private int revision
      The version revision.
      private java.lang.String tag
      The version tag.
    • Constructor Summary

      Constructors 
      Constructor Description
      Version​(int newMajor)
      Constructs a new Version object with the specified parameters.
      Version​(int newMajor, int newMinor)
      Constructs a new Version object with the specified parameters.
      Version​(int newMajor, int newMinor, int newRevision)
      Constructs a new Version object with the specified parameters.
      Version​(int newMajor, int newMinor, int newRevision, java.lang.String newTag)
      Constructs a new version object with the specified parameters.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(Version version)
      Compares two versions objects.
      int compareTo​(Version version, boolean noTagsAreNewer)
      Compares two versions objects.
      boolean equals​(java.lang.Object obj)
      Determines whether the specified object is equal to this object.
      int getMajor()
      Gets the version major number.
      int getMinor()
      Gets the version minor number.
      int getRevision()
      Gets the version revision number.
      java.lang.String getTag()
      Gets the version tag string.
      int hashCode()
      Returns a hash code for this object.
      static Version parseFromString​(java.lang.String version)
      Parses a new Version object from a string.
      Version setMajor​(int newMajor)
      Sets the version major number.
      Version setMinor​(int newMinor)
      Sets the version minor number.
      Version setRevision​(int newRevision)
      Sets the version revision number.
      Version setTag​(java.lang.String newTag)
      Sets the version tag string.
      java.lang.String toString()
      Returns a String representation of this object.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • major

        private int major
        The version major number.
      • minor

        private int minor
        The version minor number.
      • revision

        private int revision
        The version revision.
      • tag

        private java.lang.String tag
        The version tag.
    • Constructor Detail

      • Version

        public Version​(int newMajor,
                       int newMinor,
                       int newRevision,
                       java.lang.String newTag)
        Constructs a new version object with the specified parameters.
        Parameters:
        newMajor - The version major number
        newMinor - The version minor number
        newRevision - The version revision number
        newTag - The version tag string
      • Version

        public Version​(int newMajor,
                       int newMinor,
                       int newRevision)
        Constructs a new Version object with the specified parameters.
        Parameters:
        newMajor - The version major number
        newMinor - The version minor number
        newRevision - The version revision number
      • Version

        public Version​(int newMajor,
                       int newMinor)
        Constructs a new Version object with the specified parameters.
        Parameters:
        newMajor - The version major number
        newMinor - The version minor number
      • Version

        public Version​(int newMajor)
        Constructs a new Version object with the specified parameters.
        Parameters:
        newMajor - The version major number
    • Method Detail

      • parseFromString

        public static Version parseFromString​(java.lang.String version)
        Parses a new Version object from a string.
        Parameters:
        version - The version string to parse
        Returns:
        The version parsed from the string
      • hashCode

        public final int hashCode()
        Returns a hash code for this object.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The hash code for this object
        See Also:
        Object.hashCode()
      • equals

        public final boolean equals​(java.lang.Object obj)
        Determines whether the specified object is equal to this object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - The object to compare to this object
        Returns:
        true if the specified object is equal to this object, false otherwise
        See Also:
        Object.equals(java.lang.Object)
      • toString

        public final java.lang.String toString()
        Returns a String representation of this object.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The String representation of this object
        See Also:
        Object.toString()
      • compareTo

        public final int compareTo​(Version version)
        Compares two versions objects. Note that if the major, minor, and revision are all the same, tags are compared with String.compareTo(). Having no tag is considered a newer version than a version with a tag.
        Specified by:
        compareTo in interface java.lang.Comparable<Version>
        Parameters:
        version - The version to compare this version to
        Returns:
        0 if the version is equal to this version, 1 if the version is greater than this version, or -1 if the version is lower than this version.
      • compareTo

        public final int compareTo​(Version version,
                                   boolean noTagsAreNewer)
        Compares two versions objects. Note that if the major, minor, and revision are all the same, tags are compared with String.compareTo().
        Parameters:
        version - The version to compare this version to
        noTagsAreNewer - Whether versions with no tag are considered newer than those that have tags
        Returns:
        0 if the version is equal to this version, 1 if the version is greater than this version, or -1 if the version is lower than this version.
      • getMajor

        public int getMajor()
        Gets the version major number.
        Returns:
        The major version number
      • setMajor

        public Version setMajor​(int newMajor)
        Sets the version major number.
        Parameters:
        newMajor - The major version number to set
        Returns:
        This object (for fluent invocation)
      • getMinor

        public int getMinor()
        Gets the version minor number.
        Returns:
        The version minor number
      • setMinor

        public Version setMinor​(int newMinor)
        Sets the version minor number.
        Parameters:
        newMinor - The version minor number to set
        Returns:
        This object (for fluent invocation)
      • getRevision

        public int getRevision()
        Gets the version revision number.
        Returns:
        The version revision number
      • setRevision

        public Version setRevision​(int newRevision)
        Sets the version revision number.
        Parameters:
        newRevision - The revision number to set
        Returns:
        This object (for fluent invocation)
      • getTag

        public java.lang.String getTag()
        Gets the version tag string.
        Returns:
        The version tag string
      • setTag

        public Version setTag​(java.lang.String newTag)
        Sets the version tag string.
        Parameters:
        newTag - The version tag string to set
        Returns:
        This object (for fluent invocation)