/** * Checks the supplied version numbers. Throws an * {@link IllegalArgumentException} if they do not define a legal version., * * @param major * the major version number * @param minor * the minor version number * @param bugfix * the bugfix version number * @param qualifier * the qualifier to check * @return the <code>null</code>-masked qualifier * @throws IllegalArgumentException * if the supplied arguments do not identify a legal version * @since JWI 2.2.0 */ public static String checkVersion(int major, int minor, int bugfix, String qualifier){ checkVersionNumber(major, minor, bugfix); return checkQualifier(qualifier); }
/** * 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; }
/** * 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 * @return the cached version object corresponding to these numbers * @since JWI 2.1.0 */ public static Version getVersion(int major, int minor, int bugfix){ return getVersion(major, minor, bugfix, null); }
/** * Returns <code>true</code> if the arguments identify a legal version; * <code>false</code> otherwise. * * @param major * the major version number * @param minor * the minor version number * @param bugfix * the bugfix version number * @param qualifier * the version qualifier * @return <code>true</code> if the arguments identify a legal version; * <code>false</code> otherwise. * @since JWI 2.1.0 */ public static boolean isIllegalVersion(int major, int minor, int bugfix, String qualifier){ if(isIllegalVersionNumber(major, minor, bugfix)) return true; if(isIllegalQualifier(qualifier)) return true; return false; }
/** * Checks the supplied version numbers. Throws an * {@link IllegalArgumentException} if the version numbers are not valid * (that is, any are below zero). * * @param major * the major version number * @param minor * the minor version number * @param bugfix * the bugfix version number * @throws IllegalArgumentException * if any of the supplied numbers are negative * @since JWI 2.1.0 */ public static void checkVersionNumber(int major, int minor, int bugfix){ if(isIllegalVersionNumber(major, minor, bugfix)) throw new IllegalArgumentException("Illegal version number: " + makeVersionString(major, minor, bugfix, null)); }
/** * 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; }
if(isIllegalVersionNumber(major, minor, bugfix)) return null; if(parts.length == 4){ qualifier = parts[3].trim(); if(isIllegalQualifier(qualifier)) return null; return getVersion(major, minor, bugfix, qualifier);
public String toString() { if (toString == null) toString = makeVersionString(major, minor, bugfix, qualifier); return toString; }
@Override public int hashCode() { return hashCode(major, minor, bugfix, qualifier); }
/** * Checks the specified qualifier for legality. Throws an * {@link IllegalArgumentException} if it is not a legal qualifier. * * @param qualifier * the qualifier to check * @return the <code>null</code>-masked qualifier * @see #isIllegalQualifier(String) * @since JWI 2.1.0 */ public static String checkQualifier(String qualifier) { if(qualifier == null) return ""; if(isIllegalQualifier(qualifier)) throw new IllegalArgumentException("Illegal version qualifier: " + qualifier); return qualifier; }
qualifier = checkQualifier(qualifier); boolean hasQualifier = qualifier != null && qualifier.length() > 0; StringBuilder sb = new StringBuilder();
/** * Returns the wordnet version associated with this object, or null if the * version cannot be determined. * * @throws ObjectClosedException * if the object is closed when this method is called * @return the wordnet version associated with this object, or null if the * version cannot be determined * @see edu.mit.jwi.item.IHasVersion#getVersion() */ public IVersion getVersion() { if(!isOpen()) throw new ObjectClosedException(); if(version == null){ version = Version.extractVersion(type, buffer.asReadOnlyBuffer()); if(version == null) version = IVersion.NO_VERSION; } return (version == IVersion.NO_VERSION) ? null : version; }
parts[3].trim(); return getVersion(major, minor, bugfix, 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; }