/** * Creates a new version object with the specified version numbers. * <p> * Clients should normally obtain instances of this class via the static * {@code getVersion} methods. * * @param major * the major version number, i.e., the '1' in 1.2.3.q * @param minor * the minor version number, i.e., the '2' in 1.2.3.q * @param bugfix * the bugfix version number, i.e., the '3' in 1.2.3.q * @param qualifier * the version qualifier, i.e., the 'q' in 1.2.3.q * @throws IllegalArgumentException * if any of the version numbers are negative, or the qualifier * is not a legal qualifier * @since JWI 2.2.0 */ public Version(int major, int minor, int bugfix, String qualifier){ qualifier = checkVersion(major, minor, bugfix, qualifier); // field assignments this.major = major; this.minor = minor; this.bugfix = bugfix; this.qualifier = qualifier; }
/** * Calculates the hash code for a version object with the specified version * numbers. * * @param major * the major version number, i.e., the '1' in 1.2.3.q * @param minor * the minor version number, i.e., the '2' in 1.2.3.q * @param bugfix * the bugfix version number, i.e., the '3' in 1.2.3.q * @param qualifier * the version qualifier, i.e., the 'q' in 1.2.3.q * @throws IllegalArgumentException * if the specified parameters do not identify a legal version * @return the hash code for the specified version */ public static int hashCode(int major, int minor, int bugfix, String qualifier){ qualifier = checkVersion(major, minor, bugfix, qualifier); final int prime = 31; int result = 1; result = prime * result + major; result = prime * result + minor; result = prime * result + bugfix; result = prime * result + qualifier.hashCode(); return result; }
/** * Creates and caches, or retrieves from the cache, a version object * corresponding to the specified numbers. * * @param major * the major version number * @param minor * the minor version number * @param bugfix * the bugfix version number * @param qualifier * the version qualifier * @return the cached version object corresponding to these numbers * @throws IllegalArgumentException * if the version numbers and qualifier are not legal * @since JWI 2.2.0 */ public static Version getVersion(int major, int minor, int bugfix, String qualifier){ qualifier = checkVersion(major, minor, bugfix, qualifier); int hash = hashCode(major, minor, bugfix, qualifier); Version version = versionCache.get(hash); if(version == null){ version = new Version(major, minor, bugfix, qualifier); versionCache.put(version.hashCode(), version); } return version; }