Check object type in equals

This commit is contained in:
Sam Harwell 2012-07-18 14:23:46 -05:00
parent 8b4a461262
commit 3a35f3cb08
5 changed files with 23 additions and 9 deletions

View File

@ -190,6 +190,11 @@ public class DFAState {
public boolean equals(Object o) {
// compare set of ATN configurations in this set with other
if ( this==o ) return true;
if (!(o instanceof DFAState)) {
return false;
}
DFAState other = (DFAState)o;
// TODO (sam): what to do when configs==null?
boolean sameSet = this.configset.equals(other.configset);

View File

@ -94,6 +94,10 @@ public class OrderedHashSet<T> extends LinkedHashSet<T> {
@Override
public boolean equals(Object o) {
if (!(o instanceof OrderedHashSet<?>)) {
return false;
}
// System.out.print("equals " + this + ", " + o+" = ");
boolean same = elements!=null && elements.equals(((OrderedHashSet<?>)o).elements);
// System.out.println(same);

View File

@ -75,10 +75,8 @@ public class AltLabelStructDecl extends StructDecl {
@Override
public boolean equals(Object obj) {
if ( obj == this ) return true;
if ( obj.hashCode() != this.hashCode() ) return false;
if ( obj instanceof AltLabelStructDecl ) {
return name.equals(((AltLabelStructDecl)obj).name);
}
return false;
if (!(obj instanceof AltLabelStructDecl)) return false;
return name.equals(((AltLabelStructDecl)obj).name);
}
}

View File

@ -57,11 +57,10 @@ public class Decl extends SrcOp {
/** If same name, can't redefine, unless it's a getter */
@Override
public boolean equals(Object obj) {
if ( obj==null ) return false;
if ( this==obj ) return true;
if ( !(obj instanceof Decl) ) return false;
// A() and label A are different
if ( obj instanceof ContextGetterDecl ) return false;
if ( this==obj ) return true;
if ( this.hashCode() != obj.hashCode() ) return false;
return name.equals(((Decl) obj).name);
}
}

View File

@ -332,7 +332,15 @@ public class Rule implements AttributeResolver {
@Override
public boolean equals(Object obj) {
return this==obj || name.equals(((Rule)obj).name);
if (this == obj) {
return true;
}
if (!(obj instanceof Rule)) {
return false;
}
return name.equals(((Rule)obj).name);
}
@Override