2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
* Copyright (C) 2005 University of Waikato, Hamilton, New Zealand
25
import java.io.InputStream;
26
import java.io.InputStreamReader;
27
import java.io.LineNumberReader;
30
* This class contains the version number of the current WEKA release and some
31
* methods for comparing another version string. The normal layout of a
32
* version string is "MAJOR.MINOR.REVISION", but it can also handle partial
33
* version strings, e.g. "3.4". <br/>
34
* Should be used e.g. in exports to XML for keeping track, with which version
35
* of WEKA the file was produced.
37
* @author FracPete (fracpete at waikato dot ac dot nz)
38
* @version $Revision: 1.6 $
41
implements Comparable {
43
/** the version file */
44
public final static String VERSION_FILE = "weka/core/version.txt";
46
/** the major version */
47
public static int MAJOR = 3;
49
/** the minor version */
50
public static int MINOR = 4;
53
public static int REVISION = 3;
57
InputStream inR = ClassLoader.getSystemResourceAsStream(VERSION_FILE);
58
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(inR));
60
String line = lnr.readLine();
61
int[] maj = new int[1];
62
int[] min = new int[1];
63
int[] rev = new int[1];
64
parseVersion(line, maj, min, rev);
72
Version.class.getName() + ": Unable to load version information!");
76
/** the complete version */
77
public static String VERSION = MAJOR + "." + MINOR + "." + REVISION;
80
* parses the version and stores the result in the arrays
82
* @param version the version string to parse (contains "-" instead of "."!)
83
* @param maj the major version
84
* @param min the minor version
85
* @param rev the revision version
87
private static void parseVersion(String version, int[] maj, int[] min, int[] rev) {
93
String tmpStr = version;
94
tmpStr = tmpStr.replace('-', '.');
95
if (tmpStr.indexOf(".") > -1) {
96
major = Integer.parseInt(tmpStr.substring(0, tmpStr.indexOf(".")));
97
tmpStr = tmpStr.substring(tmpStr.indexOf(".") + 1);
98
if (tmpStr.indexOf(".") > -1) {
99
minor = Integer.parseInt(tmpStr.substring(0, tmpStr.indexOf(".")));
100
tmpStr = tmpStr.substring(tmpStr.indexOf(".") + 1);
101
if (!tmpStr.equals(""))
102
revision = Integer.parseInt(tmpStr);
107
if (!tmpStr.equals(""))
108
minor = Integer.parseInt(tmpStr);
114
if (!tmpStr.equals(""))
115
major = Integer.parseInt(tmpStr);
119
} catch (Exception e) {
132
* checks the version of this class against the given version-string
134
* @param o the version-string to compare with
135
* @return -1 if this version is less, 0 if equal and +1 if greater
136
* than the provided version
138
public int compareTo(Object o) {
143
int [] maj = new int [1];
144
int [] min = new int [1];
145
int [] rev = new int [1];
148
// do we have a string?
149
if (o instanceof String) {
150
parseVersion((String)o, maj, min, rev);
156
System.out.println(this.getClass().getName() + ": no version-string for comparTo povided!");
165
else if (MAJOR == major) {
169
else if (MINOR == minor) {
170
if (REVISION < revision) {
173
else if (REVISION == revision) {
192
* whether the given version string is equal to this version
194
* @param o the version-string to compare to
195
* @return TRUE if the version-string is equals to its own
197
public boolean equals(Object o) {
198
return (compareTo(o) == 0);
202
* checks whether this version is older than the one from the given
205
* @param o the version-string to compare with
206
* @return TRUE if this version is older than the given one
208
public boolean isOlder(Object o) {
209
return (compareTo(o) == -1);
213
* checks whether this version is newer than the one from the given
216
* @param o the version-string to compare with
217
* @return TRUE if this version is newer than the given one
219
public boolean isNewer(Object o) {
220
return (compareTo(o) == 1);
224
* returns the current version as string
226
* @return the current version
228
public String toString() {
235
* @param args the commandline arguments - ignored
237
public static void main(String[] args) {
242
System.out.println(VERSION + "\n");
244
// test on different versions
246
System.out.println("-1? " + v.compareTo("5.0.1"));
247
System.out.println(" 0? " + v.compareTo(VERSION));
248
System.out.println("+1? " + v.compareTo("3.4.0"));
251
System.out.println("\ncomparing with " + tmpStr);
252
System.out.println("isOlder? " + v.isOlder(tmpStr));
253
System.out.println("equals ? " + v.equals(tmpStr));
254
System.out.println("isNewer? " + v.isNewer(tmpStr));
257
System.out.println("\ncomparing with " + tmpStr);
258
System.out.println("isOlder? " + v.isOlder(tmpStr));
259
System.out.println("equals ? " + v.equals(tmpStr));
260
System.out.println("isNewer? " + v.isNewer(tmpStr));
263
System.out.println("\ncomparing with " + tmpStr);
264
System.out.println("isOlder? " + v.isOlder(tmpStr));
265
System.out.println("equals ? " + v.equals(tmpStr));
266
System.out.println("isNewer? " + v.isNewer(tmpStr));
269
System.out.println("\ncomparing with " + tmpStr);
270
System.out.println("isOlder? " + v.isOlder(tmpStr));
271
System.out.println("equals ? " + v.equals(tmpStr));
272
System.out.println("isNewer? " + v.isNewer(tmpStr));
275
System.out.println("\ncomparing with " + tmpStr);
276
System.out.println("isOlder? " + v.isOlder(tmpStr));
277
System.out.println("equals ? " + v.equals(tmpStr));
278
System.out.println("isNewer? " + v.isNewer(tmpStr));