1 11 package org.eclipse.team.internal.core.subscribers; 12 13 import java.util.*; 14 15 import org.eclipse.team.core.diff.IDiff; 16 import org.eclipse.team.core.diff.IThreeWayDiff; 17 import org.eclipse.team.core.synchronize.SyncInfo; 18 19 public class DiffTreeStatistics { 20 protected Map stats = new HashMap(); 22 23 27 public void add(int state) { 28 Long count = (Long )stats.get(new Integer (state)); 30 if(count == null) { 31 count = new Long (0); 32 } 33 stats.put(new Integer (state), new Long (count.longValue() + 1)); 34 } 35 36 40 public void remove(int state) { 41 Integer kind = new Integer (state); 43 Long count = (Long )stats.get(kind); 44 if(count == null) { 45 } else { 48 long newCount = count.intValue() - 1; 49 if(newCount > 0) { 50 stats.put(kind, new Long (newCount)); 51 } else { 52 stats.remove(kind); 53 } 54 } 55 } 56 57 67 public long countFor(int state, int mask) { 68 if(mask == 0) { 69 Long count = (Long )stats.get(new Integer (state)); 70 return count == null ? 0 : count.longValue(); 71 } else { 72 Iterator it = stats.keySet().iterator(); 73 long count = 0; 74 while (it.hasNext()) { 75 Integer key = (Integer ) it.next(); 76 if((key.intValue() & mask) == state) { 77 count += ((Long )stats.get(key)).intValue(); 78 } 79 } 80 return count; 81 } 82 } 83 84 88 public void clear() { 89 stats.clear(); 90 } 91 92 95 public String toString() { 96 StringBuffer out = new StringBuffer (); 97 Iterator it = stats.keySet().iterator(); 98 while (it.hasNext()) { 99 Integer kind = (Integer ) it.next(); 100 out.append(SyncInfo.kindToString(kind.intValue()) + ": " + stats.get(kind) + "\n"); } 102 return out.toString(); 103 } 104 105 public void add(IDiff delta) { 106 int state = getState(delta); 107 add(state); 108 } 109 110 public void remove(IDiff delta) { 111 int state = getState(delta); 112 remove(state); 113 } 114 115 private int getState(IDiff delta) { 116 int state = delta.getKind(); 117 if (delta instanceof IThreeWayDiff) { 118 IThreeWayDiff twd = (IThreeWayDiff) delta; 119 state |= twd.getDirection(); 120 } 121 return state; 122 } 123 } 124 | Popular Tags |