1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.pkg;
21
22
23 /***
24 */
25 public class PackageToken extends AbstractToken
26 {
27
28
29
30 public static final String[] COMPARE_MODES = new String[] {
31 "=", ">=", ">>", "<=", "<<"
32 };
33
34
35
36 String compareMode;
37 String name;
38 String version;
39
40
41
42 public PackageToken(String name, String compareMode, String version)
43 throws ParseException
44 {
45 this.name = name;
46 this.compareMode = compareMode;
47 this.version = version;
48
49 this.token = name;
50 if (compareMode != null) {
51 validate();
52 this.token += "(" + compareMode + " " + version + ")";
53 }
54 }
55
56
57
58 public boolean equalsVersion(int result)
59 {
60 if (compareMode.equals("=")) {
61 return result == 0;
62 }
63 else if (compareMode.equals(">=")) {
64 return result >= 0;
65 }
66 else if (compareMode.equals(">>")) {
67 return result > 0;
68 }
69 else if (compareMode.equals("<=")) {
70 return result <= 0;
71 }
72 else if (compareMode.equals("<<")) {
73 return result < 0;
74 }
75
76 throw new RuntimeException("invalid comparator");
77 }
78
79 private void validate() throws ParseException
80 {
81 for (int i = 0; i < COMPARE_MODES.length; i++) {
82 if (COMPARE_MODES[i].equals(compareMode)) {
83 return;
84 }
85 }
86 throw new ParseException("Invalid version comparator");
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 }
108