Class VersionSpec

java.lang.Object
com.dua3.gradle.jdkprovider.types.VersionSpec

@NullMarked public final class VersionSpec extends Object
Represents a version specification with a range defined by minimum and maximum versions. This class allows specifying whether the boundaries of the range are inclusive or exclusive. It provides utility methods for common version specifications, such as the latest version, any version, or a specific version.
  • Method Summary

    Modifier and Type
    Method
    Description
    any()
    Creates a VersionSpec instance that matches any version.
    Retrieves the current runtime version and constructs a VersionSpec object representing the major, minor, patch, and build versions.
    boolean
     
    int
     
    boolean
    Determines if this instance refers to a fixed feature only, i.e., represents a single Java feature version with no interim, update, etc fields set.
    Creates a VersionSpec instance representing the latest version.
    Returns a VersionSpec instance representing the latest Long-Term Support (LTS) version.
    boolean
    Determines if the specified runtime version falls within the range defined by the current VersionSpec instance.
    min()
    Retrieves the minimum runtime version specified by this VersionSpec.
    Creates a VersionSpec instance based on the specified runtime version.
    Parses a string representation of a version specification.
     

    Methods inherited from class java.lang.Object

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

    • toString

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

      public static VersionSpec of(Runtime.Version v)
      Creates a VersionSpec instance based on the specified runtime version. The resulting VersionSpec includes the given version, the next version, and the string representation of the version.
      Parameters:
      v - the Runtime.Version object representing the version to base the VersionSpec on
      Returns:
      a VersionSpec instance constructed from the specified runtime version
    • current

      public static VersionSpec current()
      Retrieves the current runtime version and constructs a VersionSpec object representing the major, minor, patch, and build versions.
      Returns:
      a VersionSpec object representing the current runtime version, with the feature version as the major, the interim version as the minor, the update version as the patch, and the build version as the build.
    • latest

      public static VersionSpec latest()
      Creates a VersionSpec instance representing the latest version. The latest version is defined as having the maximum possible major version value, with minor, patch, and build versions unspecified.
      Returns:
      a VersionSpec instance representing the latest version.
    • latestLts

      public static VersionSpec latestLts()
      Returns a VersionSpec instance representing the latest Long-Term Support (LTS) version. The latest LTS version is defined as the most recent version officially designated as LTS.
      Returns:
      a VersionSpec instance representing the latest LTS version.
    • any

      public static VersionSpec any()
      Creates a VersionSpec instance that matches any version.
      Returns:
      a VersionSpec instance representing any version.
    • parse

      public static VersionSpec parse(String s)
      Parses a string representation of a version specification.

      Supported formats:

      • "any": matches any version
      • "latest": matches the latest version
      • "latest_lts": matches the latest LTS version
      • "X.Y.Z": matches a specific version
      • "X..Y": matches versions from X to Y (inclusive)
      • "X..<Y": matches versions from X (inclusive) to Y (exclusive)
      • ">X..Y": matches versions from X (exclusive) to Y (inclusive)
      • ">X..<Y": matches versions from X (exclusive) to Y (exclusive)
      • "<=X": matches versions up to and including X
      • "<X": matches versions less than X
      • ">=X": matches versions from X onwards
      • ">X": matches versions greater than X
      Parameters:
      s - the string to parse
      Returns:
      a VersionSpec object representing the parsed specification
      Throws:
      IllegalArgumentException - if the string cannot be parsed
    • isFixedFeature

      public boolean isFixedFeature()
      Determines if this instance refers to a fixed feature only, i.e., represents a single Java feature version with no interim, update, etc fields set.
      Returns:
      true if this instances refers to a single Java feature version, otherwise false.
    • matches

      public boolean matches(Runtime.Version v)
      Determines if the specified runtime version falls within the range defined by the current VersionSpec instance.
      Parameters:
      v - the Runtime.Version object to check against the version range
      Returns:
      true if the specified version is greater than or equal to the minimum version and less than the maximum version; false otherwise
    • min

      public Runtime.Version min()
      Retrieves the minimum runtime version specified by this VersionSpec.
      Returns:
      the minimum runtime version
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object