Revision 487
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/evaluator/AndEvaluator.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.tools.evaluator; |
|
23 |
|
|
24 |
import java.util.ArrayList; |
|
25 |
import java.util.List; |
|
26 |
|
|
27 |
|
|
28 |
/** |
|
29 |
* <p> |
|
30 |
* This evaluator is a set of evaluators that are applied used the and |
|
31 |
* operator. It means that the evaluate method only returns <code>true</code> |
|
32 |
* if all the evaluators return <code>true</code>. |
|
33 |
* </p> |
|
34 |
* <p> |
|
35 |
* A condition to use this type of evaluators is that the evaluate method |
|
36 |
* of all the single evaluators has to return a boolean value. |
|
37 |
* </p> |
|
38 |
* |
|
39 |
* @author gvSIG Team |
|
40 |
* @version $Id$ |
|
41 |
* |
|
42 |
*/ |
|
43 |
public class AndEvaluator extends AbstractEvaluator{ |
|
44 |
private List evaluators = new ArrayList(); |
|
45 |
|
|
46 |
public AndEvaluator(Evaluator evaluator) { |
|
47 |
super(); |
|
48 |
addEvaluator(evaluator); |
|
49 |
} |
|
50 |
|
|
51 |
public Object evaluate(EvaluatorData data) throws EvaluatorException { |
|
52 |
for (int i=0 ; i<evaluators.size() ; i++){ |
|
53 |
Evaluator evaluator = (Evaluator)evaluators.get(i); |
|
54 |
if (!((Boolean)evaluator.evaluate(data)).booleanValue()){ |
|
55 |
return new Boolean(false); |
|
56 |
} |
|
57 |
} |
|
58 |
return new Boolean(true); |
|
59 |
} |
|
60 |
|
|
61 |
public String getName() { |
|
62 |
return "a set of evaluators"; |
|
63 |
} |
|
64 |
|
|
65 |
public void addEvaluator(Evaluator evaluator){ |
|
66 |
if (evaluator != null){ |
|
67 |
evaluators.add(evaluator); |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
public String getSQL() { |
|
72 |
if (evaluators.size() > 0){ |
|
73 |
String sql = ((Evaluator)evaluators.get(0)).getSQL(); |
|
74 |
for (int i=1 ; i<evaluators.size() ; i++){ |
|
75 |
sql = sql + " and " + ((Evaluator)evaluators.get(i)).getSQL(); |
|
76 |
} |
|
77 |
return sql; |
|
78 |
}else{ |
|
79 |
return ""; |
|
80 |
} |
|
81 |
} |
|
82 |
} |
|
0 | 83 |
Also available in: Unified diff