Revision 37599 branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/main/java/org/gvsig/installer/lib/impl/DefaultVersion.java
DefaultVersion.java | ||
---|---|---|
17 | 17 |
super(); |
18 | 18 |
} |
19 | 19 |
|
20 |
protected DefaultVersion(int mayor, int minor, int rev,String classifier, int build) { |
|
20 |
protected DefaultVersion(int mayor, int minor, int rev, String classifier, |
|
21 |
int build) { |
|
21 | 22 |
this(); |
22 | 23 |
this.mayor = mayor; |
23 | 24 |
this.minor = minor; |
... | ... | |
25 | 26 |
this.classifier = classifier; |
26 | 27 |
this.build = build; |
27 | 28 |
} |
28 |
|
|
29 |
|
|
29 | 30 |
public Version parse(String version) { |
30 | 31 |
// Formato: mayor.minor.rev-classifier-build |
31 |
|
|
32 |
|
|
32 | 33 |
String[] x = version.split("[.]"); |
33 | 34 |
int lx = x.length; |
34 |
if( lx==1 ) {
|
|
35 |
this.mayor = parseIntClassifierAndBuild(x[0],version); |
|
35 |
if (lx == 1) {
|
|
36 |
this.mayor = parseIntClassifierAndBuild(x[0], version);
|
|
36 | 37 |
this.minor = 0; |
37 | 38 |
this.rev = 0; |
38 | 39 |
this.classifier = null; |
39 | 40 |
this.build = 0; |
40 |
} else if( lx==2 ) {
|
|
41 |
} else if (lx == 2) {
|
|
41 | 42 |
this.mayor = Integer.parseInt(x[0]); |
42 |
this.minor = parseIntClassifierAndBuild(x[1],version); |
|
43 |
this.minor = parseIntClassifierAndBuild(x[1], version);
|
|
43 | 44 |
this.rev = 0; |
44 | 45 |
this.classifier = null; |
45 | 46 |
this.build = 0; |
46 |
} else if( lx==3 ) {
|
|
47 |
} else if (lx == 3) {
|
|
47 | 48 |
this.mayor = Integer.parseInt(x[0]); |
48 | 49 |
this.minor = Integer.parseInt(x[1]); |
49 |
this.rev = parseIntClassifierAndBuild(x[2],version); |
|
50 |
this.rev = parseIntClassifierAndBuild(x[2], version);
|
|
50 | 51 |
} else { |
51 | 52 |
throw new InvalidParameterException(version); |
52 | 53 |
} |
... | ... | |
55 | 56 |
|
56 | 57 |
private int parseIntClassifierAndBuild(String s, String fullversion) { |
57 | 58 |
int value; |
58 |
|
|
59 |
|
|
59 | 60 |
String[] y = s.split("[-]"); |
60 | 61 |
int ly = y.length; |
61 |
if( ly == 1 ) {
|
|
62 |
if (ly == 1) {
|
|
62 | 63 |
value = Integer.parseInt(y[0]); |
63 | 64 |
this.classifier = null; |
64 | 65 |
this.build = 0; |
65 |
} else if( ly == 2 ) {
|
|
66 |
} else if (ly == 2) {
|
|
66 | 67 |
value = Integer.parseInt(y[0]); |
67 | 68 |
try { |
68 | 69 |
this.build = Integer.parseInt(y[1]); |
69 | 70 |
this.classifier = null; |
70 |
} catch( NumberFormatException e) {
|
|
71 |
} catch (NumberFormatException e) {
|
|
71 | 72 |
this.build = 0; |
72 | 73 |
this.classifier = y[1]; |
73 | 74 |
} |
74 |
} else if( ly == 3 ) {
|
|
75 |
} else if (ly == 3) {
|
|
75 | 76 |
value = Integer.parseInt(y[0]); |
76 | 77 |
this.classifier = y[1]; |
77 | 78 |
this.build = Integer.parseInt(y[2]); |
... | ... | |
80 | 81 |
} |
81 | 82 |
return value; |
82 | 83 |
} |
83 |
|
|
84 |
|
|
84 |
|
|
85 | 85 |
public int getMayor() { |
86 | 86 |
return this.mayor; |
87 | 87 |
} |
... | ... | |
103 | 103 |
} |
104 | 104 |
|
105 | 105 |
public boolean check(String op, Version other) { |
106 |
if( "=".equals(op) || "==".equals(op) || "-eq".equals(op) ) {
|
|
107 |
return this.fullFormat().compareTo(other.fullFormat()) == 0;
|
|
106 |
if ("=".equals(op) || "==".equals(op) || "-eq".equals(op)) {
|
|
107 |
return this.fullFormat().compareTo(other.fullFormat()) == 0; |
|
108 | 108 |
} |
109 |
if( ">".equals(op) || "-gt".equals(op) ) {
|
|
110 |
return this.fullFormat().compareTo(other.fullFormat()) > 0;
|
|
109 |
if (">".equals(op) || "-gt".equals(op)) {
|
|
110 |
return this.fullFormat().compareTo(other.fullFormat()) > 0; |
|
111 | 111 |
} |
112 |
if( ">=".equals(op) || "-ge".equals(op) ) {
|
|
113 |
return this.fullFormat().compareTo(other.fullFormat()) >= 0;
|
|
112 |
if (">=".equals(op) || "-ge".equals(op)) {
|
|
113 |
return this.fullFormat().compareTo(other.fullFormat()) >= 0; |
|
114 | 114 |
} |
115 |
if( "<".equals(op) || "-lt".equals(op) ) {
|
|
116 |
return this.fullFormat().compareTo(other.fullFormat()) < 0;
|
|
115 |
if ("<".equals(op) || "-lt".equals(op)) {
|
|
116 |
return this.fullFormat().compareTo(other.fullFormat()) < 0; |
|
117 | 117 |
} |
118 |
if( "<=".equals(op) || "-le".equals(op) ) {
|
|
119 |
return this.fullFormat().compareTo(other.fullFormat()) <= 0;
|
|
118 |
if ("<=".equals(op) || "-le".equals(op)) {
|
|
119 |
return this.fullFormat().compareTo(other.fullFormat()) <= 0; |
|
120 | 120 |
} |
121 | 121 |
return false; |
122 | 122 |
} |
123 | 123 |
|
124 |
@Override |
|
124 | 125 |
public String toString() { |
125 |
if( this.classifier==null ) {
|
|
126 |
if (this.classifier == null) {
|
|
126 | 127 |
return MessageFormat.format("{0}.{1}.{2}-{3,number,####}", |
127 |
this.mayor, |
|
128 |
this.minor, |
|
129 |
this.rev, |
|
130 |
this.build |
|
131 |
); |
|
128 |
this.mayor, this.minor, this.rev, this.build); |
|
132 | 129 |
} else { |
133 | 130 |
return MessageFormat.format("{0}.{1}.{2}-{3}-{4,number,####}", |
134 |
this.mayor, |
|
135 |
this.minor, |
|
136 |
this.rev, |
|
137 |
this.classifier, |
|
138 |
this.build |
|
139 |
); |
|
131 |
this.mayor, this.minor, this.rev, this.classifier, |
|
132 |
this.build); |
|
140 | 133 |
} |
141 | 134 |
} |
142 |
|
|
135 |
|
|
143 | 136 |
public String fullFormat() { |
144 |
if( this.classifier==null ) {
|
|
137 |
if (this.classifier == null) {
|
|
145 | 138 |
// classifier AAAA allows compare correctly tow versions |
146 |
return MessageFormat.format("{0,number,0000}.{1,number,0000}.{2,number,0000}-AAAA-{3,number,0000}", |
|
147 |
this.mayor, |
|
148 |
this.minor, |
|
149 |
this.rev, |
|
150 |
this.build |
|
151 |
); |
|
139 |
return MessageFormat |
|
140 |
.format( |
|
141 |
"{0,number,0000}.{1,number,0000}.{2,number,0000}-AAAA-{3,number,0000}", |
|
142 |
this.mayor, this.minor, this.rev, this.build); |
|
152 | 143 |
} else { |
153 |
return MessageFormat.format("{0,number,0000}.{1,number,0000}.{2,number,0000}-{3}-{4,number,0000}", |
|
154 |
this.mayor, |
|
155 |
this.minor, |
|
156 |
this.rev, |
|
157 |
this.classifier, |
|
158 |
this.build |
|
159 |
); |
|
144 |
return MessageFormat |
|
145 |
.format( |
|
146 |
"{0,number,0000}.{1,number,0000}.{2,number,0000}-{3}-{4,number,0000}", |
|
147 |
this.mayor, this.minor, this.rev, this.classifier, |
|
148 |
this.build); |
|
160 | 149 |
} |
161 | 150 |
} |
162 |
|
|
151 |
|
|
152 |
@Override |
|
163 | 153 |
public Object clone() throws CloneNotSupportedException { |
164 | 154 |
return super.clone(); |
165 | 155 |
} |
166 |
|
|
156 |
|
|
157 |
@Override |
|
167 | 158 |
public boolean equals(Object obj) { |
168 |
Version other = (Version)obj; |
|
169 |
if( this.mayor != other.getMayor() ) {
|
|
159 |
Version other = (Version) obj;
|
|
160 |
if (this.mayor != other.getMayor()) {
|
|
170 | 161 |
return false; |
171 | 162 |
} |
172 |
if( this.minor != other.getMinor() ) {
|
|
163 |
if (this.minor != other.getMinor()) {
|
|
173 | 164 |
return false; |
174 | 165 |
} |
175 |
if( this.rev != other.getRevision() ) {
|
|
166 |
if (this.rev != other.getRevision()) {
|
|
176 | 167 |
return false; |
177 | 168 |
} |
178 |
if( this.build != other.getBuild() ) {
|
|
169 |
if (this.build != other.getBuild()) {
|
|
179 | 170 |
return false; |
180 | 171 |
} |
181 |
if( this.classifier==null ) {
|
|
182 |
if( other.getClassifier()==null ) {
|
|
172 |
if (this.classifier == null) {
|
|
173 |
if (other.getClassifier() == null) {
|
|
183 | 174 |
return true; |
184 | 175 |
} else { |
185 | 176 |
return false; |
186 | 177 |
} |
187 | 178 |
} |
188 |
if( !this.classifier.equalsIgnoreCase(other.getClassifier()) ) {
|
|
179 |
if (!this.classifier.equalsIgnoreCase(other.getClassifier())) {
|
|
189 | 180 |
return false; |
190 | 181 |
} |
191 | 182 |
return true; |
Also available in: Unified diff