package com.aegir.demo.model;

import java.util.Comparator;

public class BaseFloorItemComparator implements Comparator<BaseFloorItem> {

    @Override
    public int compare(BaseFloorItem t0, BaseFloorItem t1) {
        //both buildings
        if (t0.isBuilding() && t1.isBuilding()) {
            return t0.getNumber().compareTo(t1.getNumber());
        }
        //both floors
        else if (!t0.isBuilding() && !t1.isBuilding()) {
            FloorItem f0 = (FloorItem) t0;
            FloorItem f1 = (FloorItem) t1;
            if (f0.getBuildingNumber() == f1.getBuildingNumber()) {
                return f0.getNumber().compareTo(f1.getNumber());
            } else {
                return f0.getBuildingNumber().compareTo(f1.getBuildingNumber());
            }
        } else if (t0.isBuilding() && !t1.isBuilding()) {
            FloorItem f1 = (FloorItem) t1;
            return t0.getNumber().compareTo(f1.getBuildingNumber());
        } else if (!t0.isBuilding() && t1.isBuilding()) {
            FloorItem f0 = (FloorItem) t0;
            return f0.getBuildingNumber().compareTo(t1.getNumber());
        }
        return 0;
    }

}
