Class Version

  • All Implemented Interfaces:
    java.lang.Comparable<Version>

    public class Version
    extends java.lang.Object
    implements java.lang.Comparable<Version>
    Represents the version of an import.
    Author:
    Marcel Lueder, Holger Eichelberger, Pastusch
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Version NULL_VALUE  
      private static java.util.regex.Pattern PATTERN  
      private int[] segments  
      private static java.lang.String SEPARATOR  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Version()
      Represents the null-Version (not given).
        Version​(int... version)
      Constructor of the version class.
        Version​(java.lang.String version)
      Creates a new version by parsing a string.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static int compare​(Version version1, Version version2)
      Compares two versions considering null for both parameters and results in: -1 : this is smaller <=> given version and this is bigger.
      int compareTo​(Version version)
      Compares two versions and results in: -1 : this is smaller <=> given version and this is bigger.
      boolean equals​(java.lang.Object obj)  
      static boolean equals​(Version version1, Version version2)
      Returns whether two versions are equal.
      Version getIncrementedVersion()
      Returns a version that is one higher in the first segment than the actual version.
      int getSegment​(int index)
      Returns the version segment specified by index.
      int getSegmentCount()
      Returns the number of the segments.
      java.lang.String getVersion()
      Returns the version in a textual form.
      int hashCode()  
      static boolean isVersion​(java.lang.String string)
      Returns whether the given string denotes a version.
      java.lang.String toString()
      Returns a textual representation of this instance.
      static java.lang.String toString​(Version version)
      Returns the textual version of version (null-safe).
      • Methods inherited from class java.lang.Object

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

      • NULL_VALUE

        public static final Version NULL_VALUE
      • PATTERN

        private static final java.util.regex.Pattern PATTERN
      • segments

        private int[] segments
    • Constructor Detail

      • Version

        private Version()
        Represents the null-Version (not given).
      • Version

        public Version​(java.lang.String version)
                throws VersionFormatException
        Creates a new version by parsing a string.
        Parameters:
        version - the version string in form i(.i)* with i integer numbers
        Throws:
        VersionFormatException - in case of format problems
      • Version

        public Version​(int... version)
        Constructor of the version class.
        Parameters:
        version - Version number
    • Method Detail

      • isVersion

        public static final boolean isVersion​(java.lang.String string)
        Returns whether the given string denotes a version.
        Parameters:
        string - the string to be tested
        Returns:
        trueif string is a version, false else
      • getVersion

        public java.lang.String getVersion()
        Returns the version in a textual form.
        Returns:
        the version in textual form
      • getSegmentCount

        public int getSegmentCount()
        Returns the number of the segments.
        Returns:
        the number of segments
      • getSegment

        public int getSegment​(int index)
        Returns the version segment specified by index.
        Parameters:
        index - a 0-based index specifying the segment to be returned
        Returns:
        the specified segment
        Throws:
        java.lang.IndexOutOfBoundsException - if index<0 || index>=getSegmentCount()
      • compareTo

        public int compareTo​(Version version)
        Compares two versions and results in: -1 : this is smaller <=> given version and this is bigger. 0 : given version and this are equal. +1 : this is bigger <=> given version is smaller.
        Specified by:
        compareTo in interface java.lang.Comparable<Version>
        Parameters:
        version - version to compare.
        Returns:
        result in {-1, 0, 1}.
      • toString

        public java.lang.String toString()
        Returns a textual representation of this instance.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a textual representation
      • toString

        public static java.lang.String toString​(Version version)
        Returns the textual version of version (null-safe).
        Parameters:
        version - the version to be converted into text
        Returns:
        the textual representation
      • equals

        public static boolean equals​(Version version1,
                                     Version version2)
        Returns whether two versions are equal.
        Parameters:
        version1 - the first version instance (may be null)
        version2 - the second version instance (may be null)
        Returns:
        true if version1 equals version2, false else
      • compare

        public static int compare​(Version version1,
                                  Version version2)
        Compares two versions considering null for both parameters and results in: -1 : this is smaller <=> given version and this is bigger. 0 : given version and this are equal. +1 : this is bigger <=> given version is smaller.
        Parameters:
        version1 - the first version to compare.
        version2 - the second version to compare.
        Returns:
        result in {-1, 0, 1}.
      • getIncrementedVersion

        public Version getIncrementedVersion()
                                      throws VersionFormatException
        Returns a version that is one higher in the first segment than the actual version.
        Returns:
        A version that is increased by one in the first segment.
        Throws:
        VersionFormatException - in case of format problems.
      • hashCode

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

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object