修改列车折返错误

This commit is contained in:
tiger_zhou 2023-11-07 16:45:24 +08:00
parent 3335dea0a6
commit bb26f1e944
1 changed files with 32 additions and 29 deletions

View File

@ -16,36 +16,39 @@ import java.util.Optional;
/**
* 车辆折返
*/
public class TurnBackService implements CalculateDiagram{
public class TurnBackService implements CalculateDiagram {
@Override
public Optional<StationDiagram> calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation){
if(trainInfo.isTurnBack()/* && Objects.equals(trainInfo.getTurnBackStatus(),TrainInfo.EXIT)*/){
if(StringUtils.equalsAny(trainInfo.getTurnBackStatus(),TrainInfo.TO,TrainInfo.STOP)){
//列车开向折返轨或停留在折返轨
StationDiagram sd = new StationDiagram(train);
sd.setShowTrainDiagram(false);
return Optional.of(sd);
}else if(Objects.equals(trainInfo.getTurnBackStatus(),TrainInfo.EXIT)){
//列车离开折返轨
StationDiagram sd = new StationDiagram(train,0F,true);
sd.setStartStation(train.getNextStation());
Station nextStopStation = diagramStation.findNext(train.getNextStation(),train.isRight());
sd.setEndStation(nextStopStation);
sd.setTurnBack(true);
return Optional.of(sd);
}else{
//列车正在准备折返
Station lastStation = diagramStation.findLastNotDepotStation(train.isRight());
Station preStation = diagramStation.findPre(lastStation,train.isRight());
StationDiagram sd = new StationDiagram(train,1F,true);
sd.setStartStation(preStation);
sd.setEndStation(lastStation);
sd.setTurnBack(true);
return Optional.of(sd);
}
@Override
public Optional<StationDiagram> calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation) {
if (trainInfo.isTurnBack()/* && Objects.equals(trainInfo.getTurnBackStatus(),TrainInfo.EXIT)*/) {
if (StringUtils.equalsAny(trainInfo.getTurnBackStatus(), TrainInfo.TO, TrainInfo.STOP)) {
//列车开向折返轨或停留在折返轨
StationDiagram sd = new StationDiagram(train);
sd.setShowTrainDiagram(false);
return Optional.of(sd);
} else if (Objects.equals(trainInfo.getTurnBackStatus(), TrainInfo.EXIT)) {
//列车离开折返轨
if (Objects.isNull(train.getNextStation())) {
return Optional.empty();
}
return Optional.empty();
StationDiagram sd = new StationDiagram(train, 0F, true);
sd.setStartStation(train.getNextStation());
Station nextStopStation = diagramStation.findNext(train.getNextStation(), train.isRight());
sd.setEndStation(nextStopStation);
sd.setTurnBack(true);
return Optional.of(sd);
} else {
//列车正在准备折返
Station lastStation = diagramStation.findLastNotDepotStation(train.isRight());
Station preStation = diagramStation.findPre(lastStation, train.isRight());
StationDiagram sd = new StationDiagram(train, 1F, true);
sd.setStartStation(preStation);
sd.setEndStation(lastStation);
sd.setTurnBack(true);
return Optional.of(sd);
}
}
return Optional.empty();
}
}