
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;
import de.ivu.elect.business.wahlvorschlagsperson.entity.WahlvorschlagsPersonPoolSearchResultEntry;

public class WahlvorschlagsPersonPoolSearchResultEntryByTemplateComparator implements Comparator<WahlvorschlagsPersonPoolSearchResultEntry>, Serializable {

  private static final long serialVersionUID = 1L;

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

  public WahlvorschlagsPersonPoolSearchResultEntryByTemplateComparator() {
    super();
  }

  @Override
  public int compare(WahlvorschlagsPersonPoolSearchResultEntry one, WahlvorschlagsPersonPoolSearchResultEntry another) {
    if (one != null && another != null) {
      return compare(one.getTemplate(), another.getTemplate());
    }

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

      return 1;
    }

    return -1;
  }

  private int compare(WahlvorschlagsPerson one, WahlvorschlagsPerson another) {
    return PERSONENDATEN_DEFAULT_COMPARATOR.compare(one, another);
  }
}
