Version.java
2.02 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.jackrabbit.util.Text
*/
package com.day.cq.commons;
import java.util.ArrayList;
import org.apache.jackrabbit.util.Text;
public class Version
implements Comparable<Version> {
public static final Version EMPTY = new Version("", new String[0]);
private final String str;
private final String[] segments;
public static Version create(String str) {
if (str == null || str.length() == 0) {
return EMPTY;
}
return new Version(str, Text.explode((String)str, (int)46));
}
public static Version create(String[] segments) {
if (segments == null || segments.length == 0) {
return EMPTY;
}
return new Version(Text.implode((String[])segments, (String)"."), segments);
}
private Version(String str, String[] segments) {
if (str == null) {
throw new NullPointerException("Version String must not be null.");
}
this.str = str;
ArrayList<String> list = new ArrayList<String>();
for (String seg : segments) {
for (String sub : Text.explode((String)seg, (int)45)) {
list.add(sub);
}
}
this.segments = list.toArray(new String[list.size()]);
}
public int hashCode() {
return this.str.hashCode();
}
public boolean equals(Object o) {
return this == o || o instanceof Version && this.str.equals(((Version)o).str);
}
public String toString() {
return this.str;
}
public String[] getNormalizedSegments() {
return this.segments;
}
@Override
public int compareTo(Version o) {
String[] oSegs = o.getNormalizedSegments();
for (int i = 0; i < Math.min(this.segments.length, oSegs.length); ++i) {
int comp = this.segments[i].compareTo(oSegs[i]);
if (comp == 0) continue;
return comp;
}
return this.segments.length - oSegs.length;
}
}