package de.dhbwstuttgart.typeinference.result;

import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;

/**
 * Paare, welche das Unifikationsergebnis darstellen
 */
public abstract class ResultPair<A extends RefTypeOrTPHOrWildcardOrGeneric,B extends RefTypeOrTPHOrWildcardOrGeneric> {
    private final A left;
    private final B right;

    public abstract void accept(ResultPairVisitor visitor);

    public ResultPair(A left, B right){
        this.left = left;
        this.right = right;
    }

    public A getLeft() {
        return left;
    }

    public B getRight() {
        return right;
    }
    
    public String toString() {
    	return "(" + left.toString() + ", " + right.toString() + ")";
    }

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((left == null) ? 0 : left.getOffset().hashCode());
		result = prime * result + ((right == null) ? 0 : right.getOffset().hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ResultPair<?,?> other = (ResultPair<?,?>) obj;
		if (left == null) {
			if (other.left != null)
				return false;
		} else if (!left.getOffset().equals(other.left.getOffset()))
			return false;
		if (right == null) {
			if (other.right != null)
				return false;
		} else if (!right.getOffset().equals(other.right.getOffset()))
			return false;
		return true;
	}
   
}
