KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > gui2 > BugAspects


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307, USA
18  */

19
20 package edu.umd.cs.findbugs.gui2;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 /**
26  * These are the branches in our tree, each branch forms a complete query that could be sent to the main bugset to return all the bugs it contains
27  * For example, a single bugAspects could be <priority,high> or it could be <priority,high>,<designation,must fix>,<class,fishpond>,<package,default>
28  *
29  * In this implementation, <priority,high>,<designation,unclassified> is different from <designation,unclassified>,<priority,high>. (I'm not talking about the fact we use the .equals from ArrayList, I'm talking about what a query would return, though both are true)
30  * For a speed boost, this class could be rewritten to make these equal, BugSet could be rewritten to cache full queries off the main BugSet, (instead of caching each part of the query separately in the BugSets created)
31  * and resetData could be rewritten to work more like Swing's validate, only clearing data if the data is wrong. This would save time after changing certain aspects of the tree.
32  * Just an idea, I wouldn't suggest it unless its absolutely necessary. -Dan
33  *
34  *
35  * @author All of us
36  */

37 public class BugAspects implements Iterable JavaDoc<BugAspects.StringPair>
38 {
39     private static final long serialVersionUID = -5503915081879996968L;
40     private int count=-1;
41     private ArrayList JavaDoc<BugAspects.StringPair> lst = new ArrayList JavaDoc<BugAspects.StringPair>();
42     
43     public StringPair last() {
44         return lst.get(lst.size() - 1);
45     }
46     public int size() {
47         return lst.size();
48     }
49     public String JavaDoc toString()
50     {
51         if (lst.isEmpty())
52             return edu.umd.cs.findbugs.L10N.getLocalString("tree.bugs", "Bugs") + " (" + count + ")";
53         else
54         {
55             if (count==-1)
56                 return last().value;
57             else
58                 return last().key.formatValue(last().value) + " (" + count + ")";
59         }
60     }
61     
62     /**
63      * This is how the numbers after the branches contain the number of bugs in them, even if they aren't the final branch
64      * @param count
65      */

66     public void setCount(int count)
67     {
68         this.count=count;
69     }
70     
71     public int getCount()
72     {
73         return count;
74     }
75     
76     public BugAspects()
77     {
78         super();
79     }
80     
81     public BugAspects(BugAspects a)
82     {
83         lst = new ArrayList JavaDoc<StringPair>(a.lst);
84         count = a.count;
85     }
86     
87     public void add(StringPair sp) {
88         lst.add(sp);
89     }
90     public BugAspects addToNew(StringPair sp)
91     {
92         BugAspects result = new BugAspects(this);
93         result.lst.add(sp);
94         return result;
95     }
96     public StackedFilterMatcher getStackedFilterMatcher(){
97         FilterMatcher[] filters = new FilterMatcher[lst.size()];
98         for (int i = 0; i < filters.length; i++)
99             filters[i] = new FilterMatcher(lst.get(i));
100         StackedFilterMatcher sfm = new StackedFilterMatcher(filters);
101         return sfm;
102     }
103          
104     public BugSet getMatchingBugs(BugSet theSet)
105     {
106         return theSet.getBugsMatchingFilter(this.getStackedFilterMatcher());
107     }
108     static class StringPair
109     {
110         final public Sortables key;
111         final public String JavaDoc value;
112         
113         public StringPair(Sortables key, String JavaDoc value)
114         {
115             this.key = key;
116             this.value = value;
117         }
118         
119         public int hashCode()
120         {
121             return key.hashCode() + value.hashCode();
122         }
123         
124         public boolean equals(Object JavaDoc that)
125         {
126             if (!(that instanceof StringPair))
127                 return false;
128             StringPair thatStringPair = ((StringPair)that);
129             return this.key.equals(thatStringPair.key) && this.value.equals(thatStringPair.value);
130         }
131         
132         public String JavaDoc toString()
133         {
134             return key +":"+ value;
135         }
136     }
137
138     public Iterator JavaDoc<StringPair> iterator() {
139         return lst.iterator();
140     }
141 }
142
Popular Tags