diff --git a/src/de/dhbwstuttgart/typinference/unify/model/MPair.java b/src/de/dhbwstuttgart/typinference/unify/model/MPair.java index 49e905af..abf6c2c7 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/MPair.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/MPair.java @@ -4,19 +4,50 @@ import de.dhbwstuttgart.typeinference.Pair.PairOperator; public class MPair { - public final MType TYPE_1; - public final MType TYPE_2; - public final PairOperator PAIR_OP; + private MType type1; + private MType type2; + private PairOperator pairOp; public MPair(MType t1, MType t2) { - TYPE_1 = t1; - TYPE_2 = t2; - PAIR_OP = PairOperator.SmallerExtends; + type1 = t1; + type2 = t2; + pairOp = PairOperator.Smaller; } - public MPair(MType t1, MType t2, PairOperator pairOp) { - TYPE_1 = t1; - TYPE_2 = t2; - PAIR_OP = pairOp; + public MPair(MType t1, MType t2, PairOperator op) { + type1 = t1; + type2 = t2; + 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(); + } } diff --git a/src/de/dhbwstuttgart/typinference/unify/model/MType.java b/src/de/dhbwstuttgart/typinference/unify/model/MType.java index 60c99dcf..35da6b1a 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/MType.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/MType.java @@ -98,7 +98,7 @@ public class MType implements Comparable{ @Override public int hashCode() { - return identifier + 31 * typeArgs.length; + return 17 + 31 * identifier + 31 * typeArgs.length; } @Override