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

import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;

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

import de.ivu.elect.business.unterstuetzer.entity.Eintragungsliste;

public class EintragungslisteByNummerComparator implements Serializable, Comparator<Eintragungsliste> {

  private static final long serialVersionUID = 1L;

  public EintragungslisteByNummerComparator() {
    super();
  }

  @Override
  public int compare(Eintragungsliste one, Eintragungsliste another) {
    if (nonNull(one) && nonNull(another)) {
      return compare(one.getNummer(), another.getNummer());
    }

    if (isNull(one)) {
      if (isNull(another)) {
        return 0;
      }

      return -1;
    }

    return 1;
  }

  private int compare(Long one, Long another) {
    if (nonNull(one) && nonNull(another)) {
      return one.compareTo(another);
    }

    if (isNull(one)) {
      if (isNull(another)) {
        return 0;
      }

      return 1;
    }

    return -1;
  }
}
