Class Version

java.lang.Object
io.github.g00fy2.versioncompare.Version
All Implemented Interfaces:
Comparable<Version>

public class Version extends Object implements Comparable<Version>
  • Constructor Summary

    Constructors
    Constructor
    Description
    Version(@Nullable String versionString)
    Initializes a newly created Version object that represents the parsed version information.
    Version(@Nullable String versionString, boolean throwExceptions)
    Initializes a newly created Version object that represents the parsed version information.
  • Method Summary

    Modifier and Type
    Method
    Description
    final int
    compareTo(@NotNull Version version)
     
    final boolean
     
    long
    Returns the major version.
    long
    Returns the minor version.
    @Nullable String
    Returns the initial string
    long
    Returns the patch version.
    @NotNull List<@NotNull Long>
    Returns a list with all numeric version parts.
    @NotNull String
    Returns the suffix.
    final int
     
    boolean
    isAtLeast(Version otherVersion)
    Checks if the Version object is equal or higher than otherVersion.
    boolean
    isAtLeast(Version otherVersion, boolean ignoreSuffix)
    Checks if the Version object is equal or higher than otherVersion.
    boolean
    isAtLeast(String otherVersion)
    Checks if the Version object is equal or higher than otherVersion.
    boolean
    isAtLeast(String otherVersion, boolean ignoreSuffix)
    Checks if the Version object is equal or higher than otherVersion.
    boolean
    isEqual(Version otherVersion)
    Checks if the Version object is equal to otherVersion.
    boolean
    isEqual(String otherVersion)
    Checks if the Version object is equal to otherVersion.
    boolean
    isHigherThan(Version otherVersion)
    Checks if the Version object is higher than otherVersion.
    boolean
    isHigherThan(String otherVersion)
    Checks if the Version object is higher than otherVersion.
    boolean
    isLowerThan(Version otherVersion)
    Checks if the Version object is lower than otherVersion.
    boolean
    isLowerThan(String otherVersion)
    Checks if the Version object is lower than otherVersion.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Version

      public Version(@Nullable @Nullable String versionString)
      Initializes a newly created Version object that represents the parsed version information. Will have default values if versionString could not get parsed.
      Parameters:
      versionString - the string representing the version.
      See Also:
    • Version

      public Version(@Nullable @Nullable String versionString, boolean throwExceptions)
      Initializes a newly created Version object that represents the parsed version information. Throws exceptions if throwExceptions is true and versionString could not get parsed.
      Parameters:
      versionString - the string representing the version.
      throwExceptions - controls whether invalid versionString should cause exceptions.
      Throws:
      NullPointerException - if versionString is null.
      IllegalArgumentException - if versionString does not start with a numeric character.
      See Also:
  • Method Details

    • getMajor

      public long getMajor()
      Returns the major version.
      Returns:
      the major version, default 0.
    • getMinor

      public long getMinor()
      Returns the minor version.
      Returns:
      the minor version, default 0.
    • getPatch

      public long getPatch()
      Returns the patch version.
      Returns:
      the patch version, default 0.
    • getSubversionNumbers

      @NotNull public @NotNull List<@NotNull Long> getSubversionNumbers()
      Returns a list with all numeric version parts.
      Returns:
      a list with all numeric version parts found, default empty.
    • getSuffix

      @NotNull public @NotNull String getSuffix()
      Returns the suffix.
      Returns:
      the suffix (first non-numeric part), default empty.
    • getOriginalString

      @Nullable public @Nullable String getOriginalString()
      Returns the initial string
      Returns:
      the unmodified initial string.
    • isHigherThan

      public boolean isHigherThan(String otherVersion)
      Checks if the Version object is higher than otherVersion.
      Parameters:
      otherVersion - a string representing another version.
      Returns:
      true if Version object is higher than otherVersion or otherVersion could not get parsed. False if the Version is lower or equal.
      See Also:
    • isHigherThan

      public boolean isHigherThan(Version otherVersion)
      Checks if the Version object is higher than otherVersion.
      Parameters:
      otherVersion - a Version object representing another version.
      Returns:
      true if Version object is higher than otherVersion or otherVersion could not get parsed. False if the Version is lower or equal.
      See Also:
    • isLowerThan

      public boolean isLowerThan(String otherVersion)
      Checks if the Version object is lower than otherVersion.
      Parameters:
      otherVersion - a string representing another version.
      Returns:
      true if Version object is lower than otherVersion. False if the Version is higher, equal or otherVersion could not get parsed.
      See Also:
    • isLowerThan

      public boolean isLowerThan(Version otherVersion)
      Checks if the Version object is lower than otherVersion.
      Parameters:
      otherVersion - a Version object representing another version.
      Returns:
      true if Version object is lower than otherVersion. False if the Version is higher, equal or otherVersion could not get parsed.
      See Also:
    • isEqual

      public boolean isEqual(String otherVersion)
      Checks if the Version object is equal to otherVersion.
      Parameters:
      otherVersion - a string representing another version.
      Returns:
      true if Version object and otherVersion are logically equal. False if the Version is higher, lower or otherVersion could not get parsed.
      See Also:
    • isEqual

      public boolean isEqual(Version otherVersion)
      Checks if the Version object is equal to otherVersion.
      Parameters:
      otherVersion - a Version object representing another version.
      Returns:
      true if Version object and otherVersion are logically equal. False if the Version is higher, lower or otherVersion could not get parsed.
      See Also:
    • isAtLeast

      public boolean isAtLeast(String otherVersion)
      Checks if the Version object is equal or higher than otherVersion.
      Parameters:
      otherVersion - a string representing another version.
      Returns:
      true if the version is equal or higher than otherVersion. False if the version is lower than otherVersion.
      See Also:
    • isAtLeast

      public boolean isAtLeast(Version otherVersion)
      Checks if the Version object is equal or higher than otherVersion.
      Parameters:
      otherVersion - a Version object representing another version.
      Returns:
      true if the version is equal or higher than otherVersion. False if the version is lower than otherVersion.
      See Also:
    • isAtLeast

      public boolean isAtLeast(String otherVersion, boolean ignoreSuffix)
      Checks if the Version object is equal or higher than otherVersion.
      Parameters:
      otherVersion - a string representing another version.
      ignoreSuffix - controls whether suffixes should be ignored.
      Returns:
      true if the version is equal or higher than otherVersion. False if the version is lower than otherVersion.
      See Also:
    • isAtLeast

      public boolean isAtLeast(Version otherVersion, boolean ignoreSuffix)
      Checks if the Version object is equal or higher than otherVersion.
      Parameters:
      otherVersion - a Version object representing another version.
      ignoreSuffix - controls whether suffixes should be ignored.
      Returns:
      true if the version is equal or higher than otherVersion. False if the version is lower than otherVersion.
      See Also:
    • compareTo

      public final int compareTo(@NotNull @NotNull Version version)
      Specified by:
      compareTo in interface Comparable<Version>
    • equals

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

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object