class TranslationComparator implements Comparator<Translation> {

  @Override
  public int compare(final Translation o1, final Translation o2) {
    if (o1 == o2) {
      return 0;
    }

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

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

    if (o1.getLang().equals(o2.getLang())) {
      return o1.getValue().compareTo(o2.getValue());
    }

    if (o1.getLang().equals(Language.of(""))) {
      return -1;
    } else if (o2.getLang().equals(Language.of(""))) {
      return 1;
    }

    if (o1.getLang().equals(Language.of("_"))) {
      return -1;
    } else if (o2.getLang().equals(Language.of("_"))) {
      return 1;
    }

    if (o1.getLang().getLang().startsWith("<")) {
      return -1;
    } else if (o2.getLang().getLang().startsWith("<")) {
      return 1;
    }

    return o1.getLang().compareTo(o2.getLang());
  }

}