|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
VisitorContainsCheck.java | 0% | 0% | 0% | 0% |
|
1 | /* | |
2 | wsmo4j - a WSMO API and Reference Implementation | |
3 | Copyright (c) 2005, University of Innsbruck, Austria | |
4 | This library is free software; you can redistribute it and/or modify it under | |
5 | the terms of the GNU Lesser General Public License as published by the Free | |
6 | Software Foundation; either version 2.1 of the License, or (at your option) | |
7 | any later version. | |
8 | This library is distributed in the hope that it will be useful, but WITHOUT | |
9 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
10 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
11 | details. | |
12 | You should have received a copy of the GNU Lesser General Public License along | |
13 | with this library; if not, write to the Free Software Foundation, Inc., | |
14 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
15 | */ | |
16 | package org.deri.wsmo4j.logicalexpression.util; | |
17 | ||
18 | ||
19 | import java.util.*; | |
20 | ||
21 | import org.omwg.logicalexpression.*; | |
22 | ||
23 | ||
24 | /** | |
25 | * Class to check if a specified operator of a logical expression is contained in an | |
26 | * array of operators | |
27 | */ | |
28 | public class VisitorContainsCheck | |
29 | implements Visitor { | |
30 | ||
31 | private Class[] operators; | |
32 | ||
33 | private boolean containsOperator; | |
34 | ||
35 | /** | |
36 | * @param operators array of classes that will be checked for | |
37 | * @see org.deri.wsmo4j.logicalexpression.util.ExpressionContainmentUtil#contains(LogicalExpression, Class) | |
38 | */ | |
39 | 0 | protected VisitorContainsCheck(Class[] operators) { |
40 | 0 | containsOperator = false; |
41 | 0 | this.operators = operators; |
42 | } | |
43 | ||
44 | /** | |
45 | * Checks if a specified operator is contained in the array of operators | |
46 | * @param operator operator that will be checked for | |
47 | * @return <code>true</code> if the specified operator is contained | |
48 | */ | |
49 | 0 | private boolean contained(Class operator) { |
50 | 0 | for (int i = 0; i < operators.length; i++) { |
51 | 0 | List classes = Arrays.asList(operator.getInterfaces()); |
52 | 0 | if (classes.contains(operators[i])) { |
53 | 0 | return true; |
54 | } | |
55 | } | |
56 | 0 | return false; |
57 | } | |
58 | ||
59 | /** | |
60 | * Empty method, as an Atom can't contain an operator | |
61 | * @see org.omwg.logicalexpression.Visitor#visitAtom(org.omwg.logicalexpression.Atom) | |
62 | */ | |
63 | 0 | public void visitAtom(Atom expr) { |
64 | //atom can't contain operator | |
65 | } | |
66 | ||
67 | /** | |
68 | * Checks if the operator of the Unary expression is contained in the array of operators | |
69 | * @see org.omwg.logicalexpression.Visitor#visitNegationAsFailure(NegationAsFailure) | |
70 | */ | |
71 | 0 | public void visitNegationAsFailure(NegationAsFailure expr) { |
72 | 0 | if (contained(expr.getClass())) { |
73 | 0 | containsOperator = true; |
74 | 0 | return; |
75 | } | |
76 | 0 | expr.getOperand().accept(this); |
77 | } | |
78 | ||
79 | /** | |
80 | * Checks if the operator of the Unary expression is contained in the array of operators | |
81 | * @see org.omwg.logicalexpression.Visitor#visitNegation(Negation) | |
82 | */ | |
83 | 0 | public void visitNegation(Negation expr) { |
84 | 0 | if (contained(expr.getClass())) { |
85 | 0 | containsOperator = true; |
86 | 0 | return; |
87 | } | |
88 | 0 | expr.getOperand().accept(this); |
89 | } | |
90 | ||
91 | /** | |
92 | * Checks if the operator of the Unary expression is contained in the array of operators | |
93 | * @see org.omwg.logicalexpression.Visitor#visitConstraint(Constraint) | |
94 | */ | |
95 | 0 | public void visitConstraint(Constraint expr) { |
96 | 0 | if (contained(expr.getClass())) { |
97 | 0 | containsOperator = true; |
98 | 0 | return; |
99 | } | |
100 | 0 | expr.getOperand().accept(this); |
101 | } | |
102 | ||
103 | /** | |
104 | * Checks if the operator of the Binary expression is contained in the array of operators | |
105 | * @see org.omwg.logicalexpression.Visitor#visitConjunction(Conjunction) | |
106 | */ | |
107 | 0 | public void visitConjunction(Conjunction expr) { |
108 | 0 | if (contained(expr.getClass())) { |
109 | 0 | containsOperator = true; |
110 | 0 | return; |
111 | } | |
112 | 0 | expr.getLeftOperand().accept(this); |
113 | 0 | expr.getRightOperand().accept(this); |
114 | } | |
115 | ||
116 | /** | |
117 | * Checks if the operator of the Binary expression is contained in the array of operators | |
118 | * @see org.omwg.logicalexpression.Visitor#visitEquivalence(Equivalence) | |
119 | */ | |
120 | 0 | public void visitEquivalence(Equivalence expr) { |
121 | 0 | if (contained(expr.getClass())) { |
122 | 0 | containsOperator = true; |
123 | 0 | return; |
124 | } | |
125 | 0 | expr.getLeftOperand().accept(this); |
126 | 0 | expr.getRightOperand().accept(this); |
127 | } | |
128 | ||
129 | /** | |
130 | * Checks if the operator of the Binary expression is contained in the array of operators | |
131 | * @see org.omwg.logicalexpression.Visitor#visitInverseImplication(InverseImplication) | |
132 | */ | |
133 | 0 | public void visitInverseImplication(InverseImplication expr) { |
134 | 0 | if (contained(expr.getClass())) { |
135 | 0 | containsOperator = true; |
136 | 0 | return; |
137 | } | |
138 | 0 | expr.getLeftOperand().accept(this); |
139 | 0 | expr.getRightOperand().accept(this); |
140 | } | |
141 | ||
142 | /** | |
143 | * Checks if the operator of the Binary expression is contained in the array of operators | |
144 | * @see org.omwg.logicalexpression.Visitor#visitImplication(Implication) | |
145 | */ | |
146 | 0 | public void visitImplication(Implication expr) { |
147 | 0 | if (contained(expr.getClass())) { |
148 | 0 | containsOperator = true; |
149 | 0 | return; |
150 | } | |
151 | 0 | expr.getLeftOperand().accept(this); |
152 | 0 | expr.getRightOperand().accept(this); |
153 | } | |
154 | ||
155 | /** | |
156 | * Checks if the operator of the Binary expression is contained in the array of operators | |
157 | * @see org.omwg.logicalexpression.Visitor#visitLogicProgrammingRule(LogicProgrammingRule) | |
158 | */ | |
159 | 0 | public void visitLogicProgrammingRule(LogicProgrammingRule expr) { |
160 | 0 | if (contained(expr.getClass())) { |
161 | 0 | containsOperator = true; |
162 | 0 | return; |
163 | } | |
164 | 0 | expr.getLeftOperand().accept(this); |
165 | 0 | expr.getRightOperand().accept(this); |
166 | } | |
167 | ||
168 | /** | |
169 | * Checks if the operator of the Binary expression is contained in the array of operators | |
170 | * @see org.omwg.logicalexpression.Visitor#visitDisjunction(Disjunction) | |
171 | */ | |
172 | 0 | public void visitDisjunction(Disjunction expr) { |
173 | 0 | if (contained(expr.getClass())) { |
174 | 0 | containsOperator = true; |
175 | 0 | return; |
176 | } | |
177 | 0 | expr.getLeftOperand().accept(this); |
178 | 0 | expr.getRightOperand().accept(this); |
179 | } | |
180 | ||
181 | /** | |
182 | * Checks if the operator of the Quantified expression is contained in the | |
183 | * array of operators | |
184 | * @see org.omwg.logicalexpression.Visitor#visitUniversalQuantification(UniversalQuantification) | |
185 | */ | |
186 | 0 | public void visitUniversalQuantification(UniversalQuantification expr) { |
187 | 0 | if (contained(expr.getClass())) { |
188 | 0 | containsOperator = true; |
189 | 0 | return; |
190 | } | |
191 | 0 | expr.getOperand().accept(this); |
192 | } | |
193 | ||
194 | /** | |
195 | * Checks if the operator of the Quantified expression is contained in the | |
196 | * array of operators | |
197 | * @see org.omwg.logicalexpression.Visitor#visitExistentialQuantification(ExistentialQuantification) | |
198 | */ | |
199 | 0 | public void visitExistentialQuantification(ExistentialQuantification expr) { |
200 | 0 | if (contained(expr.getClass())) { |
201 | 0 | containsOperator = true; |
202 | 0 | return; |
203 | } | |
204 | 0 | expr.getOperand().accept(this); |
205 | } | |
206 | ||
207 | /** | |
208 | * Checks if the previous logexp the visitor was applied to, | |
209 | * contained the compound expression with the operator passed in constructor. | |
210 | * So it checks if this logexp contained a specified operator. | |
211 | * @return true if it is contained | |
212 | */ | |
213 | 0 | protected boolean isContained() { |
214 | 0 | return containsOperator; |
215 | } | |
216 | ||
217 | 0 | public void visitAttributeContraintMolecule(AttributeConstraintMolecule expr) { |
218 | //atom can't contain operator | |
219 | } | |
220 | ||
221 | 0 | public void visitAttributeInferenceMolecule(AttributeInferenceMolecule expr) { |
222 | //atom can't contain operator | |
223 | } | |
224 | ||
225 | 0 | public void visitAttributeValueMolecule(AttributeValueMolecule expr) { |
226 | //atom can't contain operator | |
227 | } | |
228 | ||
229 | 0 | public void visitCompoundMolecule(CompoundMolecule expr) { |
230 | //atom can't contain operator | |
231 | } | |
232 | ||
233 | 0 | public void visitMemberShipMolecule(MembershipMolecule expr) { |
234 | //atom can't contain operator | |
235 | } | |
236 | ||
237 | 0 | public void visitSubConceptMolecule(SubConceptMolecule expr) { |
238 | //atom can't contain operator | |
239 | } | |
240 | } |
|