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

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

import de.ivu.elect.business.ergebnis.entity.Gewaehlt;
import de.ivu.elect.business.kandidatur.entity.Kandidatur;
import de.ivu.elect.business.person.control.EntityMitPersonendatenByNamenComparator;

public class GewaehltByIsGewaehltAndRangComparator implements Comparator<Gewaehlt>, Serializable {

  private static final long serialVersionUID = 1L;

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

  public GewaehltByIsGewaehltAndRangComparator() {
    super();
  }

  @Override
  public int compare(Gewaehlt one, Gewaehlt another) {
    int result = one.getGewaehltStatus().compareTo(another.getGewaehltStatus());

    if (result == 0) {
      result = one.getRang().compareTo(another.getRang());

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

    return result;
  }
}
