package accrue.analysis.interprocanalysis;

import polyglot.ast.Term;
import polyglot.visit.FlowGraph.PeerKey;

public class DataFlowNodeIdentifier_c extends NodeIdentifier_c implements
        DataFlowNodeIdentifier {
    protected final PeerKey peerKey;

    public DataFlowNodeIdentifier_c(AnalysisContext context, PeerKey peerKey,
            Term node) {
        super(context, node);
        this.peerKey = peerKey;
    }

    @Override
    public PeerKey getPeerKey() {
        return peerKey;
    }

    @Override
    protected int computeHashCode() {
        return super.computeHashCode() ^ peerKey.hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof DataFlowNodeIdentifier_c) {
            DataFlowNodeIdentifier_c that = (DataFlowNodeIdentifier_c) o;
            return super.equals(o)
                    && (this.peerKey == that.peerKey || this.peerKey.equals(that.peerKey));
        }
        return false;
    }

    @Override
    public String toString() {
        return getClass().getSimpleName() + "[" + node.toString() + ":"
                + hashCode() + "]";
    }
}
