
package de.ivu.elect.jee.presentation.dynamictable;

import java.util.Comparator;

import javax.inject.Named;

import de.ivu.elect.util.CaseAndDiacriticIgnoringComparator;
import de.ivu.elect.util.NullComparator;

@Named(ColumnEntrySortByValueStringComparator.COMPONENT_NAME)
public class ColumnEntrySortByValueStringComparator implements Comparator<Object> {

  public static final String COMPONENT_NAME = "columnEntrySortByValueStringComparator";

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

  public ColumnEntrySortByValueStringComparator() {
    super();
  }

  @Override
  public int compare(Object one, Object another) {
    if (one != null && another != null) {
      return DEFAULT_COMPARATOR.compare(one.toString(), another.toString()); // ELECT-13061
    }

    return NullComparator.NON_NULL_BEFORE_NULL_COMPARATOR.compare(one, another);
  }
}
