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

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

import de.ivu.elect.business.gruppe.control.GruppeNamenComparator;
import de.ivu.elect.business.wahlvorschlag.entity.Wahlvorschlag;
import de.ivu.elect.util.NullComparator;

public class WahlvorschlagKennwortComparator implements Comparator<String>, Serializable {

  private static final long serialVersionUID = 1L;

  public static final WahlvorschlagKennwortComparator DEFAULT_INSTANCE = new WahlvorschlagKennwortComparator();

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

  public WahlvorschlagKennwortComparator() {
    super();
  }

  public int compare(Wahlvorschlag one, Wahlvorschlag another) {
    if (one != null && another != null) {
      return DEFAULT_COMPARATOR.compare(one, one::getKennwort, another, another::getKennwort);
    }

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

  @Override
  public int compare(String one, String another) {
    return DEFAULT_COMPARATOR.compare(one, another);
  }
}
