(no commit message)
[utils] / support / general / src / main / java / org / wamblee / conditions / AndCondition.java
1 /*
2  * Copyright 2005-2010 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.conditions;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 /**
22  * Represents a logical and of different boolean conditions.
23  * 
24  * @author Erik Brakkee
25  * 
26  */
27 public class AndCondition<T> implements Condition<T> {
28     private List<Condition<T>> conditions;
29
30     /**
31      * Constructs the condition.
32      * 
33      * @param aCondition1
34      *            First condition.
35      * @param aCondition2
36      *            Second condition.
37      */
38     public AndCondition(Condition<T> aCondition1, Condition<T> aCondition2) {
39         conditions = new ArrayList<Condition<T>>();
40         conditions.add(aCondition1);
41         conditions.add(aCondition2);
42     }
43
44     /**
45      * Constructs the and condition.
46      * 
47      * @param aConditions
48      *            List of conditions to use in the logical and.
49      */
50     public AndCondition(List<Condition<T>> aConditions) {
51         conditions = aConditions;
52     }
53
54     /*
55      * (non-Javadoc)
56      * 
57      * @see
58      * org.wamblee.crawler.kiss.ProgramMatcher#matches(org.wamblee.crawler.kiss
59      * .Program)
60      */
61     public boolean matches(T aObject) {
62         for (Condition<T> condition : conditions) {
63             if (!condition.matches(aObject)) {
64                 return false;
65             }
66         }
67
68         return true;
69     }
70 }