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 public class Version
27 {
28
29 int _version = 0;
30 int _revision = 0;
31 int _subrevision = 0;
32 String _suffix = "";
33
34 public Version()
35 {
36 }
37
38 public Version(String version_string)
39 {
40 parse(version_string);
41 }
42
43
44
45
46
47
48
49 public int compare(Version other)
50 {
51 if (other == null)
52 {
53 throw new NullPointerException("other version is null");
54 }
55 if (this._version < other._version)
56 {
57 return -1;
58 }
59 if (this._version > other._version)
60 {
61 return 1;
62 }
63 if (this._revision < other._revision)
64 {
65 return -1;
66 }
67 if (this._revision > other._revision)
68 {
69 return 1;
70 }
71 if (this._subrevision < other._subrevision)
72 {
73 return -1;
74 }
75 if (this._subrevision > other._subrevision)
76 {
77 return 1;
78 }
79 return 0;
80 }
81
82
83
84
85 public boolean isInRange(Version low, Version high)
86 {
87 return ((compare(low) >= 0) && (compare(high) <= 0));
88 }
89
90
91
92
93 public void parse(String version_string)
94 {
95 _version = 0;
96 _revision = 0;
97 _subrevision = 0;
98 _suffix = "";
99 int pos = 0;
100 int startpos = 0;
101 int endpos = version_string.length();
102 while ((pos < endpos) && Character.isDigit(version_string.charAt(pos)))
103 {
104 pos++;
105 }
106 _version = Integer.parseInt(version_string.substring(startpos,pos));
107 if ((pos < endpos) && (version_string.charAt(pos) == '.'))
108 {
109 startpos = ++pos;
110 while ((pos < endpos) && Character.isDigit(version_string.charAt(pos)))
111 {
112 pos++;
113 }
114 _revision = Integer.parseInt(version_string.substring(startpos,pos));
115 }
116 if ((pos < endpos) && (version_string.charAt(pos) == '.'))
117 {
118 startpos = ++pos;
119 while ((pos < endpos) && Character.isDigit(version_string.charAt(pos)))
120 {
121 pos++;
122 }
123 _subrevision = Integer.parseInt(version_string.substring(startpos,pos));
124 }
125 if (pos < endpos)
126 {
127 _suffix = version_string.substring(pos);
128 }
129 }
130
131
132
133
134 @Override
135 public String toString()
136 {
137 StringBuffer sb = new StringBuffer(10);
138 sb.append(_version);
139 sb.append('.');
140 sb.append(_revision);
141 sb.append('.');
142 sb.append(_subrevision);
143 sb.append(_suffix);
144 return sb.toString();
145 }
146 }