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