
public class Triple {

    Node a,b,c;
    int type;
    
    public Triple(Node a, Node b, Node c,int i){
	this.a = a;
	this.b = b;
	this.c = c;
	type = i;
    }

    public static boolean sameSpecies(Triple X,Triple Y){
	return ((X.a.getSpeciesNo() == Y.a.getSpeciesNo() 
		 || X.a.getSpeciesNo() == Y.b.getSpeciesNo() 
		 || X.a.getSpeciesNo() == Y.c.getSpeciesNo()) &&
		(X.b.getSpeciesNo() == Y.a.getSpeciesNo() 
		 || X.b.getSpeciesNo() == Y.b.getSpeciesNo() 
		 || X.b.getSpeciesNo() == Y.c.getSpeciesNo()) &&
		(X.c.getSpeciesNo() == Y.a.getSpeciesNo() 
		 || X.c.getSpeciesNo() == Y.b.getSpeciesNo() 
		 || X.c.getSpeciesNo() == Y.c.getSpeciesNo()));
    }

    public static boolean incompatibe(Triple X,Triple Y){
	return ((sameSpecies(X,Y) && X.type != Y.type) ||
		(sameSpecies(X,Y) && X.type == 1 && Y.type == 1 && X.c != Y.c));
    }

    public boolean equalFans(Triple Y){
	return sameSpecies(this,Y) && type == 2 && Y.type == 2;
    }

    public boolean equalTriples(Triple Y){
	return sameSpecies(this,Y) && c.getSpeciesNo() == Y.c.getSpeciesNo() && type == 1 && Y.type == 1;
    }

    public boolean isTriple(){return type == 1;}

    public boolean isFan(){return type == 2;}

    public String toString(){
	return a.getSpecies() + " " + b.getSpecies() + " " + c.getSpecies() + " " + type + " (" +
	    a.getSpeciesNo() + "," + b.getSpeciesNo() + "," + c.getSpeciesNo() + ")";
	    
    }
}
