531be627ec29884701a01d302a77475fbc17d83e.svn-base
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.espeed.ua;
public class Version implements Comparable<Version> {
String version;
String majorVersion;
String minorVersion;
/**
* This constructor is created for APIs that require default constructor
* and should never be used directly.
* @deprecated Use {@link #Version(String, String, String)}
*/
@Deprecated
public Version() {
// default constructor for APIs that require it (e.g. JSON serialization)
}
public Version(String version, String majorVersion, String minorVersion) {
super();
this.version = version;
this.majorVersion = majorVersion;
this.minorVersion = minorVersion;
}
public String getVersion() {
return version;
}
public String getMajorVersion() {
return majorVersion;
}
public String getMinorVersion() {
return minorVersion;
}
@Override
public String toString() {
return version;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((majorVersion == null) ? 0 : majorVersion.hashCode());
result = prime * result
+ ((minorVersion == null) ? 0 : minorVersion.hashCode());
result = prime * result + ((version == null) ? 0 : version.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Version other = (Version) obj;
if (majorVersion == null) {
if (other.majorVersion != null)
return false;
} else if (!majorVersion.equals(other.majorVersion))
return false;
if (minorVersion == null) {
if (other.minorVersion != null)
return false;
} else if (!minorVersion.equals(other.minorVersion))
return false;
if (version == null) {
if (other.version != null)
return false;
} else if (!version.equals(other.version))
return false;
return true;
}
public int compareTo(Version other) {
if (other == null) {
return 1;
}
String[] versionParts = version.split("\\.");
String[] otherVersionParts = other.version.split("\\.");
for (int i = 0; i < Math.min(versionParts.length, otherVersionParts.length); i++) {
if (versionParts[i].length() == otherVersionParts[i].length()) {
int comparisonResult = versionParts[i].compareTo(otherVersionParts[i]);
if (comparisonResult == 0) {
continue;
} else {
return comparisonResult;
}
} else {
return versionParts[i].length() > otherVersionParts[i].length() ? 1 : -1;
}
}
if (versionParts.length > otherVersionParts.length) {
return 1;
} else if (versionParts.length < otherVersionParts.length) {
return -1;
} else {
return 0;
}
}
}