예제 #1
0
  /**
   * Comparator for sorting.
   *
   * @param fuelLogEntry
   * @return -1 if this is before the provided entry, 0 if equal, and 1 if greater.
   */
  public int compareTo(FuelLogEntry fuelLogEntry) {

    if (this.year < fuelLogEntry.getYear()) return -1;
    else if (this.year > fuelLogEntry.getYear()) return 1;
    else {
      if (this.month < fuelLogEntry.getMonth()) return -1;
      else if (this.month > fuelLogEntry.getMonth()) return 1;
      else {
        if (this.day < fuelLogEntry.getDay()) return -1;
        if (this.day > fuelLogEntry.getDay()) return 1;
        else {
          return 0;
        }
      }
    }
  }