KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > jtrac > domain > CountsHolder


1 /*
2  * Copyright 2002-2005 the original author or authors.
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 info.jtrac.domain;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 /**
24  * Just wraps a Map of Counts keyed to Space ids
25  * but adds logic for adding and iterative totalling
26  */

27 public class CountsHolder implements Serializable JavaDoc {
28
29     Map JavaDoc<Long JavaDoc, Counts> counts = new HashMap JavaDoc<Long JavaDoc, Counts>();
30     
31     public void add(long spaceId, int type, int state, int count) {
32         Counts c = counts.get(spaceId);
33         if (c == null) {
34             c = new Counts();
35             counts.put(spaceId, c);
36         }
37         c.add(type, state, count);
38     }
39     
40     private int getTotalForType(int type) {
41         int total = 0;
42         for(Counts c : counts.values()) {
43             total += c.getTotalForType(type);
44         }
45         return total;
46     }
47     
48     public int getTotalLoggedByMe() {
49         return getTotalForType(Counts.LOGGED_BY_ME);
50     }
51         
52     public int getTotalAssignedToMe() {
53         return getTotalForType(Counts.ASSIGNED_TO_ME);
54     }
55     
56     public int getTotalTotal() {
57         return getTotalForType(Counts.TOTAL);
58     }
59
60     public Map JavaDoc<Long JavaDoc, Counts> getCounts() {
61         return counts;
62     }
63     
64 }
65
Popular Tags