Commit 0b894104 authored by Salomon Sickert-Zehnter's avatar Salomon Sickert-Zehnter

Merge branch 'equals-sanity' into 'master'

Add sanity check to equals of ValuationSet and EquivalenceClass

See merge request i7/owl!362
parents b881ca07 f0a486d1
......@@ -325,9 +325,10 @@ final class EquivalenceFactory extends GcManagedFactory<BddEquivalenceClass>
}
/**
* This class does not override `equals` and `hashCode`, since GcManagedFactory ensures
* This class does not implement a proper `equals` and `hashCode`, since GcManagedFactory ensures
* uniqueness.
*/
@SuppressWarnings("PMD.OverrideBothEqualsAndHashcode") // We only have a "bogus" assert equals
static final class BddEquivalenceClass implements BddNode, EquivalenceClass {
private final EquivalenceFactory factory;
private final int node;
......@@ -541,5 +542,13 @@ final class EquivalenceFactory extends GcManagedFactory<BddEquivalenceClass>
return truenessCache;
}
@Override
public boolean equals(Object obj) {
// Check that we are not comparing classes of different factories
assert !(obj instanceof EquivalenceClass) || ((EquivalenceClass) obj).factory() == factory();
return this == obj;
}
}
}
......@@ -357,9 +357,10 @@ final class ValuationFactory extends GcManagedFactory<BddValuationSet>
}
/**
* This class does not override `equals` and `hashCode`, since GcManagedFactory ensures
* This class does not implement a proper `equals` and `hashCode`, since GcManagedFactory ensures
* uniqueness.
*/
@SuppressWarnings("PMD.OverrideBothEqualsAndHashcode") // We only have a "bogus" assert equals
static final class BddValuationSet extends ValuationSet implements BddNode {
private final ValuationFactory factory;
private final int node;
......@@ -418,5 +419,13 @@ final class ValuationFactory extends GcManagedFactory<BddValuationSet>
public BigInteger size() {
return factory.bdd.countSatisfyingAssignments(node);
}
@Override
public boolean equals(Object obj) {
// Check that we are not comparing classes of different factories
assert !(obj instanceof ValuationSet) || ((ValuationSet) obj).factory() == factory();
return this == obj;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment