All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.day.util.JavaVersion Maven / Gradle / Ivy

There is a newer version: 2024.11.18598.20241113T125352Z-241000
Show newest version
/*************************************************************************
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2020 Adobe
 *  All Rights Reserved.
 *
 * NOTICE: All information contained herein is, and remains
 * the property of Adobe and its suppliers, if any. The intellectual
 * and technical concepts contained herein are proprietary to Adobe
 * and its suppliers and are protected by all applicable intellectual
 * property laws, including trade secret and copyright laws.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe.
 **************************************************************************/
package com.day.util;

/**
 * The JavaVersion class is a helper class to handle various
 * Java version strings and query about the version of the Java VM the
 * application is running.
 * 

* The version information provided is based on the Java Runtime of the currently * running Virtual Machine. *

* This is a utility class, which cannot be instantiated. * * @author fmeschbe * @version $Revision: 1.4 $, $Date: 2004-11-19 17:34:44 +0100 (Fri, 19 Nov 2004) $ * Audience wad * @since hawk */ public class JavaVersion { /** * This object is used to check for specification version compliance. The * nice thing about the Package class is, that it contains a method to * correctly check version names like 1.3.1, etc. */ private static final Package specPackage; static { // Get the package from the class loader(s) // See bug 10745 for details. specPackage = new ClassLoader() { Package createPackage() { return definePackage("dummy.package", System.getProperty("java.specification.name"), System.getProperty("java.specification.version"), System.getProperty("java.specification.vendor"), "Java Runtime Environment", System.getProperty("java.version"), System.getProperty("java.vendor"), null); } }.createPackage(); } /** The specification version String for Java 1.3 */ private static final String specVersion13 = "1.3"; /** The specification version String for Java 1.4 */ private static final String specVersion14 = "1.4"; /** The specification version String for Java 1.5 */ private static final String specVersion15 = "1.5"; /** Private constructor prevents instantion */ private JavaVersion() {} /** * Returns the implementation version of the current Java Runtime library. * E.g. "1.4.2_04" * @return the version */ public static String getVersion() { return specPackage.getImplementationVersion(); } /** * Returns the specification version of the current Java Runtime library. * E.g. "1.4" * @return the version */ public static String getSpecificationVersion() { return specPackage.getSpecificationVersion(); } /** * Returns true if the specification version of the current * Java Runtime library is 1.3. This is a convenience method * completely equivalent to * {@link #isSpecificationVersion(java.lang.String) isSpecificationVersion("1.3")}. * @return if it is the version */ public static boolean is13() { return isSpecificationVersion(specVersion13); } /** * Returns true if the specification version of the current * Java Runtime library is 1.4. This is a convenience method * completely equivalent to * {@link #isSpecificationVersion(java.lang.String) isSpecificationVersion("1.4")}. * @return if it is the version */ public static boolean is14() { return isSpecificationVersion(specVersion14); } /** * Returns true if the specification version of the current * Java Runtime library is 1.5. This is a convenience method * completely equivalent to * {@link #isSpecificationVersion(java.lang.String) isSpecificationVersion("1.5")}. * @return if it is the version */ public static boolean is15() { return isSpecificationVersion(specVersion15); } /** * Returns true if the specification version of the current * Java Runtime library the given version string. * * @param specVersion The specification version to compare to the * specification of the current Hava Runtime library. * @return if it is the version */ public static boolean isSpecificationVersion(String specVersion) { if (specVersion == null || specVersion.length() == 0) { return false; } else { return specVersion.equals(getSpecificationVersion()); } } /** * Returns true if the specification version of the current * Java Runtime library is compatible with 1.3, that is if the * specification version of the current Java Runtime library is the same or * newer than 1.3. This is a convenience method completely * equivalent to * {@link #isCompatibleWith(java.lang.String) isCompatibleWith("1.3")}. * @return if it is compatible */ public static boolean isCompatibleWith13() { return isCompatibleWith(specVersion13); } /** * Returns true if the specification version of the current * Java Runtime library is compatible with 1.4, that is if the * specification version of the current Java Runtime library is the same or * newer than 1.4. This is a convenience method completely * equivalent to * {@link #isCompatibleWith(java.lang.String) isCompatibleWith("1.4")}. * @return if it is compatible */ public static boolean isCompatibleWith14() { return isCompatibleWith(specVersion14); } /** * Returns true if the specification version of the current * Java Runtime library is compatible with 1.5, that is if the * specification version of the current Java Runtime library is the same or * newer than 1.5. This is a convenience method completely * equivalent to * {@link #isCompatibleWith(java.lang.String) isCompatibleWith("1.5")}. * @return if it is compatible */ public static boolean isCompatibleWith15() { return isCompatibleWith(specVersion15); } /** * Returns true if the specification version of the current * Java Runtime library is compatible with the given specification version, * that is if the specification version of the current Java Runtime library * is the same or newer than the given version. * * @param specVersion The specification version to compare to the * specification of the current Hava Runtime library. * @return if it is compatible */ public static boolean isCompatibleWith(String specVersion) { return specPackage.isCompatibleWith(specVersion); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy