Class 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[] tuple
      A version-id can be described as a tuple of values.
      private java.lang.String versionId  
      private static java.lang.String ZERO_ELEMENT  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private VersionId​(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.
      VersionString asVersionString()  
      int compareTo​(VersionId versionId)  
      boolean equals​(java.lang.Object otherVersionId)  
      static VersionId fromString​(java.lang.String versionId)
      Construct a version-id by the given versionId.
      (package private) boolean isEqualTo​(VersionId otherVersionId)
      Compares whether this version-id is equal to the otherVersionId.
      (package private) boolean isLessThan​(VersionId otherVersionId)
      Compares whether this version-id is less than otherVersionId.
      (package private) 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.
      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.
      java.lang.String toString()
      Provides a string representation of this VersionId.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • 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).

    • Constructor Detail

      • VersionId

        private VersionId​(java.lang.String versionId)
    • Method Detail

      • fromString

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

        public java.lang.String toString()
        Provides a string representation of this VersionId.
        Overrides:
        toString in class java.lang.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​(java.lang.Object otherVersionId)
        Overrides:
        equals in class java.lang.Object
      • compareTo

        public int compareTo​(VersionId versionId)
        Specified by:
        compareTo in interface java.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:
        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

        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.