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

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

import de.ivu.elect.business.kandidatur.entity.Listenkandidatur;
import de.ivu.elect.business.stimmzettel.entity.AbstractEntityAufStimmzettelStimmzettelPosition;

public final class ListenkandidaturByRelativePositionComparator implements Comparator<Listenkandidatur>, Serializable {

  private static final long serialVersionUID = 1L;

  public ListenkandidaturByRelativePositionComparator() {
    super();
  }

  @Override
  public int compare(Listenkandidatur one, Listenkandidatur another) {
    if (one == null) {
      if (another == null) {
        return 0;
      }
      return 1;
    }

    if (another == null) {
      return -1;
    }

    return compareByPosition(one.getRelativePosition(), another.getRelativePosition());
  }

  private int compareByPosition(Long one, Long another) {
    return AbstractEntityAufStimmzettelStimmzettelPosition.DEFAULT_POSITION_COMPARATOR.compare(one, another);
  }
}
