01: /*
02: * FindBugs - Find Bugs in Java programs
03: * Copyright (C) 2006, University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
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 edu.umd.cs.findbugs.ba.Location;
23: import edu.umd.cs.findbugs.ba.vna.ValueNumber;
24:
25: /**
26: * A Location where a particular value number becomes null.
27: *
28: * @author David Hovemeyer
29: */
30: public class LocationWhereValueBecomesNull implements
31: Comparable<LocationWhereValueBecomesNull> {
32: private Location location;
33: private ValueNumber valueNumber;
34:
35: /**
36: * Constructor.
37: *
38: * @param location the Location where a value becomes null
39: * @param valueNumber the value number
40: */
41: public LocationWhereValueBecomesNull(Location location,
42: ValueNumber valueNumber) {
43: this .location = location;
44: this .valueNumber = valueNumber;
45: }
46:
47: /**
48: * @return Returns the location.
49: */
50: public Location getLocation() {
51: return location;
52: }
53:
54: /**
55: * @return Returns the valueNumber.
56: */
57: public ValueNumber getValueNumber() {
58: return valueNumber;
59: }
60:
61: /* (non-Javadoc)
62: * @see java.lang.Comparable#compareTo(java.lang.Object)
63: */
64: public int compareTo(LocationWhereValueBecomesNull o) {
65: int cmp = this .location.compareTo(o.location);
66: if (cmp != 0) {
67: return cmp;
68: }
69: cmp = this .valueNumber.compareTo(o.valueNumber);
70: return cmp;
71: }
72:
73: /* (non-Javadoc)
74: * @see java.lang.Object#equals(java.lang.Object)
75: */
76: @Override
77: public boolean equals(Object obj) {
78: if (obj == null || obj.getClass() != this .getClass()) {
79: return false;
80: }
81: LocationWhereValueBecomesNull other = (LocationWhereValueBecomesNull) obj;
82: return this .location.equals(other.location)
83: && this .valueNumber.equals(other.valueNumber);
84: }
85:
86: /* (non-Javadoc)
87: * @see java.lang.Object#hashCode()
88: */
89: @Override
90: public int hashCode() {
91: return location.hashCode() * 6563 + valueNumber.hashCode();
92: }
93:
94: @Override
95: public String toString() {
96: return valueNumber + " becomes null at "
97: + location.getHandle().getPosition() + ":" + location;
98: }
99: }
|