Пример #1
0
 public void dispose() {
   setKernel(null);
   setFinalDestination(null); // removes property change listener
   setFinalDestinationTrack(null); // removes property change listener
   CarTypes.instance().removePropertyChangeListener(this);
   CarLengths.instance().removePropertyChangeListener(this);
   super.dispose();
 }
Пример #2
0
  public void reset() {
    setScheduleItemId(getPreviousScheduleId()); // revert to previous
    setNextLoadName(NONE);
    setNextWait(0);
    setFinalDestination(getPreviousFinalDestination()); // revert to previous
    setFinalDestinationTrack(getPreviousFinalDestinationTrack()); // revert to previous
    if (isLoadGeneratedFromStaging()) {
      setLoadGeneratedFromStaging(false);
      setLoadName(CarLoads.instance().getDefaultEmptyName());
    }

    super.reset();
  }
Пример #3
0
 private void setReturnWhenEmpty() {
   if (getReturnWhenEmptyDestination() != null) {
     setFinalDestination(getReturnWhenEmptyDestination());
     if (getReturnWhenEmptyDestTrack() != null) {
       setFinalDestinationTrack(getReturnWhenEmptyDestTrack());
     }
     log.debug(
         "Car ({}) has return when empty destination ({}, {}) load {}",
         toString(),
         getFinalDestinationName(),
         getFinalDestinationTrackName(),
         getLoadName());
   }
 }
Пример #4
0
 /**
  * Updates all cars in a kernel. After the update, the cars will all have the same final
  * destination, load, and next load.
  */
 public void updateKernel() {
   if (getKernel() != null && getKernel().isLead(this)) {
     for (Car car : getKernel().getCars()) {
       car.setFinalDestination(getFinalDestination());
       car.setFinalDestinationTrack(getFinalDestinationTrack());
       car.setLoadGeneratedFromStaging(isLoadGeneratedFromStaging());
       if (CarLoads.instance().containsName(car.getTypeName(), getLoadName())) {
         car.setLoadName(getLoadName());
       }
       if (CarLoads.instance().containsName(car.getTypeName(), getNextLoadName())) {
         car.setNextLoadName(getNextLoadName());
       }
     }
   }
 }
Пример #5
0
 public void propertyChange(PropertyChangeEvent e) {
   super.propertyChange(e);
   if (e.getPropertyName().equals(CarTypes.CARTYPES_NAME_CHANGED_PROPERTY)) {
     if (e.getOldValue().equals(getTypeName())) {
       if (log.isDebugEnabled()) {
         log.debug(
             "Car ({}) sees type name change old: ({}) new: ({})",
             toString(),
             e.getOldValue(),
             e.getNewValue()); // NOI18N
       }
       setTypeName((String) e.getNewValue());
     }
   }
   if (e.getPropertyName().equals(CarLengths.CARLENGTHS_NAME_CHANGED_PROPERTY)) {
     if (e.getOldValue().equals(getLength())) {
       if (log.isDebugEnabled()) {
         log.debug(
             "Car ({}) sees length name change old: ({}) new: ({})",
             toString(),
             e.getOldValue(),
             e.getNewValue()); // NOI18N
       }
       setLength((String) e.getNewValue());
     }
   }
   if (e.getPropertyName().equals(Location.DISPOSE_CHANGED_PROPERTY)) {
     if (e.getSource() == _finalDestination) {
       if (log.isDebugEnabled()) {
         log.debug("delete final destination for car: ({})", toString());
       }
       setFinalDestination(null);
     }
   }
   if (e.getPropertyName().equals(Track.DISPOSE_CHANGED_PROPERTY)) {
     if (e.getSource() == _finalDestTrack) {
       if (log.isDebugEnabled()) {
         log.debug("delete final destination for car: ({})", toString());
       }
       setFinalDestinationTrack(null);
     }
   }
 }
Пример #6
0
 public void loadNext(Track destTrack) {
   setLoadGeneratedFromStaging(false);
   // update wait count
   setWait(getNextWait());
   setNextWait(0);
   // and the pickup day
   setPickupScheduleId(getNextPickupScheduleId());
   setNextPickupScheduleId(NONE);
   // arrived at spur?
   if (destTrack != null && destTrack.getTrackType().equals(Track.SPUR)) {
     updateLoad();
   } // update load optionally when car reaches staging
   else if (destTrack != null && destTrack.getTrackType().equals(Track.STAGING)) {
     if (destTrack.isLoadSwapEnabled() && getLoadName().equals(carLoads.getDefaultEmptyName())) {
       setLoadName(carLoads.getDefaultLoadName());
     } else if (destTrack.isLoadSwapEnabled()
         && getLoadName().equals(carLoads.getDefaultLoadName())) {
       setLoadEmpty();
     } else if (destTrack.isLoadEmptyEnabled()
         && getLoadName().equals(carLoads.getDefaultLoadName())) {
       setLoadEmpty();
     } // empty car if it has a custom load
     else if (destTrack.isRemoveCustomLoadsEnabled()
         && !getLoadName().equals(carLoads.getDefaultEmptyName())
         && !getLoadName().equals(carLoads.getDefaultLoadName())) {
       // remove this car's final destination if it has one
       setFinalDestination(null);
       setFinalDestinationTrack(null);
       // car arriving into staging with the RWE load?
       if (getLoadName().equals(getReturnWhenEmptyLoadName())) {
         setLoadName(carLoads.getDefaultEmptyName());
       } else {
         setLoadEmpty(); // note that RWE sets the car's final destination
       }
     }
   }
 }
