1 16 17 package info.jtrac.domain; 18 19 import java.io.Serializable ; 20 import java.util.EnumMap ; 21 import java.util.HashMap ; 22 import java.util.Map ; 23 24 29 public class Counts implements Serializable { 30 31 public static final int ASSIGNED_TO_ME = 1; 32 public static final int LOGGED_BY_ME = 2; 33 public static final int TOTAL = 3; 34 35 private Map <Integer , Map <Integer , Integer >> typeCounts = new HashMap <Integer , Map <Integer , Integer >>(); 36 37 public void add(int type, int state, int count) { 38 Map <Integer , Integer > stateCounts = typeCounts.get(type); 39 if (stateCounts == null) { 40 stateCounts = new HashMap <Integer , Integer >(); 41 typeCounts.put(type, stateCounts); 42 } 43 Integer i = stateCounts.get(state); 44 if (i == null) { 45 stateCounts.put(state, count); 46 } else { 47 stateCounts.put(state, i + count); 48 } 49 } 50 51 protected int getTotalForType(int type) { 52 Map <Integer , Integer > stateCounts = typeCounts.get(type); 53 if (stateCounts == null) { 54 return 0; 55 } 56 int total = 0; 57 for(Map.Entry <Integer , Integer > entry : stateCounts.entrySet()) { 58 total += entry.getValue(); 59 } 60 return total; 61 } 62 63 public int getLoggedByMe() { 64 return getTotalForType(LOGGED_BY_ME); 65 } 66 67 public int getAssignedToMe() { 68 return getTotalForType(ASSIGNED_TO_ME); 69 } 70 71 public int getTotal() { 72 return getTotalForType(TOTAL); 73 } 74 75 public Map <Integer , Integer > getLoggedByMeMap() { 76 return typeCounts.get(LOGGED_BY_ME); 77 } 78 79 public Map <Integer , Integer > getAssignedToMeMap() { 80 return typeCounts.get(ASSIGNED_TO_ME); 81 } 82 83 public Map <Integer , Integer > getTotalMap() { 84 return typeCounts.get(TOTAL); 85 } 86 87 } 88 | Popular Tags |