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

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

import de.ivu.elect.business.staat.entity.Staat;
import de.ivu.elect.util.CaseAndDiacriticIgnoringComparator;

public final class StaatByNameStaatsangehoerigkeitInlandZuerstComparator implements Comparator<Staat>, Serializable {

  private static final long serialVersionUID = 1L;

  private final Comparator<String> nameComparator;

  public StaatByNameStaatsangehoerigkeitInlandZuerstComparator() {
    this(Locale.getDefault());
  }

  private StaatByNameStaatsangehoerigkeitInlandZuerstComparator(Locale language) {
    super();

    this.nameComparator = new CaseAndDiacriticIgnoringComparator(language);
  }

  @Override
  public int compare(Staat one, Staat another) {
    if (one.matchesInland()) {
      return -1;
    }

    if (another.matchesInland()) {
      return 1;
    }

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

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