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

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

import de.ivu.elect.business.datei.control.DateiImportByImportiertAmComparator;
import de.ivu.elect.business.datei.entity.DateiImport;
import de.ivu.elect.business.dokumente.entity.DokumentVorlage;
import de.ivu.elect.util.NullComparator;

public class DokumentVorlageByImportiertAmComparator implements Serializable, Comparator<DokumentVorlage> {

  private static final long serialVersionUID = 1L;

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

  private static final Comparator<DateiImport> DATEI_IMPORT_COMPARATOR = DateiImportByImportiertAmComparator.ASCENDING;

  public static final Comparator<DokumentVorlage> ASCENDING = new DokumentVorlageByImportiertAmComparator();

  public static final Comparator<DokumentVorlage> DESCENDING = Collections.reverseOrder(ASCENDING);

  public DokumentVorlageByImportiertAmComparator() {
    super();
  }

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

    return NULL_COMPARATOR.compare(one, another);
  }

  private int compare(DateiImport one, DateiImport another) {
    return DATEI_IMPORT_COMPARATOR.compare(one, another);
  }
}
