01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
20: import java.util.HashMap;
21: import java.util.Map;
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 {
28:
29: private Map<Long, Counts> counts = new HashMap<Long, Counts>();
30:
31: public void addLoggedByMe(long spaceId, long count) {
32: add(Counts.LOGGED_BY_ME, spaceId, count);
33: }
34:
35: public void addAssignedToMe(long spaceId, long count) {
36: add(Counts.ASSIGNED_TO_ME, spaceId, count);
37: }
38:
39: public void addTotal(long spaceId, long count) {
40: add(Counts.TOTAL, spaceId, count);
41: }
42:
43: private void add(int type, long spaceId, long count) {
44: Counts c = counts.get(spaceId);
45: if (c == null) {
46: c = new Counts(false);
47: counts.put(spaceId, c);
48: }
49: c.add(type, -1, count);
50: }
51:
52: private int getTotalForType(int type) {
53: int total = 0;
54: for (Counts c : counts.values()) {
55: total += c.getTotalForType(type);
56: }
57: return total;
58: }
59:
60: public int getTotalLoggedByMe() {
61: return getTotalForType(Counts.LOGGED_BY_ME);
62: }
63:
64: public int getTotalAssignedToMe() {
65: return getTotalForType(Counts.ASSIGNED_TO_ME);
66: }
67:
68: public int getTotalTotal() {
69: return getTotalForType(Counts.TOTAL);
70: }
71:
72: public Map<Long, Counts> getCounts() {
73: return counts;
74: }
75:
76: }
|