1 /*
2 * dpkg - Debian Package library and the Debian Package Maven plugin
3 * (c) Copyright 2016 Gerrit Hohl
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 * <p>
31 * A {@link PackageVersionRelationOperatorParser} implementation.
32 * </p>
33 *
34 * @author Gerrit Hohl (gerrit-hohl@users.sourceforge.net)
35 * @version <b>1.0</b>, 01.01.2016 by Gerrit Hohl
36 */
37 public class PackageVersionRelationOperatorParserImpl implements PackageVersionRelationOperatorParser {
38
39
40 /** The relational operators. */
41 private Map<String, PackageVersionRelationOperator> relationOperators;
42
43
44 /**
45 * <p>
46 * Creates a parser.
47 * </p>
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 * <p>
63 * Adds a relation operator to the internal map.
64 * </p>
65 *
66 * @param text
67 * The text.
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 * <p>
100 * The {@link PackageVersionRelationOperator} implementation of this class.
101 * </p>
102 *
103 * @author Gerrit Hohl (gerrit-hohl@users.sourceforge.net)
104 * @version <b>1.0</b>, 01.01.2016 by Gerrit Hohl
105 */
106 private class PackageVersionRelationOperatorImpl implements PackageVersionRelationOperator {
107
108
109 /** The text. */
110 private String text;
111
112
113 /**
114 * <p>
115 * Creates a relation operator.
116 * </p>
117 *
118 * @param text
119 * The text.
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 }