Change header template for a new version
[jabaws.git] / webservices / compbio / stat / servlet / util / Totals.java
1 /* Copyright (c) 2011 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 package compbio.stat.servlet.util;\r
19 \r
20 import java.util.Date;\r
21 import java.util.Map;\r
22 \r
23 import compbio.stat.collector.StatProcessor;\r
24 import compbio.ws.client.Services;\r
25 \r
26 public class Totals {\r
27         int total;\r
28         int incomplete;\r
29         int abandoned;\r
30         int cancelled;\r
31         int failed;\r
32 \r
33         public int getTotal() {\r
34                 return total;\r
35         }\r
36 \r
37         public int getIncomplete() {\r
38                 return incomplete;\r
39         }\r
40 \r
41         public int getAbandoned() {\r
42                 return abandoned;\r
43         }\r
44 \r
45         public int getCancelled() {\r
46                 return cancelled;\r
47         }\r
48 \r
49         public int getFailed() {\r
50                 return failed;\r
51         }\r
52 \r
53         public static Totals sumOfTotals(Map<Date, Totals> stat) {\r
54                 Totals total = new Totals();\r
55                 for (Map.Entry<Date, Totals> entry : stat.entrySet()) {\r
56                         Totals mtotal = entry.getValue();\r
57                         total.total += mtotal.getTotal();\r
58                         total.incomplete += mtotal.getIncomplete();\r
59                         total.abandoned += mtotal.getAbandoned();\r
60                         total.cancelled += mtotal.getCancelled();\r
61                         total.failed += mtotal.getFailed();\r
62                 }\r
63                 return total;\r
64         }\r
65 \r
66         public static Totals sumStats(Map<Services, StatProcessor> stat) {\r
67                 Totals total = new Totals();\r
68                 for (Map.Entry<Services, StatProcessor> serv : stat.entrySet()) {\r
69                         total.total += serv.getValue().getJobNumber();\r
70                         total.incomplete += serv.getValue().getIncompleteJobs().size();\r
71                         total.abandoned += serv.getValue().getAbandonedJobs().size();\r
72                         total.cancelled += serv.getValue().getCancelledJobs().size();\r
73                         total.failed += serv.getValue().getFailedJobs().size();\r
74                 }\r
75                 return total;\r
76         }\r
77 }