Exemple #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;
        }
      }
    }
  }
Exemple #2
0
 @Override
 public boolean equals(Object object) {
   if (object == null || object.getClass() != getClass()) return false;
   else {
     // its a fuel log entry, check equality.
     FuelLogEntry fuelLogEntry = (FuelLogEntry) object;
     // check date is equal
     if (!this.getDate().equals(fuelLogEntry.getDate())) return false;
     // check station equal
     else if (!this.station.equals(fuelLogEntry.getStation())) return false;
     // check odometer equal
     else if (!this.getOdometer().equals(fuelLogEntry.getOdometer())) return false;
     // check grade equal
     else if (!this.getGrade().equals(fuelLogEntry.getGrade())) return false;
     // check amount equal
     else if (!this.getAmount().equals(fuelLogEntry.getAmount())) return false;
     // check unitCost equal
     else if (!this.getUnitCost().equals(fuelLogEntry.getUnitCost())) return false;
     // they are equal.
     else {
       return true;
     }
   }
 }