hashcodes and work on Mpair

This commit is contained in:
Florian Steurer 2015-10-24 19:05:48 +02:00
parent 3d38ea2e08
commit 4539faf241
2 changed files with 42 additions and 11 deletions

View File

@ -4,19 +4,50 @@ import de.dhbwstuttgart.typeinference.Pair.PairOperator;
public class MPair { public class MPair {
public final MType TYPE_1; private MType type1;
public final MType TYPE_2; private MType type2;
public final PairOperator PAIR_OP; private PairOperator pairOp;
public MPair(MType t1, MType t2) { public MPair(MType t1, MType t2) {
TYPE_1 = t1; type1 = t1;
TYPE_2 = t2; type2 = t2;
PAIR_OP = PairOperator.SmallerExtends; pairOp = PairOperator.Smaller;
} }
public MPair(MType t1, MType t2, PairOperator pairOp) { public MPair(MType t1, MType t2, PairOperator op) {
TYPE_1 = t1; type1 = t1;
TYPE_2 = t2; type2 = t2;
PAIR_OP = pairOp; pairOp = op;
}
public MType GetType1() {
return type1;
}
public MType GetType2() {
return type2;
}
public PairOperator GetPairOp() {
return pairOp;
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof MPair))
return false;
if(obj.hashCode() != hashCode())
return false;
MPair other = (MPair) obj;
return other.GetPairOp() == pairOp
&& other.GetType1().equals(type1)
&& other.GetType2().equals(type2);
}
@Override
public int hashCode() {
return 17 + 31 * type1.hashCode() + 31 * type2.hashCode() + 31 * pairOp.hashCode();
} }
} }

View File

@ -98,7 +98,7 @@ public class MType implements Comparable<MType>{
@Override @Override
public int hashCode() { public int hashCode() {
return identifier + 31 * typeArgs.length; return 17 + 31 * identifier + 31 * typeArgs.length;
} }
@Override @Override