Enum Class JavaVersion

java.lang.Object
java.lang.Enum<JavaVersion>
eu.cloudnetservice.driver.base.JavaVersion
All Implemented Interfaces:
Serializable, Comparable<JavaVersion>, Constable

public enum JavaVersion extends Enum<JavaVersion>
An enumeration of all java versions starting from 8. This list is updated each time an early access build for a new java version gets released.
Since:
4.0
  • Enum Constant Details

    • JAVA_UNSUPPORTED

      public static final JavaVersion JAVA_UNSUPPORTED
      Represents all java version before 8.
    • JAVA_NEXT

      public static final JavaVersion JAVA_NEXT
      Represents all java versions after the latest known release in this list.
    • JAVA_8

      public static final JavaVersion JAVA_8
      Java version 8 (LTS).
    • JAVA_9

      public static final JavaVersion JAVA_9
      Java version 9.
    • JAVA_10

      public static final JavaVersion JAVA_10
      Java version 10.
    • JAVA_11

      public static final JavaVersion JAVA_11
      Java version 11 (LTS).
    • JAVA_12

      public static final JavaVersion JAVA_12
      Java version 12.
    • JAVA_13

      public static final JavaVersion JAVA_13
      Java version 13.
    • JAVA_14

      public static final JavaVersion JAVA_14
      Java version 14.
    • JAVA_15

      public static final JavaVersion JAVA_15
      Java version 15.
    • JAVA_16

      public static final JavaVersion JAVA_16
      Java version 16.
    • JAVA_17

      public static final JavaVersion JAVA_17
      Java version 17 (LTS).
    • JAVA_18

      public static final JavaVersion JAVA_18
      Java version 18.
    • JAVA_19

      public static final JavaVersion JAVA_19
      Java version 19.
    • JAVA_20

      public static final JavaVersion JAVA_20
      Java version 20.
    • JAVA_21

      public static final JavaVersion JAVA_21
      Java version 21 (LTS).
    • JAVA_22

      public static final JavaVersion JAVA_22
      Java version 22.
    • JAVA_23

      public static final JavaVersion JAVA_23
      Java version 23.
    • JAVA_24

      public static final JavaVersion JAVA_24
      Java version 24.
    • JAVA_25

      public static final JavaVersion JAVA_25
      Java version 25.
  • Field Details

    • JAVA_VERSIONS

      private static final JavaVersion[] JAVA_VERSIONS
    • LATEST_VERSION

      private static final JavaVersion LATEST_VERSION
    • RUNTIME_VERSION

      private static final JavaVersion RUNTIME_VERSION
    • majorVersion

      private final int majorVersion
    • classFileVersion

      private final double classFileVersion
    • displayName

      private final String displayName
  • Constructor Details

    • JavaVersion

      private JavaVersion(int majorVersion, double classFileVersion, @NonNull @NonNull String displayName)
      Constructs a new java version constant.
      Parameters:
      majorVersion - the major version number of the release.
      classFileVersion - the class file version used by the release.
      displayName - the display name of the release.
      Throws:
      NullPointerException - if the given display name is null.
  • Method Details

    • values

      public static JavaVersion[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static JavaVersion valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • resolveActualJavaVersions

      @NonNull private static @NonNull JavaVersion[] resolveActualJavaVersions()
      Constructs an array of the java versions that are actually usable in the runtime (this excludes the unsupported and next constants).
      Returns:
      an array of the java versions that are actually executable.
    • resolveRuntimeVersion

      @NonNull private static @NonNull JavaVersion resolveRuntimeVersion()
      Resolves the runtime version of the current jvm. This method returns JAVA_NEXT if the current jvm version is newer than the latest registered version in this enum. On the other hand, this method returns JAVA_UNSUPPORTED if the runtime version is older than 8.
      Returns:
      the java version enum constant representing the current jvm version.
    • runtimeVersion

      @NonNull public static @NonNull JavaVersion runtimeVersion()
      Get the java version enum constant representing the current runtime version.
      Returns:
      the java version enum constant representing the current runtime version.
    • fromClassFileVersion

      @NonNull public static @NonNull Optional<JavaVersion> fromClassFileVersion(double classFileVersion)
      Finds the java version enum constant that is representing the given class file version. This method returns an empty optional if no known java version represents that version.
      Parameters:
      classFileVersion - the class file version to find the java version constant of.
      Returns:
      an optional containing the java version that is associated with the given class file version, if any.
    • guessFromMajor

      @NonNull public static @NonNull JavaVersion guessFromMajor(int major)
      Guesses the java version from the given major version, returning either JAVA_NEXT or JAVA_UNSUPPORTED in case no known version uses the given major version.
      Parameters:
      major - the major version number of the java version to get.
      Returns:
      the exact matching java version from the major version, or either next or unsupported.
    • fromMajor

      @NonNull public static @NonNull Optional<JavaVersion> fromMajor(int version)
      Finds the exact known java version from the given major version. This method returns an empty optional in case no known java version with the given major version number matches.
      Parameters:
      version - the major version number of the java version to find.
      Returns:
      an optional containing the java version associated with the given major version, if any.
    • majorVersion

      public int majorVersion()
      Returns the major version number of this java version.
      Returns:
      the major version number of this java version.
    • classFileVersion

      public double classFileVersion()
      Get the class file version number of this java version.
      Returns:
      the class file version number of this java version.
    • displayName

      @NonNull public @NonNull String displayName()
      Get the display name of this java version.
      Returns:
      the display name of this java version.
    • supported

      public boolean supported()
      Checks if this java version constant is actually supported. In other words, this method checks if this java version is not JAVA_UNSUPPORTED.
      Returns:
      true if this java version constant is actually supported, false otherwise.
    • atOrAbove

      public boolean atOrAbove()
      Checks if the version of the current java runtime is at least this java version.
      Returns:
      true if the runtime version is at least this java version, false otherwise.
    • isInRange

      public boolean isInRange(@NonNull @NonNull JavaVersion lowerBound, @NonNull @NonNull JavaVersion upperBound)
      Checks if this java version is newer or at the given lower bound and older or at the given upper bound. There is no sanity check made if the lower bound is smaller than the upper bound.
      Parameters:
      lowerBound - the lower bound of the version range to check.
      upperBound - the upper bound of the version range to check.
      Returns:
      true if this version is within the lower and upper java version bound, false otherwise.
      Throws:
      NullPointerException - if the given lower or upper bound is null.
    • isNewerOrAt

      public boolean isNewerOrAt(@NonNull @NonNull JavaVersion version)
      Checks if this java version is newer or at the given other version.
      Parameters:
      version - the version to check against.
      Returns:
      true if this version is newer or at the given version, false otherwise.
      Throws:
      NullPointerException - if the given version is null.
    • isOlderOrAt

      public boolean isOlderOrAt(@NonNull @NonNull JavaVersion version)
      Checks if this java version is older or at the given other version.
      Parameters:
      version - the version to check against.
      Returns:
      true if this version is older or at the given version, false otherwise.
      Throws:
      NullPointerException - if the given version is null.