@Override
    public int compare(Trigger trig1, Trigger trig2) {

      Date t1 = trig1.getNextFireTime();
      Date t2 = trig2.getNextFireTime();

      if (t1 != null || t2 != null) {
        if (t1 == null) {
          return 1;
        }

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

        if (t1.before(t2)) {
          return -1;
        }

        if (t1.after(t2)) {
          return 1;
        }
      }

      int comp = trig2.getPriority() - trig1.getPriority();
      if (comp != 0) {
        return comp;
      }

      return trig1.getName().compareTo(trig2.getName());
    }