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

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

import de.ivu.elect.business.person.control.EntityMitPersonendatenByNamenComparator;
import de.ivu.elect.business.wahlvorschlagsperson.entity.WahlvorschlagsPerson;

public class WahlvorschlagsPersonByEingangssequenznummerComparator implements Comparator<WahlvorschlagsPerson>, Serializable {

  private static final long serialVersionUID = 1L;

  private static final Comparator<WahlvorschlagsPerson> PERSONENDATEN_DEFAULT_COMPARATOR = new EntityMitPersonendatenByNamenComparator<>();

  public WahlvorschlagsPersonByEingangssequenznummerComparator() {
    super();
  }

  @Override
  public int compare(WahlvorschlagsPerson one, WahlvorschlagsPerson another) {
    if (one != null && another != null) {
      int result = compare(one.getEingangssequenznummer(), another.getEingangssequenznummer());

      if (result == 0) {
        result = PERSONENDATEN_DEFAULT_COMPARATOR.compare(one, another);
      }

      return result;
    }

    if (one == null) {
      if (another == null) {
        return 0;
      }

      return -1;
    }

    return 1;
  }

  private int compare(Long one, Long another) {
    if (one != null && another != null) {
      return one.compareTo(another);
    }

    if (one == null) {
      if (another == null) {
        return 0;
      }

      return 1;
    }

    return -1;
  }
}
