1 11 package org.eclipse.team.internal.core.subscribers; 12 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.Map ; 16 17 import org.eclipse.team.core.synchronize.SyncInfo; 18 19 22 public class SyncInfoStatistics { 23 protected Map stats = new HashMap (); 25 26 30 public void add(SyncInfo info) { 31 Long count = (Long )stats.get(new Integer (info.getKind())); 33 if(count == null) { 34 count = new Long (0); 35 } 36 stats.put(new Integer (info.getKind()), new Long (count.longValue() + 1)); 37 } 38 39 43 public void remove(SyncInfo info) { 44 Integer kind = new Integer (info.getKind()); 46 Long count = (Long )stats.get(kind); 47 if(count == null) { 48 } else { 51 long newCount = count.intValue() - 1; 52 if(newCount > 0) { 53 stats.put(kind, new Long (newCount)); 54 } else { 55 stats.remove(kind); 56 } 57 } 58 } 59 60 70 public long countFor(int kind, int mask) { 71 if(mask == 0) { 72 Long count = (Long )stats.get(new Integer (kind)); 73 return count == null ? 0 : count.longValue(); 74 } else { 75 Iterator it = stats.keySet().iterator(); 76 long count = 0; 77 while (it.hasNext()) { 78 Integer key = (Integer ) it.next(); 79 if((key.intValue() & mask) == kind) { 80 count += ((Long )stats.get(key)).intValue(); 81 } 82 } 83 return count; 84 } 85 } 86 87 91 public void clear() { 92 stats.clear(); 93 } 94 95 98 public String toString() { 99 StringBuffer out = new StringBuffer (); 100 Iterator it = stats.keySet().iterator(); 101 while (it.hasNext()) { 102 Integer kind = (Integer ) it.next(); 103 out.append(SyncInfo.kindToString(kind.intValue()) + ": " + stats.get(kind) + "\n"); } 105 return out.toString(); 106 } 107 } 108 | Popular Tags |