Пример #1
0
  /**
   * Initialize a FillUp based on a set of ContentValues. This is likely to be used when saving a
   * new FillUp into the database. By initializing the data before sending, we can perform sanity
   * checks to make sure that there isn't anything weird with the data before we commit it to the
   * database.
   *
   * @param values A ContentValues mapping of the data to load.
   */
  public FillUp(ContentValues values) {
    this((CalculationEngine) null);

    Double price = values.getAsDouble(PRICE);
    if (price != null) {
      setPrice(price);
    }

    Double odometer = values.getAsDouble(ODOMETER);
    if (odometer != null) {
      setOdometer(odometer);
    }

    Long time = values.getAsLong(DATE);
    if (time != null) {
      setDate(time);
    }

    Double amount = values.getAsDouble(AMOUNT);
    if (amount != null) {
      setAmount(amount);
    }

    Double latitude = values.getAsDouble(LATITUDE);
    if (latitude != null) {
      setLatitude(latitude);
    }

    Double longitude = values.getAsDouble(LONGITUDE);
    if (longitude != null) {
      setLongitude(longitude);
    }

    String comment = values.getAsString(COMMENT);
    if (comment != null) {
      setComment(comment);
    }

    Long vehicleId = values.getAsLong(VEHICLE_ID);
    if (vehicleId != null) {
      setVehicleId(vehicleId);
    }

    Integer isPartial = values.getAsInteger(PARTIAL);
    if (isPartial != null) {
      setPartial(isPartial == 1);
    }
  }
Пример #2
0
 /**
  * Set odometer in string format, so that patterns can be parsed out (such as the '+' prefix
  * notation. Note that if you are using this feature, the caller needs to set the vehicle ID
  * before calling this in order to get the previous odometer value! Also, remember that this
  * method is not free, due to the additional database lookup(s)!
  *
  * @param odometer The string representing the odometer value
  */
 public void setOdometer(String odometer) throws NumberFormatException {
   if (m_vehicleId < 0) {
     throw new IllegalStateException(
         "Need to set vehicle ID before calling setOdometer(String odometer)!");
   }
   if (odometer.startsWith("+")) {
     // m_odometer must be maxed out for getPrevious() to work.
     m_odometer = Double.MAX_VALUE;
     FillUp previous = getPrevious();
     if (previous == null) {
       setOdometer(odometer.substring(1));
       return;
     }
     m_odometer = previous.getOdometer() + Double.parseDouble(odometer.substring(1));
   } else {
     m_odometer = Double.parseDouble(odometer);
   }
 }