
package de.ivu.elect.business.ui.boundary;

import java.util.Comparator;

import de.ivu.elect.business.ui.entity.UITableColumnOrder;

public class UITableColumnOrderComparator implements Comparator<UITableColumnOrder> {

  public UITableColumnOrderComparator() {
    super();
  }

  @Override
  public int compare(UITableColumnOrder one, UITableColumnOrder another) {
    if (one == null && another == null) {
      return 0;
    }

    if (one == null) {
      return 1;
    }

    if (another == null) {
      return -1;
    }

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

  private int compare(Long one, Long another) {
    if (one == null && another == null) {
      return 0;
    }

    if (one == null) {
      return 1;
    }

    if (another == null) {
      return -1;
    }

    return one.compareTo(another);
  }
}
