
package de.ivu.elect.dokumente.stimmeingabe;

import java.util.Comparator;

import de.ivu.elect.util.NullComparator;

class StimmenDocumentByPositionComparator implements Comparator<AbstractStimmenDocument> {

  private static final Comparator<Object> NULL_COMPARATOR = NullComparator.NULL_BEFORE_NON_NULL_COMPARATOR;

  public StimmenDocumentByPositionComparator() {
    super();
  }

  @Override
  public int compare(AbstractStimmenDocument one, AbstractStimmenDocument another) {
    if (one == null || another == null) {
      return NULL_COMPARATOR.compare(one, another);
    }

    return compareByPosition(one.position, another.position);
  }

  private int compareByPosition(Long one, Long another) {
    if (one == null || another == null) {
      return NULL_COMPARATOR.compare(one, another);
    }

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