diff options
author | Sven Gothel <[email protected]> | 2013-04-16 04:12:47 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-04-16 04:12:47 +0200 |
commit | 588b47fd4c0784cd48bbe19890f4a0074f389cf0 (patch) | |
tree | db80c689e709df87193bf6146c6d31643c17b5f2 /src/java | |
parent | 86f5e7eac7544d2511b70c2142634c89c69d0594 (diff) |
VersionNumber: Add API doc, use final int values, remove protected 'nop' ctor; Add VersionNumberString [extends VersionNumber] which additionally holds the orig. string value.
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/com/jogamp/common/util/VersionNumber.java | 56 | ||||
-rw-r--r-- | src/java/com/jogamp/common/util/VersionNumberString.java | 59 |
2 files changed, 94 insertions, 21 deletions
diff --git a/src/java/com/jogamp/common/util/VersionNumber.java b/src/java/com/jogamp/common/util/VersionNumber.java index 61a4c2e..806c187 100644 --- a/src/java/com/jogamp/common/util/VersionNumber.java +++ b/src/java/com/jogamp/common/util/VersionNumber.java @@ -31,19 +31,27 @@ package com.jogamp.common.util; import java.util.StringTokenizer; import java.util.regex.Matcher; +/** + * Simple version number class containing a version number + * either being {@link #VersionNumber(int, int, int) defined explicit} + * or {@link #VersionNumber(String, String) derived from a string}. + */ public class VersionNumber implements Comparable<Object> { - /** int[3] { major, minor, sub } */ - protected int[] val = new int[] { 0, 0, 0 }; + protected final int major, minor, sub; + /** Explicit version number instantiation. */ public VersionNumber(int majorRev, int minorRev, int subMinorRev) { - val[0] = majorRev; - val[1] = minorRev; - val[2] = subMinorRev; + major = majorRev; + minor = minorRev; + sub = subMinorRev; } /** + * String derived version number instantiation. + * <p> * Parser first tokenizes the input versionString w/ given delimiter. + * </p> * <p> * Tokens represent the major, minor and sub version number component in this order. * </p> @@ -59,6 +67,7 @@ public class VersionNumber implements Comparable<Object> { // group3: .* == any pending chars, optional final java.util.regex.Pattern nonDigitsCutOff = java.util.regex.Pattern.compile("(\\D*)(\\d*)(.*)"); final StringTokenizer tok = new StringTokenizer(versionString, delim); + final int[] val = new int[3]; for(int n=0; tok.hasMoreTokens() && n<3; n++) { try { final Matcher matcher = nonDigitsCutOff.matcher( tok.nextToken() ); @@ -67,16 +76,21 @@ public class VersionNumber implements Comparable<Object> { } } catch (Exception e) { } } + major = val[0]; + minor = val[1]; + sub = val[2]; + } + + public final boolean isZero() { + return major == 0 && minor == 0 && sub == 0; } - protected VersionNumber() { } - @Override public final int hashCode() { // 31 * x == (x << 5) - x - int hash = 31 + val[0]; - hash = ((hash << 5) - hash) + val[1]; - return ((hash << 5) - hash) + val[2]; + int hash = 31 + major; + hash = ((hash << 5) - hash) + minor; + return ((hash << 5) - hash) + sub; } @Override @@ -97,36 +111,36 @@ public class VersionNumber implements Comparable<Object> { } public final int compareTo(VersionNumber vo) { - if (val[0] > vo.val[0]) { // major + if (major > vo.major) { return 1; - } else if (val[0] < vo.val[0]) { // major + } else if (major < vo.major) { return -1; - } else if (val[1] > vo.val[1]) { // minor + } else if (minor > vo.minor) { return 1; - } else if (val[1] < vo.val[1]) { // minor + } else if (minor < vo.minor) { return -1; - } else if (val[2] > vo.val[2]) { // sub + } else if (sub > vo.sub) { return 1; - } else if (val[2] < vo.val[2]) { // sub + } else if (sub < vo.sub) { return -1; } - return 0; // they are equal + return 0; } public final int getMajor() { - return val[0]; + return major; } public final int getMinor() { - return val[1]; + return minor; } public final int getSub() { - return val[2]; + return sub; } @Override public String toString() { - return getMajor() + "." + getMinor() + "." + getSub() ; + return major + "." + minor + "." + sub ; } } diff --git a/src/java/com/jogamp/common/util/VersionNumberString.java b/src/java/com/jogamp/common/util/VersionNumberString.java new file mode 100644 index 0000000..342fa9a --- /dev/null +++ b/src/java/com/jogamp/common/util/VersionNumberString.java @@ -0,0 +1,59 @@ +/** + * Copyright 2013 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.common.util; + +/** + * {@link VersionNumber} specialization, holding the <code>versionString</code> + * this instance is derived from. + */ +public class VersionNumberString extends VersionNumber { + + protected final String strVal; + + public VersionNumberString(int majorRev, int minorRev, int subMinorRev, String versionString) { + super(majorRev, minorRev, subMinorRev); + strVal = versionString; + } + + /** + * See {@link VersionNumber#VersionNumber(String, String)}. + */ + public VersionNumberString(String versionString, String delim) { + super( versionString, delim); + strVal = versionString; + } + + /** Returns the version string this version number is derived from. */ + public final String getVersionString() { return strVal; } + + @Override + public String toString() { + return super.toString() + " ("+strVal+")" ; + } +} |