Class VersionId

java.lang.Object
net.adoptopenjdk.icedteaweb.jnlp.version.VersionId
All Implemented Interfaces:
Comparable<VersionId>

public class VersionId extends Object implements 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:
  • Field Details

    • ZERO_ELEMENT

      private static final String ZERO_ELEMENT
      See Also:
    • versionId

      private final String versionId
    • tuple

      private final 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).

  • Constructor Details

    • VersionId

      private VersionId(String versionId)
  • Method Details

    • fromString

      public static VersionId fromString(String versionId)
      Construct a version-id by the given versionId.
      Parameters:
      versionId - a version-id
      Returns:
      a version-id
    • asVersionString

      public VersionString asVersionString()
    • toString

      public String toString()
      Provides a string representation of this VersionId.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this version-id
    • isEqualTo

      boolean isEqualTo(VersionId otherVersionId)
      Compares whether this version-id is equal to the otherVersionId.
      Parameters:
      otherVersionId - a version-id
      Returns:
      true if this equals to otherVersionId, false otherwise.
    • equals

      public boolean equals(Object otherVersionId)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(VersionId versionId)
      Specified by:
      compareTo in interface 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:
      true if this version-id is a prefix matches of otherVersionId, false otherwise.
    • isLessThan

      boolean isLessThan(VersionId otherVersionId)
      Compares whether this version-id is less than otherVersionId.

      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:
      true if this version-id is less than otherVersionId, false otherwise.
    • asNormalizedTuple

      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 Object prepareForComparison(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

      String[] asTuple()
      NOTE: Package visible for testing - do not use this method outside of VersionId.