| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DataSearcher |
|
| 1.5;1.5 |
| 1 | package org.jtheque.films.services.impl.utils.search; | |
| 2 | ||
| 3 | import org.jtheque.utils.collections.CollectionUtils; | |
| 4 | import org.jtheque.utils.collections.Filter; | |
| 5 | ||
| 6 | import java.util.ArrayList; | |
| 7 | import java.util.Collection; | |
| 8 | ||
| 9 | /* | |
| 10 | * This file is part of JTheque. | |
| 11 | * | |
| 12 | * JTheque is free software: you can redistribute it and/or modify | |
| 13 | * it under the terms of the GNU General Public License as published by | |
| 14 | * the Free Software Foundation, either version 3 of the License. | |
| 15 | * | |
| 16 | * JTheque is distributed in the hope that it will be useful, | |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | * GNU General Public License for more details. | |
| 20 | * | |
| 21 | * You should have received a copy of the GNU General Public License | |
| 22 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
| 23 | */ | |
| 24 | ||
| 25 | /** | |
| 26 | * A data searcher. It search on a selected Collection using some filters. | |
| 27 | * | |
| 28 | * @author Baptiste Wicht | |
| 29 | * @param <T> The type of data to search. | |
| 30 | */ | |
| 31 | 0 | public final class DataSearcher<T> implements Searcher<T> { |
| 32 | 0 | private final Collection<Filter<T>> filters = new ArrayList<Filter<T>>(10); |
| 33 | ||
| 34 | @Override | |
| 35 | public void addFilter(Filter<T> filter) { | |
| 36 | 0 | filters.add(filter); |
| 37 | 0 | } |
| 38 | ||
| 39 | @Override | |
| 40 | public Collection<T> search(Collection<T> datas) { | |
| 41 | 0 | Collection<T> filteredCopy = new ArrayList<T>(datas); |
| 42 | ||
| 43 | 0 | for (Filter<T> filter : filters) { |
| 44 | 0 | CollectionUtils.filter(filteredCopy, filter); |
| 45 | } | |
| 46 | ||
| 47 | 0 | return filteredCopy; |
| 48 | } | |
| 49 | } |