Class VersionId
- java.lang.Object
-
- net.adoptopenjdk.icedteaweb.jnlp.version.VersionId
-
- All Implemented Interfaces:
java.lang.Comparable<VersionId>
public class VersionId extends java.lang.Object implements java.lang.Comparable<VersionId>
A version-id specifies the version that is associated with a resource, such as a JAR file. The version-id used in this specification must conform to the following syntax:version-id ::= string ( separator string ) * string ::= char ( char ) * char ::= any ASCII character except a space, an ampersand, a separator, or a modifier. separator ::= "." | "-" | "_" modifier ::= "+" | "*"See JSR-56 Specification, Appendix A.
- See Also:
JNLPVersionPatterns
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String[]tupleA version-id can be described as a tuple of values.private java.lang.StringversionIdprivate static java.lang.StringZERO_ELEMENT
-
Constructor Summary
Constructors Modifier Constructor Description privateVersionId(java.lang.String versionId)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.lang.String[]asNormalizedTuple(int normalizationLength)Normalizes a tuple to compare two version-ids.(package private) java.lang.String[]asTuple()NOTE: Package visible for testing - do not use this method outside of VersionId.VersionStringasVersionString()intcompareTo(VersionId versionId)booleanequals(java.lang.Object otherVersionId)static VersionIdfromString(java.lang.String versionId)Construct a version-id by the givenversionId.(package private) booleanisEqualTo(VersionId otherVersionId)Compares whether this version-id is equal to theotherVersionId.(package private) booleanisLessThan(VersionId otherVersionId)Compares whether this version-id is less thanotherVersionId.(package private) booleanisPrefixMatchOf(VersionId otherVersionId)A is a prefix matches of B if, when represented as tuples, the elements of A are the same as the first elements of B.private static java.lang.ObjectprepareForComparison(java.lang.String tupleValue)This method provides a tuple value as correct object (numeric or alphanumeric) for normalized comparison.java.lang.StringtoString()Provides a string representation of thisVersionId.
-
-
-
Field Detail
-
ZERO_ELEMENT
private static final java.lang.String ZERO_ELEMENT
- See Also:
- Constant Field Values
-
versionId
private final java.lang.String versionId
-
tuple
private final java.lang.String[] tuple
A version-id can be described as a tuple of values. A version-id string is broken in parts for each separator ('.', '-', or '_'). For example, "1.3.0-rc2-w" becomes (1,3,0,rc2,w), and "1.2.2-001" becomes (1,2,2,001).
-
-
Method Detail
-
fromString
public static VersionId fromString(java.lang.String versionId)
Construct a version-id by the givenversionId.- Parameters:
versionId- a version-id- Returns:
- a version-id
-
asVersionString
public VersionString asVersionString()
-
toString
public java.lang.String toString()
Provides a string representation of thisVersionId.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of this version-id
-
isEqualTo
boolean isEqualTo(VersionId otherVersionId)
Compares whether this version-id is equal to theotherVersionId.- Parameters:
otherVersionId- a version-id- Returns:
trueif this equals tootherVersionId,falseotherwise.
-
equals
public boolean equals(java.lang.Object otherVersionId)
- Overrides:
equalsin classjava.lang.Object
-
compareTo
public int compareTo(VersionId versionId)
- Specified by:
compareToin interfacejava.lang.Comparable<VersionId>
-
isPrefixMatchOf
boolean isPrefixMatchOf(VersionId otherVersionId)
A is a prefix matches of B if, when represented as tuples, the elements of A are the same as the first elements of B. The padding with 0 (zero element) entries ensures that B has at least as many elements as A. For example, given the above definition "1.2.1" will be a prefix matches to "1.2.1-004", but not to "1.2.0" or "1.2.10". The padding step ensures that "1.2.0.0" is a prefix of "1.2". Note that prefix matching and ordering are distinct: "1.3" is greater than "1.2", and less than "1.4", but not a prefix of either. See JSR-56 Specification, Appendix A.2 Prefix Match.- Parameters:
otherVersionId- a version-id- Returns:
trueif this version-id is a prefix matches ofotherVersionId,falseotherwise.
-
isLessThan
boolean isLessThan(VersionId otherVersionId)
Compares whether this version-id is less thanotherVersionId. A is less than B if, when represented as normalized tuples, there exists some element of A which is less than the corresponding element of B, and all earlier elements of A are the same as in B (see JSR-56 Specification, Appendix A.1 Ordering). Two numeric elements are compared numerically. Two alphanumeric elements are compared lexicographically according to the Unicode value of the individual characters. When one element is numeric and the other is alphanumeric, the alphanumeric element is greater than the numeric element. Numeric elements have lower precedence than non-numeric elements. See JSR-56 Specification, Appendix A- Parameters:
otherVersionId- a version-id- Returns:
trueif this version-id is less thanotherVersionId,falseotherwise.
-
asNormalizedTuple
java.lang.String[] asNormalizedTuple(int normalizationLength)
Normalizes a tuple to compare two version-ids. The tuple is padded with 0 (zero element) entries at the end. For example, to compare the tuples T1(1, 4) and T2(1, 4, 1) you need to normalize T2 to (1, 4, 0) first.NOTE: Package visible for testing - do not use this method outside of VersionId.
- Parameters:
normalizationLength- the tuple length to normalize to- Returns:
- the normalized tuple
-
prepareForComparison
private static java.lang.Object prepareForComparison(java.lang.String tupleValue)
This method provides a tuple value as correct object (numeric or alphanumeric) for normalized comparison. Each element in a tuple is either numeric or alphanumeric. An elements is numeric if it can be parsed as Java int, otherwise it is alphanumeric. Two numeric elements are compared numerically. Two alphanumeric elements are compared lexicographically according to the Unicode value of the individual characters. When one element is numeric and the other is alphanumeric, the alphanumeric element is greater than the numeric element. Numeric elements have lower precedence than non-numeric elements. See JSR-56 Specification, Appendix A- Parameters:
tupleValue- the raw tuple value- Returns:
- the tuple value suited for normalized comparison
-
asTuple
java.lang.String[] asTuple()
NOTE: Package visible for testing - do not use this method outside of VersionId.
-
-