
package de.ivu.elect.business.geodata.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.geodata.entity.GeodataPlz;

public class GeodataPlzByPlzComparator implements Comparator<GeodataPlz>, Serializable {

  private static final long serialVersionUID = 1L;

  // Naja, 5-stellig numerisch, ohne Buchstaben... mal schauen.
  private static final Comparator<String> PLZ_COMPARATOR = String.CASE_INSENSITIVE_ORDER;

  public GeodataPlzByPlzComparator() {
    super();
  }

  @Override
  public int compare(GeodataPlz one, GeodataPlz another) {
    if (nonNull(one) && nonNull(another)) {
      return PLZ_COMPARATOR.compare(one.getPlz(), another.getPlz());
    }

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

      return -1;
    }

    return 1;
  }
}
