Class Revision

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Revision>

    public class Revision
    extends java.lang.Object
    implements java.lang.Comparable<Revision>, java.io.Serializable
    The revision of an Android SDK package.

    Distinguishes between x and x.0, x.0.0, x.y.0: it keeps track of the precision of the revision string.

    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Revision​(int major)
      Creates a new Revision with the specified major revision and no other revision components.
      Revision​(int major, int minor)
      Creates a new Revision with the specified major and minor revision components and no others.
      Revision​(int major, int minor, int micro)
      Creates a new Revision with the specified major, minor, and micro revision components and no preview component.
      Revision​(int major, int minor, int micro, int preview)
      Creates a new Revision with the specified components.
      Revision​(int major, java.lang.Integer minor, java.lang.Integer micro, java.lang.Integer preview)
      Creates a new Revision with the specified components.
      Revision​(Revision revision)
      Creates a copy of the specified Revision.
    • Constructor Detail

      • Revision

        public Revision​(int major)
        Creates a new Revision with the specified major revision and no other revision components.
      • Revision

        public Revision​(int major,
                        int minor)
        Creates a new Revision with the specified major and minor revision components and no others.
      • Revision

        public Revision​(@NonNull
                        Revision revision)
        Creates a copy of the specified Revision.
      • Revision

        public Revision​(int major,
                        int minor,
                        int micro)
        Creates a new Revision with the specified major, minor, and micro revision components and no preview component.
      • Revision

        public Revision​(int major,
                        int minor,
                        int micro,
                        int preview)
        Creates a new Revision with the specified components.
      • Revision

        public Revision​(int major,
                        @Nullable
                        java.lang.Integer minor,
                        @Nullable
                        java.lang.Integer micro,
                        @Nullable
                        java.lang.Integer preview)
        Creates a new Revision with the specified components. The precision will be exactly sufficient to include all non-null components.
    • Method Detail

      • parseRevision

        @NonNull
        public static Revision parseRevision​(@NonNull
                                             java.lang.String revisionString,
                                             @NonNull
                                             Revision.Precision minimumPrecision)
                                      throws java.lang.NumberFormatException
        Parses a string of format "major.minor.micro rcPreview" and returns a new Revision for it. All the fields except major are optional.

        Parameters:
        revisionString - A non-null revisionString to parse.
        minimumPrecision - Create a Revision with at least the given precision, regardless of how precise the revisionString is.
        Returns:
        A new non-null Revision.
        Throws:
        java.lang.NumberFormatException - if the parsing failed.
      • parseRevision

        @NonNull
        public static Revision parseRevision​(@NonNull
                                             java.lang.String revisionString)
                                      throws java.lang.NumberFormatException
        Parses a string of format "major.minor.micro rcPreview" and returns a new Revision for it. All the fields except major are optional.

        Parameters:
        revisionString - A non-null revisionString to parse.
        Returns:
        A new non-null Revision, with precision depending on the precision of revisionString.
        Throws:
        java.lang.NumberFormatException - if the parsing failed.
      • toString

        public java.lang.String toString​(@NonNull
                                         java.lang.String previewSeparator)
        Returns the version in a fixed format major.minor.micro with an optional "rc preview#". For example it would return "18.0.0", "18.1.0" or "18.1.2 rc5", with the separator between the main version number and the preview component being specified by previewSeparator.
      • toString

        public java.lang.String toString()
        Returns the version in a fixed format major.minor.micro with an optional "rc preview#". For example it would return "18.0.0", "18.1.0" or "18.1.2 rc5". The character before "rc" is specified at construction time, and defaults to space.
        Overrides:
        toString in class java.lang.Object
      • toIntArray

        @NonNull
        public int[] toIntArray​(boolean includePreview)
        Returns an int[] containing the Major, Minor, and Micro (and optionally Preview) components (if specified) of this revision
        Parameters:
        includePreview - If false, the preview component of this revision will be ignored.
        Returns:
        An array exactly long enough to include the components specified in this revision. For example, if only Major and Minor revisions are specified the array will be of length 2. If a preview component is specified and includePreview is true, the result will always be of length 4.
      • equals

        public boolean equals​(@Nullable
                              java.lang.Object rhs)
        Returns true if this revision is equal, including in precision to rhs. That is, (new Revision(20)).equals(new Revision(20, 0, 0) will return false.
        Overrides:
        equals in class java.lang.Object
      • getMajor

        public int getMajor()
      • getMinor

        public int getMinor()
      • getMicro

        public int getMicro()
      • getSeparator

        @NonNull
        protected java.lang.String getSeparator()
      • isPreview

        public boolean isPreview()
      • getPreview

        public int getPreview()
      • toShortString

        @NonNull
        public java.lang.String toShortString()
        Returns the version in a dynamic format "major.minor.micro rc#". This is similar to toString() except it omits minor, micro or preview versions when they are zero. For example it would return "18 rc1" instead of "18.0.0 rc1", or "18.1 rc2" instead of "18.1.0 rc2".
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • compareTo

        public int compareTo​(@NonNull
                             Revision rhs)
        Trivial comparison of a version, e.g 17.1.2 < 18.0.0. Note that preview/release candidate are released before their final version, so "18.0.0 rc1" comes below "18.0.0". The best way to think of it as if the lack of preview number was "+inf": "18.1.2 rc5" ⇒ "18.1.2.5" so its less than "18.1.2.+INF" but more than "18.1.1.0" and more than "18.1.2.4"
        Specified by:
        compareTo in interface java.lang.Comparable<Revision>
        Parameters:
        rhs - The right-hand side Revision to compare with.
        Returns:
        <0 if lhs < rhs; 0 if lhs==rhs; >0 if lhs > rhs.
      • compareTo

        public int compareTo​(@NonNull
                             Revision rhs,
                             @NonNull
                             Revision.PreviewComparison comparePreview)
        Trivial comparison of a version, e.g 17.1.2 < 18.0.0. Note that preview/release candidate are released before their final version, so "18.0.0 rc1" comes below "18.0.0". The best way to think of it as if the lack of preview number was "+inf": "18.1.2 rc5" ⇒ "18.1.2.5" so its less than "18.1.2.+INF" but more than "18.1.1.0" and more than "18.1.2.4"
        Parameters:
        rhs - The right-hand side Revision to compare with.
        comparePreview - How to compare the preview value.
        Returns:
        <0 if lhs < rhs; 0 if lhs==rhs; >0 if lhs > rhs.