com.android.sdklib.repository
Class FullRevision

java.lang.Object
  extended by com.android.sdklib.repository.FullRevision
All Implemented Interfaces:
java.lang.Comparable<FullRevision>
Direct Known Subclasses:
MajorRevision, NoPreviewRevision

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

Package multi-part revision number composed of a tuple (major.minor.micro) and an optional preview revision (the lack of a preview number indicates it's not a preview but a final package.)

See Also:
MajorRevision

Nested Class Summary
static class FullRevision.PreviewComparison
          Indicates how to compare the preview field in compareTo(FullRevision, PreviewComparison)
 
Field Summary
static int IMPLICIT_MICRO_REV
           
static int IMPLICIT_MINOR_REV
           
static int MISSING_MAJOR_REV
           
static int NOT_A_PREVIEW
           
static FullRevision NOT_SPECIFIED
           
 
Constructor Summary
FullRevision(int major)
           
FullRevision(int major, int minor, int micro)
           
FullRevision(int major, int minor, int micro, int preview)
           
 
Method Summary
 int compareTo(FullRevision rhs)
          Trivial comparison of a version, e.g 17.1.2 < 18.0.0.
 int compareTo(FullRevision rhs, FullRevision.PreviewComparison comparePreview)
          Trivial comparison of a version, e.g 17.1.2 < 18.0.0.
 boolean equals(java.lang.Object rhs)
           
 int getMajor()
           
 int getMicro()
           
 int getMinor()
           
 int getPreview()
           
 int hashCode()
           
 boolean isPreview()
           
static FullRevision parseRevision(java.lang.String revision)
          Parses a string of format "major.minor.micro rcPreview" and returns a new FullRevision for it.
protected static FullRevision parseRevisionImpl(java.lang.String revision, boolean supportMinorMicro, boolean supportPreview)
           
 int[] toIntArray(boolean includePreview)
          Returns the version number as an integer array, in the form [major, minor, micro] or [major, minor, micro, preview].
 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 FullRevision NOT_SPECIFIED
Constructor Detail

FullRevision

public FullRevision(int major)

FullRevision

public FullRevision(int major,
                    int minor,
                    int micro)

FullRevision

public FullRevision(int major,
                    int minor,
                    int micro,
                    int preview)
Method Detail

getMajor

public int getMajor()

getMinor

public int getMinor()

getMicro

public int getMicro()

isPreview

public boolean isPreview()

getPreview

public int getPreview()

parseRevision

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

The parsing is equivalent to the pseudo-BNF/regexp:

   Major/Minor/Micro/Preview := [0-9]+
   Revision := Major ('.' Minor ('.' Micro)? )? \s* ('rc'Preview)?
 

Parameters:
revision - A non-null revision to parse.
Returns:
A new non-null FullRevision.
Throws:
java.lang.NumberFormatException - if the parsing failed.

parseRevisionImpl

@NonNull
protected static FullRevision parseRevisionImpl(@NonNull
                                                        java.lang.String revision,
                                                        boolean supportMinorMicro,
                                                        boolean supportPreview)
                                         throws java.lang.NumberFormatException
Throws:
java.lang.NumberFormatException

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

toShortString

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".


toIntArray

public int[] toIntArray(boolean includePreview)
Returns the version number as an integer array, in the form [major, minor, micro] or [major, minor, micro, preview]. This is useful to initialize an instance of org.apache.tools.ant.util.DeweyDecimal using a FullRevision.

Parameters:
includePreview - If true the output will contain 4 fields to include the preview number (even if 0.) If false the output will contain only 3 fields (major, minor and micro.)
Returns:
A new int array, never null, with either 3 or 4 fields.

hashCode

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

equals

public boolean equals(java.lang.Object rhs)
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(FullRevision 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<FullRevision>
Parameters:
rhs - The right-hand side FullRevision to compare with.
Returns:
<0 if lhs < rhs; 0 if lhs==rhs; >0 if lhs > rhs.

compareTo

public int compareTo(FullRevision rhs,
                     FullRevision.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 FullRevision to compare with.
comparePreview - How to compare the preview value.
Returns:
<0 if lhs < rhs; 0 if lhs==rhs; >0 if lhs > rhs.