
package de.ivu.elect.business.gebietsbaum.control;

import java.io.Serializable;
import java.util.Comparator;

import de.ivu.elect.business.gebietsbaum.entity.EntityMitGebiet;
import de.ivu.elect.business.gebietsbaum.entity.Gebiet;

public class EntityMitGebietByBreadthFirstComparator implements Comparator<EntityMitGebiet>, Serializable {

  public static final EntityMitGebietByBreadthFirstComparator INSTANCE = new EntityMitGebietByBreadthFirstComparator();

  private static final long serialVersionUID = -1L;

  @Override
  public int compare(EntityMitGebiet o1, EntityMitGebiet o2) {
    if (o1 == null && o2 == null) {
      return 0;
    }
    if (o1 == null) {
      return 1;
    }
    if (o2 == null) {
      return -1;
    }

    Gebiet gebiet1 = o1.getGebiet();
    Gebiet gebiet2 = o2.getGebiet();

    if (gebiet1 == null && gebiet2 == null) {
      return 0;
    }

    if (gebiet1 == null) {
      return 1;
    }
    if (gebiet2 == null) {
      return -1;
    }

    return GebietByBreadthFirstComparator.INSTANCE.compare(gebiet1, gebiet2);
  }
}
