1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2004 Regents of the University of California and the
|
4
|
* National Center for Ecological Analysis and Synthesis
|
5
|
*
|
6
|
* '$Author: daigle $'
|
7
|
* '$Date: 2008-07-06 21:25:34 -0700 (Sun, 06 Jul 2008) $'
|
8
|
* '$Revision: 4080 $'
|
9
|
*
|
10
|
* This program is free software; you can redistribute it and/or modify
|
11
|
* it under the terms of the GNU General Public License as published by
|
12
|
* the Free Software Foundation; either version 2 of the License, or
|
13
|
* (at your option) any later version.
|
14
|
*
|
15
|
* This program is distributed in the hope that it will be useful,
|
16
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
* GNU General Public License for more details.
|
19
|
*
|
20
|
* You should have received a copy of the GNU General Public License
|
21
|
* along with this program; if not, write to the Free Software
|
22
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23
|
*/
|
24
|
package edu.ucsb.nceas.metacat;
|
25
|
|
26
|
import java.util.Vector;
|
27
|
|
28
|
import edu.ucsb.nceas.utilities.StringUtil;
|
29
|
|
30
|
|
31
|
/**
|
32
|
* @author jones
|
33
|
*
|
34
|
* Version represents the current version information for this Metacat instance.
|
35
|
*/
|
36
|
public class Version implements Comparable<Version>
|
37
|
{
|
38
|
protected static int allowedVersionLevels = 4;
|
39
|
protected int[] subversions = {0, 0, 0, 0};
|
40
|
protected String versionString = null;
|
41
|
|
42
|
/**
|
43
|
* Create a Version object, setting sub version levels based on the given
|
44
|
* version id.
|
45
|
*
|
46
|
* @param versionID
|
47
|
*/
|
48
|
public Version(String versionID) {
|
49
|
setSubversions(versionID);
|
50
|
versionString = versionID;
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* Compare this Version object to another. Use the sub version levels to do
|
55
|
* the comparison. In that way, we can make sure that something like version
|
56
|
* 1.0.0.1 is less than 2.0.1.
|
57
|
*
|
58
|
* @param anotherVersion
|
59
|
* @return -1 if this version is less than given version, 0 if they are
|
60
|
* equal and 1 if this version is greater than given version.
|
61
|
*/
|
62
|
public int compareTo(Version anotherVersion) {
|
63
|
for (int i = 0; i < allowedVersionLevels; i++) {
|
64
|
if (this.getSubversion(i) < ((Version)anotherVersion).getSubversion(i)) {
|
65
|
return -1;
|
66
|
} else if (this.getSubversion(i) > ((Version)anotherVersion).getSubversion(i)) {
|
67
|
return 1;
|
68
|
}
|
69
|
}
|
70
|
return 0;
|
71
|
}
|
72
|
|
73
|
public int getSubversion(int level) {
|
74
|
return subversions[level];
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* Set each level (up to 4) of sub version based on the given version id.
|
79
|
*
|
80
|
* @param versionID
|
81
|
* a string representing a dotted version notation
|
82
|
*/
|
83
|
private void setSubversions(String versionID) throws NumberFormatException {
|
84
|
Vector<String> subversionStrings = StringUtil.toVector(versionID, '.');
|
85
|
for (int i = 0; i < subversionStrings.size() && i < allowedVersionLevels; i++) {
|
86
|
int subversion = Integer.parseInt(subversionStrings.elementAt(i));
|
87
|
this.subversions[i] = subversion;
|
88
|
}
|
89
|
}
|
90
|
|
91
|
public String getVersionString() {
|
92
|
return versionString;
|
93
|
}
|
94
|
}
|