1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.mortbay.start;
15
16
17
18
19
20
21
22 public class Version {
23
24 int _version = 0;
25 int _revision = 0;
26 int _subrevision = 0;
27 String _suffix = "";
28
29 public Version() {
30 }
31
32 public Version(String version_string) {
33 parse(version_string);
34 }
35
36
37
38
39
40 public void parse(String version_string) {
41 _version = 0;
42 _revision = 0;
43 _subrevision = 0;
44 _suffix = "";
45 int pos = 0;
46 int startpos = 0;
47 int endpos = version_string.length();
48 while ( (pos < endpos) && Character.isDigit(version_string.charAt(pos))) {
49 pos++;
50 }
51 _version = Integer.parseInt(version_string.substring(startpos,pos));
52 if ((pos < endpos) && version_string.charAt(pos)=='.') {
53 startpos = ++pos;
54 while ( (pos < endpos) && Character.isDigit(version_string.charAt(pos))) {
55 pos++;
56 }
57 _revision = Integer.parseInt(version_string.substring(startpos,pos));
58 }
59 if ((pos < endpos) && version_string.charAt(pos)=='.') {
60 startpos = ++pos;
61 while ( (pos < endpos) && Character.isDigit(version_string.charAt(pos))) {
62 pos++;
63 }
64 _subrevision = Integer.parseInt(version_string.substring(startpos,pos));
65 }
66 if (pos < endpos) {
67 _suffix = version_string.substring(pos);
68 }
69 }
70
71
72
73
74 public String toString() {
75 StringBuffer sb = new StringBuffer(10);
76 sb.append(_version);
77 sb.append('.');
78 sb.append(_revision);
79 sb.append('.');
80 sb.append(_subrevision);
81 sb.append(_suffix);
82 return sb.toString();
83 }
84
85
86
87
88
89
90
91
92
93 public int compare(Version other) {
94 if (other == null) throw new NullPointerException("other version is null");
95 if (this._version < other._version) return -1;
96 if (this._version > other._version) return 1;
97 if (this._revision < other._revision) return -1;
98 if (this._revision > other._revision) return 1;
99 if (this._subrevision < other._subrevision) return -1;
100 if (this._subrevision > other._subrevision) return 1;
101 return 0;
102 }
103
104
105
106
107 public boolean isInRange(Version low, Version high) {
108 return (compare(low)>=0 && compare(high)<=0);
109 }
110 }