blob: a0486ba2be12c906ecfd9ae206c8eb8599fe6e57 (
plain)
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
|
package uk.ac.cam.cl.xeno.domctl;
public class StringPattern
{
String base;
int bn;
boolean addDom;
boolean appendDom;
static StringPattern parse (String t)
{
StringPattern result = new StringPattern ();
char[] ca = t.toCharArray ();
int idx = 0;
int len = ca.length;
if (len == 0) {
result.base = "";
result.bn = 0;
result.addDom = false;
} else if (ca[len - 1] == '+') {
idx = len - 2;
if ((idx >= 0) && (ca[idx] >= '0') && (ca[idx] <= '9')) {
while ((idx >= 0) && (ca[idx] >= '0') && (ca[idx] <= '9')) {
idx --;
}
result.base = t.substring(0, idx + 1);
result.bn = Integer.parseInt (t.substring (idx + 1, len - 1));
result.addDom = true;
} else {
result.base = t.substring(0, len - 1);
result.appendDom = true;
}
} else {
result.base = t;
}
return result;
}
public String resolve (int domain_id) {
if (addDom) {
return base + (bn + domain_id);
} else if (appendDom) {
return base + domain_id;
} else {
return base;
}
}
public String toString () {
return ("[" +
base +
(addDom ? "+" + bn : "") +
((addDom || appendDom) ? "+ID" : "") +
"]");
}
}
|