package biduledres;

public class Arete implements SerialisableXML {
    private Sommet s1;
    private Sommet s2;
    
    public Arete(Sommet s1, Sommet s2) {
        this.s1 = s1;
        this.s2 = s2;
    }
    public SommetConstruit getMilieu() {
        return s1.getIsobarycentre(s2);
    }
    public Sommet getSommet1() {
        return s1;
    }
    public Sommet getSommet2() {
        return s2;
    }
    
    public boolean contains(Sommet s) {
        return s1.equals(s) || s2.equals(s);
    }
    
    public String toXML(int tab) {
        return Util.printTab(tab, "<Arete>") +
        s1.toXML(tab + 1) + s2.toXML(tab + 1) +
        Util.printTab(tab, "</Arete>");
    }
    
    public boolean equals(Object o) {
        if (o instanceof Arete) {
            Arete autreArete = (Arete) o;
            return  (getSommet1().equals(autreArete.getSommet1()) && getSommet2().equals(autreArete.getSommet2()))
            ||      (getSommet1().equals(autreArete.getSommet2()) && getSommet2().equals(autreArete.getSommet1()));
        } else return false;
    }
}