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

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

import de.ivu.elect.business.wahlvorschlag.entity.ReferendumOption;

public class ReferendumOptionByPositionComparator implements Comparator<ReferendumOption>, Serializable {

  private static final long serialVersionUID = 1L;

  public ReferendumOptionByPositionComparator() {
    super();
  }

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

    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;
  }
}
