a15b4eff152fc9e4c15fc05bbc76f73c7f0febf5
[utils] / support / general / src / main / java / org / wamblee / conditions / OrCondition.java
1 /*
2  * Copyright 2005 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
17 package org.wamblee.conditions;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 /**
23  * Represents a logical or of different boolean conditions.
24  *
25  * @author Erik Brakkee
26  */
27 public class OrCondition<T> implements Condition<T> {
28
29     private List<Condition<T>> conditions;
30
31     /**
32      * Constructs the condition.
33      * 
34      * @param aCondition1
35      *            First condition.
36      * @param aCondition2
37      *            Second condition.
38      */
39     public OrCondition(Condition<T> aCondition1, Condition<T> aCondition2) {
40         conditions = new ArrayList<Condition<T>>();
41         conditions.add(aCondition1);
42         conditions.add(aCondition2);
43     }
44
45     /**
46      * Constructs the or condition.
47      * 
48      * @param aConditions
49      *            List of conditions to use in the logical or.
50      */
51     public OrCondition(List<Condition<T>> aConditions) {
52         conditions = aConditions;
53     }
54
55     /*
56      * (non-Javadoc)
57      * 
58      * @see org.wamblee.crawler.kiss.ProgramMatcher#matches(org.wamblee.crawler.kiss.Program)
59      */
60     public boolean matches(T aObject) {
61         for (Condition<T> condition : conditions) {
62             if (condition.matches(aObject)) {
63                 return true;
64             }
65         }
66         return false;
67     }
68
69 }