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