• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2008 Google Inc. All Rights Reserved.
2 
3 package autotest.common;
4 
5 import com.google.gwt.json.client.JSONObject;
6 
7 import java.util.Arrays;
8 
9 public class StatusSummary extends AbstractStatusSummary {
10     public int passed = 0;
11     public int complete = 0;
12     public int incomplete = 0;
13     public int total = 0; // TEST_NA is included here, but not in any other
14 
15     private String[] contents = null;
16 
getStatusSummary(JSONObject group, String passCountField, String completeCountField, String incompleteCountField, String groupCountField)17     public static StatusSummary getStatusSummary(JSONObject group, String passCountField,
18                                                 String completeCountField, String incompleteCountField,
19                                                 String groupCountField) {
20         StatusSummary summary = new StatusSummary();
21         summary.passed = getField(group, passCountField);
22         summary.complete = getField(group, completeCountField);
23         summary.incomplete = getField(group, incompleteCountField);
24         summary.total = getField(group, groupCountField);
25 
26         if (group.containsKey("extra_info")) {
27             summary.contents = Utils.JSONtoStrings(group.get("extra_info").isArray());
28         }
29 
30         return summary;
31     }
32 
getField(JSONObject group, String field)33     private static int getField(JSONObject group, String field) {
34         return (int) group.get(field).isNumber().doubleValue();
35     }
36 
37     /**
38      * Force construction to go through getStatusSummary() factory method.
39      */
StatusSummary()40     private StatusSummary() {}
41 
getTotal()42     public int getTotal() {
43         return total;
44     }
45 
formatContents()46     public String formatContents() {
47         String result = formatStatusCounts();
48 
49         if (contents != null) {
50             result += "<br>";
51             result += Utils.joinStrings("<br>", Arrays.asList(contents), true);
52         }
53 
54         return result;
55     }
56 
57     @Override
getComplete()58     protected int getComplete() {
59         return complete;
60     }
61 
62     @Override
getIncomplete()63     protected int getIncomplete() {
64         return incomplete;
65     }
66 
67     @Override
getPassed()68     protected int getPassed() {
69         return passed;
70     }
71 }
72