1 18 19 package org.netbeans.modules.changelog; 20 21 22 import java.util.*; 23 24 28 29 30 public class SummaryProcessor { 31 32 34 private static final int MAX_LENGTH = 10; 35 36 37 private int commitCount; 38 39 40 private HashMap usersList; 41 42 private HashMap mostChangedFilesMap; 43 private HashMap activeUsersMap; 44 45 46 public SummaryProcessor() { 47 usersList = new HashMap(); 48 commitCount = 0; 49 mostChangedFilesMap = new HashMap(); 50 } 51 52 53 public void processGroup(RevisionsGroup group) { 54 String user = group.getUser(); 55 increaseCountByOne(usersList, user); 56 commitCount = commitCount + 1; 57 Iterator it = group.getList().iterator(); 58 while (it.hasNext()) { 59 LogInfoRevision rev = (LogInfoRevision)it.next(); 60 increaseCountByOne(mostChangedFilesMap, 61 rev.getLogInfoHeader().getRepositoryFilename()); 62 63 } 64 } 65 66 private void increaseCountByOne(Map map, Object key) { 67 Integer val = (Integer )map.get(key); 68 if (val == null) { 69 val = new Integer (1); 70 } else { 71 val = new Integer (val.intValue() + 1); 72 } 73 map.put(key, val); 74 } 75 76 private List createSortedList(Map map) { 77 Iterator it = map.keySet().iterator(); 78 LinkedList keyList = new LinkedList(); 79 LinkedList valList = new LinkedList(); 80 while (it.hasNext()) { 81 Object key = it.next(); 82 Integer val = (Integer )map.get(key); 83 Iterator valIt = valList.iterator(); 84 boolean wasSet = false; 85 int valIndex = -1; 86 while (valIt.hasNext()) { 87 Integer val2 = (Integer )valIt.next(); 88 valIndex = valIndex + 1; 89 if (val.compareTo(val2) >= 0) { 90 keyList.add(valIndex, key); 91 valList.add(valIndex, val); 92 wasSet = true; 93 break; 94 } 95 } 96 if (!wasSet && keyList.size() < MAX_LENGTH) { 97 keyList.add(key); 98 valList.add(val); 99 } 100 if (keyList.size() >= MAX_LENGTH) { 101 keyList.removeLast(); 102 valList.removeLast(); 103 } 104 } 105 return keyList; 106 } 107 108 111 public String [] getMostActiveUsers() { 112 List topList = createSortedList(usersList); 113 String [] toReturn = new String [topList.size()]; 114 Iterator it = topList.iterator(); 115 int count = 0; 116 while (it.hasNext()) { 117 String item = (String )it.next(); 118 Integer num = (Integer )usersList.get(item); 119 toReturn[count] = num.toString() + " " + item; 120 count = count + 1; 121 } 122 return toReturn; 123 } 124 125 128 public String [] getMostChangedFiles() { 129 List topList = createSortedList(mostChangedFilesMap); 130 String [] toReturn = new String [topList.size()]; 131 Iterator it = topList.iterator(); 132 int count = 0; 133 while (it.hasNext()) { 134 String item = (String )it.next(); 135 Integer num = (Integer )mostChangedFilesMap.get(item); 136 toReturn[count] = num.toString() + " " + item; 137 count = count + 1; 138 } 139 return toReturn; 140 } 141 142 145 public int getCommitCount() { 146 return this.commitCount; 147 } 148 149 152 public String [] getUserList() { 153 String [] toReturn = new String [usersList.size()]; 154 toReturn = (String [])usersList.keySet().toArray(toReturn); 155 return toReturn; 156 } 157 158 } 159 | Popular Tags |