public class Intervalle {

    private Chrono debut, fin;

    public Intervalle(Chrono d, Chrono f) {
        this.debut = d;
        if (d.avant(f)) {
            this.fin = f;
        } else {
            this.fin = d;
        }
    }

    public boolean conflit(Intervalle i) {
        return this.debut.avant(i.fin) == i.debut.avant(this.fin);
    }

    public Intervalle intersection(Intervalle i) {
        Chrono d = this.debut.avant(i.debut)?i.debut:this.debut;
        Chrono f = this.fin.avant(i.fin)?this.fin:i.fin;
        return new Intervalle(d, f);
    }

    public Intervalle union(Intervalle i) {
        Chrono d = this.debut.avant(i.debut)?this.debut:i.debut;
        Chrono f = this.fin.avant(i.fin)?i.fin:this.fin;
        return new Intervalle(d, f);
    }

    public boolean avant(Intervalle i) {
        return this.fin.avant(i.debut);
    }

    public String toString() {
        return "De " + this.debut.toString() + " à " + this.fin.toString() + ".\n";
    }

}
