View Javadoc

1   /*
2       Copyright 2008 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.output;
18  
19  import java.util.ArrayList;
20  import java.util.Iterator;
21  import java.util.List;
22  
23  import com.philemonworks.selfdiagnose.DiagnosticTaskResult;
24  import com.philemonworks.selfdiagnose.SelfDiagnose;
25  
26  public class DiagnoseRun {
27      public List<DiagnosticTaskResult> results = new ArrayList<DiagnosticTaskResult>();
28      public long timeMs = System.currentTimeMillis();
29  
30      /**
31       * Run has finished. Compute the execution time.
32       */
33      public void finished() {
34          timeMs = System.currentTimeMillis() - timeMs;
35      }
36  
37      public int howManyTasks() {
38          return results.size();
39      }
40  
41      public long totalTime() {
42          return timeMs;
43      }
44  
45      public int howManyNotPassed() {
46          int noTasksFailed = 0;
47          for (Iterator<DiagnosticTaskResult> iterator = results.iterator(); iterator.hasNext();) {
48              DiagnosticTaskResult result = (DiagnosticTaskResult) iterator.next();
49              boolean failed = result.isError() || result.isFailed();
50              if (failed)
51                  noTasksFailed++;
52          }
53          return noTasksFailed;
54      }
55  
56      public String getProductStamp() {
57          return "SelfDiagnose " + SelfDiagnose.VERSION + " " + SelfDiagnose.COPYRIGHT;
58      }
59  
60      public String getTotalsLine() {
61          return "Checks: " + howManyTasks() + " , Failures: " + howManyNotPassed() + " , Time: " + totalTime() + " ms";
62      }
63  
64      public boolean isOK() {
65          return this.howManyNotPassed() == 0;
66      }
67  }