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

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

import de.ivu.elect.business.person.entity.Beruf;
import de.ivu.elect.util.CaseAndDiacriticIgnoringComparator;

public class BerufByNameComparator implements Comparator<Beruf>, Serializable {

  private static final long serialVersionUID = 1L;

  private static final Comparator<String> NAME_COMPARATOR = CaseAndDiacriticIgnoringComparator.DEFAULT_INSTANCE;

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

    if (one == null) {
      if (another == null) {
        return 0;
      }

      return -1;
    }

    return 1;
  }

  private int compare(String one, String another) {
    return NAME_COMPARATOR.compare(one, another);
  }
}
