View Javadoc

1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
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 p3j.experiment.results.filters;
17  
18  import java.util.Set;
19  
20  import p3j.experiment.results.ResultsOfTrial;
21  import p3j.pppm.parameters.ParameterAssignment;
22  
23  /**
24   * This is a configurable result filter. It is initialized with a list of
25   * assignment IDs. Each result is checked: only if it contains at least *one* of
26   * the given IDs, it will be considered. In other words, the set of IDs can be
27   * considered as a white list.
28   * 
29   * @see ParameterAssignment
30   * @see ResultsOfTrial
31   * @see p3j.experiment.results.ResultExport
32   * 
33   * @author Christina Bohk
34   * @author Roland Ewald
35   * 
36   */
37  public class ConfigurableResultFilter implements IResultFilter {
38  
39  	/** The assignment IDs. */
40  	private final Set<Integer> assignmentIDs;
41  
42  	/**
43  	 * Instantiates a new configurable result filter.
44  	 * 
45  	 * @param requiredIDs
46  	 *          the list of assignment IDs defining the filter
47  	 */
48  	public ConfigurableResultFilter(Set<Integer> requiredIDs) {
49  		assignmentIDs = requiredIDs;
50  	}
51  
52  	@Override
53  	public boolean considerResult(ResultsOfTrial results) {
54  		for (ParameterAssignment assignment : results.getAssignment().values()) {
55  			if (assignmentIDs.contains(assignment.getID())) {
56  				return true;
57  			}
58  		}
59  		return false;
60  	}
61  }