Interface Version<T extends Version<T>>

Type Parameters:
T - The version type (denotes which types this version can be compared with).
All Superinterfaces:
Comparable<T>
All Known Implementing Classes:
SemanticVersion

public interface Version<T extends Version<T>> extends Comparable<T>
A parsed representation of a version.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compareTo(@NonNull T other)
    Compares this version with the specified version.
    boolean
    equals(Object other)
    Indicates whether the other version object is equal to this one.
    default boolean
    isEquivalent(@NonNull T other)
    A convenience method that invokes compareTo(T) and checks whether the result is equal to zero.
    default boolean
    isGreaterThan(@NonNull T other)
    A convenience method that invokes compareTo(T) and checks whether the result is greater than zero.
    default boolean
    isLessThan(@NonNull T other)
    A convenience method that invokes compareTo(T) and checks whether the result is less than zero.
    @NonNull String
    Renders the version as either its original string, or a new equivalent string.
  • Method Details

    • compareTo

      int compareTo(@NonNull T other)
      Compares this version with the specified version.

      The comparison adheres to the Comparable specification and semantics.

      Specified by:
      compareTo in interface Comparable<T extends Version<T>>
      Parameters:
      other - the object to be compared.
      Returns:
      a negative integer if this version is less than the other version, zero if the versions are equal or a positive integer if this version is greater than the other version.
      Throws:
      NullPointerException - If the other version is null.
    • isLessThan

      default boolean isLessThan(@NonNull T other)
      A convenience method that invokes compareTo(T) and checks whether the result is less than zero.
      Parameters:
      other - The other version.
      Returns:
      True if, and only if, the other version is less than this version.
    • isEquivalent

      default boolean isEquivalent(@NonNull T other)
      A convenience method that invokes compareTo(T) and checks whether the result is equal to zero.

      This is NOT necessarily the same as equals(Object). This method follows the semantics of the version specification rather than of Java objects (for the latter, use equals(Object)). The implementation notes of the concrete version type should provide more specific details.

      Parameters:
      other - The other version.
      Returns:
      True if, and only if, the other version is considered equivalent per the version's specification.
      See Also:
    • isGreaterThan

      default boolean isGreaterThan(@NonNull T other)
      A convenience method that invokes compareTo(T) and checks whether the result is greater than zero.
      Parameters:
      other - The other version.
      Returns:
      True if, and only if, the other version is greater than this version.
    • equals

      boolean equals(Object other)
      Indicates whether the other version object is equal to this one.

      This follows the semantics of Object.equals(Object) and is intended for comparing version object values (the representation rather than the semantics) with each other.

      This method does not necessarily follow the ordering or semantics of equality of the version specification. For that use case, instead use isEquivalent(Version).

      For example, Semantic Versioning (SemVer) stipulates that build metadata not be considered in precedence, but it is still part of the version string, so for versions that differ only by build metadata, equals would return false and isEquivalent(Version) would return true.

      Overrides:
      equals in class Object
      Parameters:
      other - The other version.
      Returns:
      True if, and only if, the other version's value is identical in that it would produce the exact same representation.
      See Also:
    • toString

      @NonNull String toString()
      Renders the version as either its original string, or a new equivalent string.
      Overrides:
      toString in class Object
      Returns:
      The string form of the version.