示例#1
0
 /**
  * Calculates the distance since the previous fill-up.
  *
  * @return the distance since the previous fill-up
  */
 public double calcDistance() {
   if (m_distance == 0D) {
     m_previous = getPrevious();
     if (m_previous == null) {
       // we're at the first fill-up, so there's nothing we can do
       return -1D;
     }
     m_distance = m_odometer - m_previous.getOdometer();
   }
   return m_distance;
 }
示例#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);
   }
 }