com.android.repository
Class Revision

java.lang.Object
  extended by com.android.repository.Revision
All Implemented Interfaces:
java.lang.Comparable<Revision>

public class Revision
extends java.lang.Object
implements java.lang.Comparable<Revision>

A Revision which distinguishes between x and x.0, x.0.0, x.y.0, etc; it basically keeps track of the precision of the revision string.

This is vital when referencing Gradle artifact numbers, since versions x.y.0 and version x.y are not the same.


Nested Class Summary
static class Revision.Precision
           
static class Revision.PreviewComparison
          Indicates how to compare the preview field in compareTo(Revision, PreviewComparison)
 
Field Summary
protected static java.lang.String DEFAULT_SEPARATOR
           
static int IMPLICIT_MICRO_REV
           
static int IMPLICIT_MINOR_REV
           
static int MISSING_MAJOR_REV
           
static int NOT_A_PREVIEW
           
static Revision NOT_SPECIFIED
           
 
Constructor Summary
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, java.lang.Integer minor, java.lang.Integer micro, java.lang.Integer preview)
          Creates a new Revision with the specified components.
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(Revision revision)
          Creates a copy of the specified Revision.
 
Method Summary
 int compareTo(Revision rhs)
          Trivial comparison of a version, e.g 17.1.2 < 18.0.0.
 int compareTo(Revision rhs, Revision.PreviewComparison comparePreview)
          Trivial comparison of a version, e.g 17.1.2 < 18.0.0.
 boolean equals(java.lang.Object rhs)
          Returns true if this revision is equal, including in precision to rhs.
 int getMajor()
           
 int getMicro()
           
 int getMinor()
           
 int getPreview()
           
protected  java.lang.String getSeparator()
           
 int hashCode()
           
 boolean isPreview()
           
static Revision parseRevision(java.lang.String revisionString)
          Parses a string of format "major.minor.micro rcPreview" and returns a new Revision for it.
static Revision parseRevision(java.lang.String revisionString, Revision.Precision minimumPrecision)
          Parses a string of format "major.minor.micro rcPreview" and returns a new Revision for it.
 int[] toIntArray(boolean includePreview)
          Returns an int[] containing the Major, Minor, and Micro (and optionally Preview) components (if specified) of this revision
 java.lang.String toShortString()
          Returns the version in a dynamic format "major.minor.micro rc#".
 java.lang.String toString()
          Returns the version in a fixed format major.minor.micro with an optional "rc preview#".
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MISSING_MAJOR_REV

public static final int MISSING_MAJOR_REV
See Also:
Constant Field Values

IMPLICIT_MINOR_REV

public static final int IMPLICIT_MINOR_REV
See Also:
Constant Field Values

IMPLICIT_MICRO_REV

public static final int IMPLICIT_MICRO_REV
See Also:
Constant Field Values

NOT_A_PREVIEW

public static final int NOT_A_PREVIEW
See Also:
Constant Field Values

NOT_SPECIFIED

public static final Revision NOT_SPECIFIED

DEFAULT_SEPARATOR

protected static final java.lang.String DEFAULT_SEPARATOR
See Also:
Constant Field Values
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()
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".

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.