KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > changelog > SummaryProcessor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Ralph Krueger.
17  */

18
19 package org.netbeans.modules.changelog;
20
21
22 import java.util.*;
23
24 /**
25  *
26  * @author Ralph Krueger
27  */

28
29
30 public class SummaryProcessor {
31
32     /** the max. number of top values.
33      */

34     private static final int MAX_LENGTH = 10;
35
36     /** Holds value of property commitCount. */
37     private int commitCount;
38
39     /** Holds value of property userList. */
40     private HashMap usersList;
41
42     private HashMap mostChangedFilesMap;
43     private HashMap activeUsersMap;
44
45     /** Creates a new instance of SummaryProcessor */
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 JavaDoc 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 JavaDoc key) {
67         Integer JavaDoc val = (Integer JavaDoc)map.get(key);
68         if (val == null) {
69             val = new Integer JavaDoc(1);
70         } else {
71             val = new Integer JavaDoc(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 JavaDoc key = it.next();
82             Integer JavaDoc val = (Integer JavaDoc)map.get(key);
83             Iterator valIt = valList.iterator();
84             boolean wasSet = false;
85             int valIndex = -1;
86             while (valIt.hasNext()) {
87                 Integer JavaDoc val2 = (Integer JavaDoc)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     /** Getter for property mostActiveUsers.
109      * @return Value of property mostActiveUsers.
110      */

111     public String JavaDoc[] getMostActiveUsers() {
112         List topList = createSortedList(usersList);
113         String JavaDoc[] toReturn = new String JavaDoc[topList.size()];
114         Iterator it = topList.iterator();
115         int count = 0;
116         while (it.hasNext()) {
117             String JavaDoc item = (String JavaDoc)it.next();
118             Integer JavaDoc num = (Integer JavaDoc)usersList.get(item);
119             toReturn[count] = num.toString() + " " + item;
120             count = count + 1;
121         }
122         return toReturn;
123     }
124     
125     /** Getter for property mostChangedFiles.
126      * @return Value of property mostChangedFiles.
127      */

128     public String JavaDoc[] getMostChangedFiles() {
129         List topList = createSortedList(mostChangedFilesMap);
130         String JavaDoc[] toReturn = new String JavaDoc[topList.size()];
131         Iterator it = topList.iterator();
132         int count = 0;
133         while (it.hasNext()) {
134             String JavaDoc item = (String JavaDoc)it.next();
135             Integer JavaDoc num = (Integer JavaDoc)mostChangedFilesMap.get(item);
136             toReturn[count] = num.toString() + " " + item;
137             count = count + 1;
138         }
139         return toReturn;
140     }
141
142     /** Getter for property commitCount.
143      * @return Value of property commitCount.
144      */

145     public int getCommitCount() {
146         return this.commitCount;
147     }
148     
149     /** Getter for property userList.
150      * @return Value of property userList.
151      */

152     public String JavaDoc[] getUserList() {
153         String JavaDoc[] toReturn = new String JavaDoc[usersList.size()];
154         toReturn = (String JavaDoc[])usersList.keySet().toArray(toReturn);
155         return toReturn;
156     }
157     
158 }
159
Popular Tags