View Javadoc

1   package net.obsearch.filter;
2   
3   import java.util.LinkedList;
4   import java.util.List;
5   
6   import net.obsearch.OB;
7   
8   /*
9    OBSearch: a distributed similarity search engine This project is to
10   similarity search what 'bit-torrent' is to downloads. 
11   Copyright (C) 2008 Arnoldo Jose Muller Molina
12  
13   This program is free software: you can redistribute it and/or modify
14   it under the terms of the GNU General Public License as published by
15   the Free Software Foundation, either version 3 of the License, or
16   (at your option) any later version.
17  
18   This program is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21   GNU General Public License for more details.
22  
23   You should have received a copy of the GNU General Public License
24   along with this program.  If not, see <http://www.gnu.org/licenses/>.
25   */
26  
27  /**
28   * FilterOr creates an or of filters. If any of the 
29   * added filters returns true, this filter also returns true.
30   * 
31   * @author Arnoldo Jose Muller Molina
32   */
33  
34  public final class FilterOr<O extends OB> implements Filter<O> {
35  
36  	private List<Filter<O>> andList;
37  	
38  	public FilterOr(){
39  		andList = new LinkedList<Filter<O>>();
40  	}
41  
42  	public boolean accept(O dbObject, O query) {
43  		for(Filter<O> f : andList){
44  			if(f.accept(dbObject, query)){
45  				return true;
46  			}
47  		}
48  		return false;
49  	}
50  	
51  	public void addFilter(Filter<O> f){
52  		andList.add(f);
53  	}
54  }