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