+
+ // Note that this is a heuristic, "fuzzy", equals.
+ // Two BugInstances will be considered equal if:
+ // - they refer to the same bug type
+ // - they took place in the same class and method
+ // - the variable names referred to (if any) match
+ // In particular, this equality test does not check
+ // for line numbers being equal. This is by design;
+ // we want to consider two bugs to be the "same bug"
+ // even if other changes in the file have shifted
+ // line numbers a bit.
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (null == obj) {
+ return false;
+ }
+ if (obj instanceof BugInstance) {
+ BugInstance that = (BugInstance)obj;
+
+ if (! Util.objsAreEqual(this.m_type, that.m_type)) {
+ return false;
+ }
+
+ if (! Util.objsAreEqual(this.m_category, that.m_category)) {
+ return false;
+ }
+
+ BugMethod thisMethod = this.getPrincipalMethod();
+ BugMethod thatMethod = that.getPrincipalMethod();
+ if (null == thisMethod) {
+ if (null == thatMethod) {
+ return false;
+ }
+ }
+ else {
+ if (! Util.objsAreEqual(thisMethod.getClassName(), thatMethod.getClassName())) {
+ return false;
+ }
+ if (! Util.objsAreEqual(thisMethod.getMethodName(), thatMethod.getMethodName())) {
+ return false;
+ }
+ }
+
+ if (! Util.objsAreEqual(this.getVariables(), that.getVariables())) {
+ return false;
+ }
+
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int code = Util.objHashCode(m_type)
+ * Util.objHashCode(m_category)
+ * Util.objHashCode(getPrincipalMethod())
+ * Util.objHashCode(getVariables());
+ return code;
+ }
+
+ // Get the "principal" method.
+ // This should be the place where the bug is reported.
+ BugMethod getPrincipalMethod()
+ {
+ List<BugMethod> bugMethods = getMethods();
+ if ((null == bugMethods) || (0 == bugMethods.size())) {
+ return null;
+ }
+ return bugMethods.get(0);
+ }