1 /* 2 * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.] 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.opensaml.xml.security; 18 19 import java.util.Iterator; 20 import java.util.Set; 21 22 /** 23 * An implementation of {@link Iterable} which wraps another underlying Iterable in order to support 24 * production of instances of {@link CriteriaFilteringIterator} based on the underlying Iterable's Iterator. 25 * 26 * For iterator behavior and meaning and use of the parameters, see {@link CriteriaFilteringIterator}. 27 * 28 * @param <T> the type of candidate elements being evaluated 29 */ 30 public class CriteriaFilteringIterable<T> implements Iterable<T> { 31 32 /** The candidates to evaluate. */ 33 private Iterable<? extends T> candidates; 34 35 /** The set of criteria against which to evaluate the candidates. */ 36 private Set<EvaluableCriteria<T>> criteriaSet; 37 38 /** Flag indicating whether the candidate must satisfy all the criteria in the set, or just one. */ 39 private boolean meetAll; 40 41 /** Flag indicating how candidates which can not be evaluated by a criteria are to be handled. */ 42 private boolean unevaledSatisfies; 43 44 /** 45 * Constructor. 46 * 47 * @param candidatesIterable the candidates to evaluate 48 * @param criteria the set of criteria against which to evaluate the candidates 49 * @param meetAllCriteria whether a candidate must meet all criteria, or just one 50 * @param unevaluableSatisfies whether a can-not-evaluate result of a particular criteria's evaluation 51 * is treated as the candidate having satisfied or not satisfied the criteria, for purposes 52 * of determinig whether to return the element 53 */ 54 public CriteriaFilteringIterable(Iterable<? extends T> candidatesIterable, Set<EvaluableCriteria<T>> criteria, 55 boolean meetAllCriteria, boolean unevaluableSatisfies) { 56 57 candidates = candidatesIterable; 58 criteriaSet = criteria; 59 meetAll = meetAllCriteria; 60 unevaledSatisfies = unevaluableSatisfies; 61 } 62 63 /** {@inheritDoc} */ 64 public Iterator<T> iterator() { 65 return new CriteriaFilteringIterator<T>(candidates.iterator(), criteriaSet, meetAll, unevaledSatisfies); 66 } 67 68 }