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

import java.util.Comparator;

import de.ivu.elect.business.gebietsbaum.control.GebietByNummerComparator;
import de.ivu.elect.util.NullComparator;

public class WahlverwaltungGebietInformationByNummerComparator implements Comparator<WahlverwaltungGebietInformation> {

  private static final Comparator<Object> NULL_COMPARATOR = NullComparator.NULL_BEFORE_NON_NULL_COMPARATOR;

  public WahlverwaltungGebietInformationByNummerComparator() {
    super();
  }

  @Override
  public int compare(WahlverwaltungGebietInformation one, WahlverwaltungGebietInformation another) {
    if (one == null || another == null) {
      return NULL_COMPARATOR.compare(one, another);
    }

    int comparedByNummer = GebietByNummerComparator.compareNummer(one.getNummer(), another.getNummer());

    if (comparedByNummer == 0) {
      return one.getArtIndex() - another.getArtIndex(); // ELECT-8091
    }

    return comparedByNummer;
  }
}
