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

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

import de.ivu.elect.business.unterstuetzer.entity.EintragungslisteEintrag;
import de.ivu.elect.util.NullComparator;

public class EintragungslisteEintragByPositionComparator implements Serializable, Comparator<EintragungslisteEintrag> {

  private static final long serialVersionUID = 1L;

  public static final Comparator<EintragungslisteEintrag> ASCENDING = new EintragungslisteEintragByPositionComparator();

  public static final Comparator<EintragungslisteEintrag> DESCENDING = Collections.reverseOrder(ASCENDING);

  public EintragungslisteEintragByPositionComparator() {
    super();
  }

  @Override
  public int compare(EintragungslisteEintrag one, EintragungslisteEintrag another) {
    if (one == null || another == null) {
      return NullComparator.NULL_BEFORE_NON_NULL_COMPARATOR.compare(one, another);
    }

    return compare(one.getPosition(), another.getPosition());
  }

  private int compare(Long one, Long another) {
    if (one == null || another == null) {
      return NullComparator.NON_NULL_BEFORE_NULL_COMPARATOR.compare(one, another);
    }

    return one.compareTo(another);
  }
}
