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

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

import de.ivu.elect.business.gruppe.entity.Gruppe;
import de.ivu.elect.util.NullComparator;

public class GruppeByNameComparator<G extends Gruppe> implements Comparator<G>, Serializable {

  private static final long serialVersionUID = 1L;

  public static final Comparator<Gruppe> ASCENDING = new GruppeByNameComparator<>();

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

  // WASDE-1334
  private static final GruppeNamenComparator GRUPPE_NAMEN_COMPARATOR = GruppeNamenComparator.DEFAULT_INSTANCE;

  private GruppeByNameComparator() {
    super();
  }

  @Override
  public int compare(Gruppe one, Gruppe another) {
    if (one != null && another != null) {
      return GRUPPE_NAMEN_COMPARATOR.compare(one, one::getName, another, another::getName);
    }

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