StatusSummary.java revision aac545784cea51dbe230c6c126b52987b7906fb5
1// Copyright 2008 Google Inc. All Rights Reserved.
2
3package autotest.common;
4
5import com.google.gwt.json.client.JSONObject;
6
7import java.util.Arrays;
8
9public 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
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
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     */
40    private StatusSummary() {}
41
42    public int getTotal() {
43        return total;
44    }
45
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
58    protected int getComplete() {
59        return complete;
60    }
61
62    @Override
63    protected int getIncomplete() {
64        return incomplete;
65    }
66
67    @Override
68    protected int getPassed() {
69        return passed;
70    }
71}
72