KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > npe > WillBeDereferencedInfo


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.npe;
21
22 import java.util.HashSet JavaDoc;
23 import java.util.Set JavaDoc;
24
25 import edu.umd.cs.findbugs.ba.vna.ValueNumber;
26
27 public class WillBeDereferencedInfo {
28         
29         Set JavaDoc<ValueNumber> value = new HashSet JavaDoc<ValueNumber>();
30         boolean isTop;
31
32         public static WillBeDereferencedInfo getTop() {
33             WillBeDereferencedInfo top = new WillBeDereferencedInfo();
34             top.isTop = true;
35             return top;
36         }
37         
38         public WillBeDereferencedInfo copy() {
39             WillBeDereferencedInfo w = new WillBeDereferencedInfo();
40             w.copyFrom(this);
41             return w;
42         }
43         
44         public void copyFrom (WillBeDereferencedInfo w) {
45             this.isTop = w.isTop;
46             this.value.clear();
47             this.value.addAll(w.value);
48         }
49         public void meet(WillBeDereferencedInfo source) {
50             if (source.isTop) return;
51             if (isTop) {
52                 isTop = false;
53                 value.clear();
54                 value.addAll(source.value);
55                 return;
56             }
57             value.retainAll(source.value);
58         }
59         
60         @Override JavaDoc
61                  public int hashCode() {
62             if (isTop) return 42;
63             return value.hashCode();
64         }
65         @Override JavaDoc
66                  public boolean equals(Object JavaDoc o) {
67             if (o == null || o.getClass() != WillBeDereferencedInfo.class) return false;
68             WillBeDereferencedInfo w = (WillBeDereferencedInfo) o;
69             if (isTop != w.isTop) return false;
70             return value.equals(w.value);
71         }
72         
73         
74
75     }
76
Popular Tags