1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.javadpkg.control.impl;
20
21 import java.util.Map;
22 import java.util.TreeMap;
23
24 import net.sourceforge.javadpkg.ParseException;
25 import net.sourceforge.javadpkg.control.PackageVersionRelationOperator;
26 import net.sourceforge.javadpkg.control.PackageVersionRelationOperatorParser;
27
28
29
30
31
32
33
34
35
36
37 public class PackageVersionRelationOperatorParserImpl implements PackageVersionRelationOperatorParser {
38
39
40
41 private Map<String, PackageVersionRelationOperator> relationOperators;
42
43
44
45
46
47
48
49 public PackageVersionRelationOperatorParserImpl() {
50 super();
51
52 this.relationOperators = new TreeMap<>();
53 this.addRelationOperator("<<");
54 this.addRelationOperator("<=");
55 this.addRelationOperator("=");
56 this.addRelationOperator(">=");
57 this.addRelationOperator(">>");
58 }
59
60
61
62
63
64
65
66
67
68
69 private void addRelationOperator(String text) {
70 this.relationOperators.put(text, new PackageVersionRelationOperatorImpl(text));
71 }
72
73
74 @Override
75 public PackageVersionRelationOperator parsePackageVersionRelationOperator(String value) throws ParseException {
76 PackageVersionRelationOperator relationOperator;
77
78
79 if (value == null)
80 throw new IllegalArgumentException("Argument value is null.");
81
82 relationOperator = this.relationOperators.get(value);
83 if (relationOperator == null)
84 throw new ParseException("The relational operator |" + value + "| is not a supported relational operator.");
85
86 return relationOperator;
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 private class PackageVersionRelationOperatorImpl implements PackageVersionRelationOperator {
107
108
109
110 private String text;
111
112
113
114
115
116
117
118
119
120
121 public PackageVersionRelationOperatorImpl(String text) {
122 super();
123
124 this.text = text;
125 }
126
127
128 @Override
129 public String getText() {
130 return this.text;
131 }
132
133
134 }
135
136
137 }