Class Version

java.lang.Object
com.day.cq.commons.Version
All Implemented Interfaces:
Comparable<Version>

public class Version extends Object implements Comparable<Version>
Implements a version.
  • Field Details

    • EMPTY

      public static final Version EMPTY
      The empty version
  • Method Details

    • create

      public static Version create(String str)
      Creates a new version from the given string.
      Parameters:
      str - the version string.
      Returns:
      the new version or EMPTY if str is an empty string.
    • create

      public static Version create(String[] segments)
      Creates a new version from version segments
      Parameters:
      segments - version segments
      Returns:
      the new version or EMPTY if segments is empty.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getNormalizedSegments

      public String[] getNormalizedSegments()
      Returns all segments.
      Returns:
      all segments.
    • compareTo

      public int compareTo(Version o)
      Compares this version to the given one, segment by segment with a special "SNAPSHOT" handling. Examples:
      "1" < "2"
      "1.0" < "2"
      "2.0.1" < "2.1"
      "2.1" < "2.1.1"
      "2.1" < "2.1-SNAPSHOT"
      "2.1" < "2.1-R1234556"
      "2.1-R12345" < "2.1-SNAPSHOT"
      Specified by:
      compareTo in interface Comparable<Version>
      Parameters:
      o - the other version
      Returns:
      a negative integer, zero, or a positive integer as this version is less than, equal to, or greater than the specified version.