Package com.android.repository
Class Revision
- java.lang.Object
-
- com.android.repository.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRevision.Precisionstatic classRevision.PreviewComparisonIndicates how to compare the preview field incompareTo(Revision, PreviewComparison)
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringDEFAULT_SEPARATORstatic intIMPLICIT_MICRO_REVstatic intIMPLICIT_MINOR_REVstatic intMISSING_MAJOR_REVstatic intNOT_A_PREVIEWstatic RevisionNOT_SPECIFIED
-
Constructor Summary
Constructors Constructor Description Revision(int major)Creates a newRevisionwith the specified major revision and no other revision components.Revision(int major, int minor)Creates a newRevisionwith the specified major and minor revision components and no others.Revision(int major, int minor, int micro)Creates a newRevisionwith the specified major, minor, and micro revision components and no preview component.Revision(int major, int minor, int micro, int preview)Creates a newRevisionwith the specified components.Revision(int major, java.lang.Integer minor, java.lang.Integer micro, java.lang.Integer preview)Creates a newRevisionwith the specified components.Revision(Revision revision)Creates a copy of the specifiedRevision.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Revision rhs)Trivial comparison of a version, e.g 17.1.2 < 18.0.0.intcompareTo(Revision rhs, Revision.PreviewComparison comparePreview)Trivial comparison of a version, e.g 17.1.2 < 18.0.0.booleanequals(java.lang.Object rhs)Returnstrueif this revision is equal, including in precision torhs.intgetMajor()intgetMicro()intgetMinor()intgetPreview()protected java.lang.StringgetSeparator()inthashCode()booleanisPreview()static RevisionparseRevision(java.lang.String revisionString)Parses a string of format "major.minor.micro rcPreview" and returns a newRevisionfor it.static RevisionparseRevision(java.lang.String revisionString, Revision.Precision minimumPrecision)Parses a string of format "major.minor.micro rcPreview" and returns a newRevisionfor it.static RevisionsafeParseRevision(java.lang.String revisionString)A safe version ofparseRevision(java.lang.String, com.android.repository.Revision.Precision)that does not throw, but instead returns an unspecified revision if it fails to parse.int[]toIntArray(boolean includePreview)Returns anint[]containing the Major, Minor, and Micro (and optionally Preview) components (if specified) of this revisionjava.lang.StringtoShortString()Returns the version in a dynamic format "major.minor.micro rc#".java.lang.StringtoString()Returns the version in a fixed format major.minor.micro with an optional "rc preview#".java.lang.StringtoString(java.lang.String previewSeparator)Returns the version in a fixed format major.minor.micro with an optional "rc preview#".
-
-
-
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 newRevisionwith the specified major revision and no other revision components.
-
Revision
public Revision(int major, int minor)Creates a newRevisionwith the specified major and minor revision components and no others.
-
Revision
public Revision(@NonNull Revision revision)Creates a copy of the specifiedRevision.
-
Revision
public Revision(int major, int minor, int micro)Creates a newRevisionwith 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 newRevisionwith 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 newRevisionwith 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 newRevisionfor it. All the fields except major are optional.- Parameters:
revisionString- A non-null revisionString to parse.minimumPrecision- Create aRevisionwith at least the given precision, regardless of how precise therevisionStringis.- 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 newRevisionfor 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 ofrevisionString. - Throws:
java.lang.NumberFormatException- if the parsing failed.
-
safeParseRevision
@NonNull public static Revision safeParseRevision(@NonNull java.lang.String revisionString)
A safe version ofparseRevision(java.lang.String, com.android.repository.Revision.Precision)that does not throw, but instead returns an unspecified revision if it fails to parse.
-
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 bypreviewSeparator.
-
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:
toStringin classjava.lang.Object
-
toIntArray
@NonNull public int[] toIntArray(boolean includePreview)
Returns anint[]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
includePreviewis true, the result will always be of length 4.
-
equals
public boolean equals(@Nullable java.lang.Object rhs)Returnstrueif this revision is equal, including in precision torhs. That is,(new Revision(20)).equals(new Revision(20, 0, 0)will returnfalse.- Overrides:
equalsin classjava.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 totoString()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:
hashCodein classjava.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"
-
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 sideRevisionto compare with.comparePreview- How to compare the preview value.- Returns:
- <0 if lhs < rhs; 0 if lhs==rhs; >0 if lhs > rhs.
-
-