Пример #7
0
  /**
   * Construct this Entry from XML. This member has to remain synchronized with the detailed DTD in
   * operations-cars.dtd
   *
   * @param e Car XML element
   */
  public Car(org.jdom2.Element e) {
    super(e);
    loaded = true;
    org.jdom2.Attribute a;
    if ((a = e.getAttribute(Xml.PASSENGER)) != null) {
      _passenger = a.getValue().equals(Xml.TRUE);
    }
    if ((a = e.getAttribute(Xml.HAZARDOUS)) != null) {
      _hazardous = a.getValue().equals(Xml.TRUE);
    }
    if ((a = e.getAttribute(Xml.CABOOSE)) != null) {
      _caboose = a.getValue().equals(Xml.TRUE);
    }
    if ((a = e.getAttribute(Xml.FRED)) != null) {
      _fred = a.getValue().equals(Xml.TRUE);
    }
    if ((a = e.getAttribute(Xml.UTILITY)) != null) {
      _utility = a.getValue().equals(Xml.TRUE);
    }
    if ((a = e.getAttribute(Xml.KERNEL)) != null) {
      Kernel k = CarManager.instance().getKernelByName(a.getValue());
      if (k != null) {
        setKernel(k);
        if ((a = e.getAttribute(Xml.LEAD_KERNEL)) != null && a.getValue().equals(Xml.TRUE)) {
          _kernel.setLead(this);
        }
      } else {
        log.error("Kernel " + a.getValue() + " does not exist");
      }
    }
    if ((a = e.getAttribute(Xml.LOAD)) != null) {
      _loadName = a.getValue();
    }
    if ((a = e.getAttribute(Xml.LOAD_FROM_STAGING)) != null && a.getValue().equals(Xml.TRUE)) {
      setLoadGeneratedFromStaging(true);
    }

    if ((a = e.getAttribute(Xml.WAIT)) != null) {
      try {
        _wait = Integer.parseInt(a.getValue());
      } catch (NumberFormatException nfe) {
        log.error("Wait count ({}) for car ({}) isn't a valid number!", a.getValue(), toString());
      }
    }
    if ((a = e.getAttribute(Xml.PICKUP_SCHEDULE_ID)) != null) {
      _pickupScheduleId = a.getValue();
    }
    if ((a = e.getAttribute(Xml.SCHEDULE_ID)) != null) {
      _scheduleId = a.getValue();
    }
    if ((a = e.getAttribute(Xml.NEXT_LOAD)) != null) {
      _nextLoadName = a.getValue();
    }
    if ((a = e.getAttribute(Xml.NEXT_WAIT)) != null) {
      try {
        _nextWait = Integer.parseInt(a.getValue());
      } catch (NumberFormatException nfe) {
        log.error(
            "Next wait count ({}) for car ({}) isn't a valid number!", a.getValue(), toString());
      }
    }
    if ((a = e.getAttribute(Xml.NEXT_PICKUP_SCHEDULE_ID)) != null) {
      _nextPickupScheduleId = a.getValue();
    }
    if ((a = e.getAttribute(Xml.NEXT_DEST_ID)) != null) {
      setFinalDestination(LocationManager.instance().getLocationById(a.getValue()));
    }
    if (getFinalDestination() != null && (a = e.getAttribute(Xml.NEXT_DEST_TRACK_ID)) != null) {
      setFinalDestinationTrack(getFinalDestination().getTrackById(a.getValue()));
    }
    if ((a = e.getAttribute(Xml.PREVIOUS_NEXT_DEST_ID)) != null) {
      setPreviousFinalDestination(LocationManager.instance().getLocationById(a.getValue()));
    }
    if (getPreviousFinalDestination() != null
        && (a = e.getAttribute(Xml.PREVIOUS_NEXT_DEST_TRACK_ID)) != null) {
      setPreviousFinalDestinationTrack(getPreviousFinalDestination().getTrackById(a.getValue()));
    }
    if ((a = e.getAttribute(Xml.PREVIOUS_SCHEDULE_ID)) != null) {
      setPreviousScheduleId(a.getValue());
    }
    if ((a = e.getAttribute(Xml.RWE_DEST_ID)) != null) {
      _rweDestination = LocationManager.instance().getLocationById(a.getValue());
    }
    if (_rweDestination != null && (a = e.getAttribute(Xml.RWE_DEST_TRACK_ID)) != null) {
      _rweDestTrack = _rweDestination.getTrackById(a.getValue());
    }
    if ((a = e.getAttribute(Xml.RWE_LOAD)) != null) {
      _rweLoadName = a.getValue();
    }
    addPropertyChangeListeners();
  }
Пример #8
0
 @Deprecated
 // available for old scripts
 public void setNextDestinationTrack(Track track) {
   setFinalDestinationTrack(track);
 }