View Javadoc

1   /*
2       Copyright 2006-2011 Ernest Micklei @ PhilemonWorks.com
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 com.philemonworks.selfdiagnose;
18  
19  import java.util.ArrayList;
20  import java.util.Iterator;
21  import java.util.List;
22  
23  /**
24   * CompositeDiagnosticTaskResult is
25   *
26   * @author E.M.Micklei
27   */
28  public class CompositeDiagnosticTaskResult extends DiagnosticTaskResult {
29  	
30  	private List results = new ArrayList();
31  	public boolean includeCompositeResult = true;
32  	/**
33  	 * @param task
34  	 */
35  	public CompositeDiagnosticTaskResult(DiagnosticTask task) {
36  		super(task);		
37  	}
38  	public void addResult(DiagnosticTaskResult result){
39  		results.add(result);
40  	}
41  	public List getResults(){
42  		return results;
43  	}
44  	public int howManyErrors(){
45  		int sum=0;
46  		for (Iterator iter = results.iterator(); iter.hasNext();) {
47  			DiagnosticTaskResult element = (DiagnosticTaskResult) iter.next();
48  			if (!element.isPassed()) sum++;			
49  		}
50  		return sum;
51  	}
52  	/**
53  	 * Add all results to the list.
54  	 */
55      public void addToResults(List newResults) {
56      	if (includeCompositeResult) newResults.add(this);
57          // add all or mine
58          newResults.addAll(results);  
59      }	
60      
61      public String toString() {
62      	StringBuilder sb = new StringBuilder();
63      	sb.append(super.toString());
64      	for (int i=0;i<results.size();i++) {
65      		sb.append("\n\t");
66      		sb.append(results.get(i));
67      	}
68      	return sb.toString();
69      }
70  }