VersionRange.java
4.28 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.jackrabbit.vault.packaging.VersionRange
*/
package com.day.jcr.vault.packaging;
import com.day.jcr.vault.packaging.Version;
@Deprecated
public class VersionRange {
public static final VersionRange INFINITE = new VersionRange(null, true, null, true);
private final Version low;
private final boolean lowIncl;
private final Version high;
private final boolean highIncl;
private final String str;
public VersionRange(Version low, boolean lowIncl, Version high, boolean highIncl) {
if (low != null && high != null) {
int comp = low.compareTo(high);
if (comp > 0) {
throw new IllegalArgumentException("lower bound must be less or equal to upper bound.");
}
if (!(comp != 0 || lowIncl && highIncl)) {
throw new IllegalArgumentException("invalid empty range. upper and lower bound must be inclusive.");
}
}
this.low = low;
this.lowIncl = lowIncl;
this.high = high;
this.highIncl = highIncl;
StringBuilder b = new StringBuilder();
if (low != null || high != null) {
if (high == null) {
if (lowIncl) {
b.append(low);
} else {
b.append('(');
b.append(low);
b.append(",)");
}
} else if (low == null) {
b.append("[,");
b.append(high);
b.append(highIncl ? ']' : ')');
} else {
b.append(lowIncl ? '[' : '(');
b.append(low);
b.append(',');
b.append(high);
b.append(highIncl ? ']' : ')');
}
}
this.str = b.toString();
}
public VersionRange(Version v) {
this(v, true, v, true);
}
public Version getLow() {
return this.low;
}
public boolean isLowInclusive() {
return this.lowIncl;
}
public Version getHigh() {
return this.high;
}
public boolean isHighInclusive() {
return this.highIncl;
}
public int hashCode() {
return this.str.hashCode();
}
public boolean equals(Object obj) {
return this == obj || obj instanceof VersionRange && this.str.equals(obj.toString());
}
public String toString() {
return this.str;
}
public boolean isInRange(Version v) {
int comp;
if (this.low != null && ((comp = v.osgiCompareTo(this.low)) < 0 || comp == 0 && !this.lowIncl)) {
return false;
}
if (this.high != null && ((comp = v.osgiCompareTo(this.high)) > 0 || comp == 0 && !this.highIncl)) {
return false;
}
return true;
}
public static VersionRange fromString(String str) {
int idx = str.indexOf(44);
if (idx >= 0) {
boolean linc = false;
int lm = str.indexOf(40);
if (lm < 0) {
lm = str.indexOf(91);
if (lm < 0) {
throw new IllegalArgumentException("Range must start with '[' or '('");
}
linc = true;
}
boolean hinc = false;
int hm = str.indexOf(41);
if (hm < 0) {
hm = str.indexOf(93);
if (hm < 0) {
throw new IllegalArgumentException("Range must end with ']' or ')'");
}
hinc = true;
}
String low = str.substring(lm + 1, idx).trim();
String high = str.substring(idx + 1, hm).trim();
Version vLow = low.length() == 0 ? null : Version.create(low);
Version vHigh = high.length() == 0 ? null : Version.create(high);
return new VersionRange(vLow, linc, vHigh, hinc);
}
if (str.length() == 0) {
return new VersionRange(null, false, null, false);
}
return new VersionRange(Version.create(str), true, null, false);
}
public org.apache.jackrabbit.vault.packaging.VersionRange toJrVltVersionRange() {
return org.apache.jackrabbit.vault.packaging.VersionRange.fromString((String)this.str);
}
}