Source Code Cross Referenced for BugSet.java in  » Code-Analyzer » findbugs » edu » umd » cs » findbugs » gui2 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » findbugs » edu.umd.cs.findbugs.gui2 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * FindBugs - Find Bugs in Java programs
003:         * Copyright (C) 2006, University of Maryland
004:         * 
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * Lesser General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307, USA
018:         */
019:
020:        package edu.umd.cs.findbugs.gui2;
021:
022:        import java.util.ArrayList;
023:        import java.util.Collection;
024:        import java.util.Collections;
025:        import java.util.Comparator;
026:        import java.util.HashMap;
027:        import java.util.Iterator;
028:        import java.util.List;
029:
030:        import edu.umd.cs.findbugs.BugCollection;
031:        import edu.umd.cs.findbugs.BugInstance;
032:        import edu.umd.cs.findbugs.BugPattern;
033:        import edu.umd.cs.findbugs.filter.Filter;
034:        import edu.umd.cs.findbugs.filter.Matcher;
035:        import edu.umd.cs.findbugs.gui2.BugAspects.SortableValue;
036:
037:        /**
038:         * BugSet is what we use instead of SortedBugCollections.  BugSet is somewhat poorly named, in that its actually a HashList of bugs, 
039:         * not a Set of them.  (It can't be a set because we need to be able to sort it, also, HashList is great for doing contains and indexOf, its just slow for removing which we never need to do)  The power of BugSet is in query.  You can query a BugSet with a BugAspects, a list of StringPairs like <priority,high>, <designation,unclassified>
040:         * and you will get out a new BugSet containing all of the bugs that are both high priority and unclassified.  Also, after the first time a query is made, the results will come back instantly on future calls
041:         * because the old queries are cached.  Note that this caching can also lead to issues, problems with the BugTreeModel and the JTree getting out of sync, if there comes a time when the model and tree are out of sync
042:         * but come back into sync if the tree is rebuilt, say by sorting the column headers, it probably means that resetData needs to be called on the model after doing one of its operations.  
043:         * 
044:         * @author Dan
045:         *
046:         */
047:        public class BugSet implements  Iterable<BugLeafNode> {
048:
049:            private HashList<BugLeafNode> mainList;
050:            private HashMap<SortableValue, BugSet> doneMap;
051:            private HashMap<SortableValue, Boolean> doneContainsMap;
052:            private HashMap<Sortables, HashList<String>> sortablesToStrings;
053:
054:            private static BugSet mainBugSet = null;
055:
056:            //	private ThreadMXBean bean = ManagementFactory.getThreadMXBean();
057:            /** mainBugSet should probably always be the same as the data field in the current BugTreeModel
058:             * we haven't run into any issues where it isn't, but if the two aren't equal using ==, problems might occur.
059:             * If these problems do occur, See BugTreeModel.resetData() and perhaps adding a setAsRootAndCache() to it would fix the issue.
060:             * This is not done right now for fear it might be slow.
061:             */
062:            public static BugSet getMainBugSet() {
063:                return mainBugSet;
064:            }
065:
066:            /**
067:             * Gets all the string values out of the bugs in the set
068:             * @param s The Sortables you want all values for
069:             * @return all values of the sortable passed in that occur in this bugset, in order based on the sortable's compare method.
070:             */
071:            public String[] getAll(Sortables s) {
072:                HashList<String> list = sortablesToStrings.get(s);
073:                Collections.sort(list, new SortableStringComparator(s));
074:                return list.toArray(new String[list.size()]);
075:            }
076:
077:            /**
078:             * Creates a filterable dataset from the set passed in.  The first time this is used is from outside to create the main data list
079:             * After that BugSet will create new smaller filtered sets and store them using this method.
080:             * @param filteredSet
081:             */
082:            BugSet(Collection<? extends BugLeafNode> filteredSet) {
083:                this .mainList = new HashList<BugLeafNode>(filteredSet);
084:                doneMap = new HashMap<SortableValue, BugSet>();
085:                doneContainsMap = new HashMap<SortableValue, Boolean>();
086:                cacheSortables();
087:            }
088:
089:            BugSet(BugCollection bugCollection) {
090:                this (Collections.EMPTY_LIST);
091:                for (Iterator<BugInstance> i = bugCollection.iterator(); i
092:                        .hasNext();)
093:                    mainList.add(new BugLeafNode(i.next()));
094:
095:            }
096:
097:            /**
098:             * Sets the BugSet passed in to be the mainBugSet, this should always match up with the data set in the BugTreeModel
099:             * @param bs
100:             */
101:            static void setAsRootAndCache(BugSet bs) {
102:                mainBugSet = bs;
103:                bs.sortList();
104:                bs.cacheSortables();
105:            }
106:
107:            /**
108:             * we cache all values of each sortable that appear in the BugSet as we create it using cacheSortables, this makes it
109:             * possible to only show branches that actually have bugs in them, and makes it faster by caching the results.
110:             */
111:            void cacheSortables() {
112:                sortablesToStrings = new HashMap<Sortables, HashList<String>>();
113:                for (Sortables key : Sortables.values())
114:                    if (key != Sortables.DIVIDER) {
115:                        HashList<String> list = new HashList<String>();
116:                        sortablesToStrings.put(key, list);
117:                    }
118:
119:                ArrayList<BugLeafNode> bugNodes = new ArrayList<BugLeafNode>();
120:                Filter suppressionFilter = ProjectSettings.getInstance()
121:                        .getSuppressionFilter();
122:
123:                for (BugLeafNode p : mainList) {
124:                    if (!suppressionFilter.match(p.getBug()))
125:                        bugNodes.add(p);
126:                }
127:
128:                for (BugLeafNode b : bugNodes) {
129:                    BugInstance bug = b.getBug();
130:                    BugPattern bugP = bug.getBugPattern();
131:
132:                    if (bugP == null) {
133:                        assert false;
134:                        if (MainFrame.DEBUG)
135:                            System.err
136:                                    .println("A bug pattern was not found for "
137:                                            + bug.getMessage());
138:                        continue;
139:                    }
140:
141:                    for (Sortables key : Sortables.values())
142:                        if (key != Sortables.DIVIDER) {
143:                            HashList<String> list = sortablesToStrings.get(key);
144:
145:                            String value = key.getFrom(bug);
146:                            if (!list.contains(value))
147:                                list.add(value);
148:                            sortablesToStrings.put(key, list);
149:                        }
150:                }
151:
152:                for (Sortables key : Sortables.values())
153:                    if (key != Sortables.DIVIDER)
154:                        Collections.sort(sortablesToStrings.get(key));
155:            }
156:
157:            /** used to update the status bar in mainframe with the number of bugs that are filtered out */
158:            static int countFilteredBugs() {
159:                Filter cm = ProjectSettings.getInstance()
160:                        .getSuppressionFilter();
161:                int result = 0;
162:                for (BugLeafNode bug : mainBugSet.mainList)
163:                    if (cm.match(bug.getBug()))
164:                        result++;
165:
166:                return result;
167:            }
168:
169:            /**
170:             * Copy constructor, also used to make sure things are recalculated
171:             * @param copySet
172:             */
173:            //Note: THIS CLEARS THE CACHES OF DONE SETS!
174:            BugSet(BugSet copySet) {
175:                this .mainList = copySet.mainList;
176:                doneMap = new HashMap<SortableValue, BugSet>();
177:                doneContainsMap = new HashMap<SortableValue, Boolean>();
178:                cacheSortables();
179:            }
180:
181:            /**
182:             * A String pair has a key and a value.  The key is the general category ie: Type
183:             * The value is the value  ie: Malicious Code.  
184:             * 
185:             * Query looks through a BugLeafNode set with a keyValuePair to see which BugLeafNodes inside
186:             * match the value under the category of key.  
187:             * 
188:             * passing in a key of Abbrev and a value of MS should return a new BugSet with all the Mutable Static bugs in the current set
189:             * Note also:  This query will only be performed once, and then stored and reused if the same query is used again.  
190:             * @param keyValuePair
191:             * @return
192:             */
193:            BugSet query(SortableValue keyValuePair) {
194:                if (doneMap.containsKey(keyValuePair))
195:                    return doneMap.get(keyValuePair);
196:                ArrayList<BugLeafNode> bugs = new ArrayList<BugLeafNode>();
197:
198:                for (BugLeafNode b : mainList) {
199:                    if (b.matches(keyValuePair))
200:                        bugs.add(b);
201:                }
202:
203:                BugSet temp = new BugSet(bugs);
204:                doneMap.put(keyValuePair, temp);
205:                return temp;
206:            }
207:
208:            /* Sort the contents of the list by the Sortables in the order after the divider, if any. */
209:            void sortList() {
210:                // Go backward through the sort order, sorting the entire list: that achieves the correct order
211:                // But it takes waaaay too long.
212:                final List<Sortables> order = MainFrame.getInstance()
213:                        .getSorter().getOrderAfterDivider();
214:                //		for (int i = order.size() - 1; i >= 0; i--)
215:                //			Collections.sort(mainList, order.get(i).getBugLeafNodeComparator());
216:
217:                Collections.sort(mainList, new Comparator<BugLeafNode>() {
218:                    public int compare(BugLeafNode one, BugLeafNode two) {
219:                        for (Sortables i : order) {
220:                            int result = i.getBugLeafNodeComparator().compare(
221:                                    one, two);
222:                            if (result != 0)
223:                                return result;
224:                        }
225:                        // If still here, they're really equal
226:                        return 0;
227:                    }
228:                });
229:            }
230:
231:            /**
232:             * 
233:             * Contains takes a key/value pair
234:             * 
235:             * @param keyValuePair
236:             * @return true if a bug leaf from filterNoCache() matches the pair
237:             */
238:            public boolean contains(SortableValue keyValuePair) {
239:                if (doneContainsMap.containsKey(keyValuePair))
240:                    return doneContainsMap.get(keyValuePair);
241:
242:                for (BugLeafNode p : filterNoCache().mainList) {
243:                    if (p.matches(keyValuePair)) {
244:                        doneContainsMap.put(keyValuePair, true);
245:                        return true;
246:                    }
247:                }
248:                doneContainsMap.put(keyValuePair, false);
249:                return false;
250:            }
251:
252:            /**
253:             *Gives you back the BugSet containing all bugs that match your query
254:             */
255:            public BugSet query(BugAspects a) {
256:                BugSet result = this ;
257:                for (SortableValue sp : a) {
258:                    result = result.query(sp);
259:                }
260:
261:                return result;
262:            }
263:
264:            public int sizeUnfiltered() {
265:                return mainList.size();
266:            }
267:
268:            /*	
269:             public Iterator<BugLeafNode> iterator() {
270:             return mainList.iterator();
271:             }
272:             */
273:            public int indexOfUnfiltered(BugLeafNode p) {
274:                return mainList.indexOf(p);
275:            }
276:
277:            public BugLeafNode getUnfiltered(int index) {
278:                return mainList.get(index);
279:            }
280:
281:            public Iterator<BugLeafNode> iterator() {
282:                return mainList.iterator();
283:            }
284:
285:            ////////Filtered API
286:
287:            BugSet(ArrayList<BugLeafNode> filteredSet, boolean cacheSortables) {
288:                this .mainList = new HashList<BugLeafNode>(filteredSet);
289:                doneMap = new HashMap<SortableValue, BugSet>();
290:                doneContainsMap = new HashMap<SortableValue, Boolean>();
291:                if (cacheSortables)
292:                    cacheSortables();
293:            }
294:
295:            public BugSet filterNoCache() {
296:
297:                Matcher m = ProjectSettings.getInstance()
298:                        .getSuppressionFilter();
299:                ArrayList<BugLeafNode> people = new ArrayList<BugLeafNode>();
300:                for (BugLeafNode p : mainList) {
301:                    if (!m.match(p.getBug()))
302:                        people.add(p);
303:                }
304:                return new BugSet(people, false);
305:            }
306:
307:            public BugSet getBugsMatchingFilter(Matcher m) {
308:                ArrayList<BugLeafNode> people = new ArrayList<BugLeafNode>();
309:                for (BugLeafNode p : mainList) {
310:                    if (!(m.match(p.getBug())))
311:                        people.add(p);
312:                }
313:                return new BugSet(people, false);
314:            }
315:
316:            public int size() {
317:                return filterNoCache().sizeUnfiltered();
318:            }
319:
320:            public int indexOf(BugLeafNode p) {
321:                return filterNoCache().indexOfUnfiltered(p);
322:            }
323:
324:            public BugLeafNode get(int index) {
325:                return filterNoCache().getUnfiltered(index);
326:            }
327:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.