KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > heap > FieldSet


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2005, 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.ba.heap;
21
22 import java.util.HashSet JavaDoc;
23 import java.util.Set JavaDoc;
24
25 import edu.umd.cs.findbugs.ba.XField;
26
27 /**
28  * @author David Hovemeyer
29  */

30 public class FieldSet {
31     private boolean isTop, isBottom;
32     private Set JavaDoc<XField> fieldSet;
33     
34     public FieldSet() {
35         fieldSet = new HashSet JavaDoc<XField>();
36     }
37     
38     public void setTop() {
39         clear();
40         isTop = true;
41     }
42     
43     public boolean isTop() {
44         return isTop;
45     }
46     
47     public void setBottom() {
48         clear();
49         isBottom = true;
50     }
51     
52     public boolean isBottom() {
53         return isBottom;
54     }
55     
56     public boolean isValid() {
57         return !isTop && !isBottom;
58     }
59     
60     public boolean isEmpty() {
61         return !isTop && !isBottom && fieldSet.isEmpty();
62     }
63     
64     public void clear() {
65         isTop = isBottom = false;
66         fieldSet.clear();
67     }
68     
69     public void addField(XField field) {
70         if (!isValid())
71             throw new IllegalStateException JavaDoc();
72         fieldSet.add(field);
73     }
74     
75     public boolean contains(XField field) {
76         return fieldSet.contains(field);
77     }
78     
79     public void mergeWith(FieldSet other) {
80         if (other.isTop() || this.isBottom())
81             return;
82         
83         if (other.isBottom() || this.isTop()) {
84             this.copyFrom(other);
85             return;
86         }
87         
88         fieldSet.addAll(other.fieldSet);
89     }
90     
91     public boolean sameAs(FieldSet other) {
92         return this.isTop == other.isTop
93             && this.isBottom == other.isBottom
94             && this.fieldSet.equals(other.fieldSet);
95     }
96     
97     public void copyFrom(FieldSet other) {
98         this.isTop = other.isTop;
99         this.isBottom = other.isBottom;
100         this.fieldSet.clear();
101         this.fieldSet.addAll(other.fieldSet);
102     }
103     
104     public boolean isIntersectionNonEmpty(FieldSet other) {
105         for (XField field : fieldSet) {
106             if (other.fieldSet.contains(field))
107                 return true;
108         }
109         return false;
110     }
111     
112     @Override JavaDoc
113          public String JavaDoc toString() {
114         if (isTop)
115             return "TOP";
116         else if (isBottom)
117             return "BOTTOM";
118         else
119             return fieldSet.toString();
120     }
121 }
122
Popular Tags