中途添加计划车导致报错问题

This commit is contained in:
tiger_zhou 2023-11-16 15:45:18 +08:00
parent 618c8dc33c
commit 3d86ae0355
1 changed files with 80 additions and 75 deletions

View File

@ -10,79 +10,82 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class SortDiagramStation {
private List<Station> stationList;
public SortDiagramStation(Simulation simulation){
List<Station> list = simulation.getRepository().getListByType(MapElement.DeviceType.STATION,Station.class);
stationList = list.stream().sorted((o1, o2) -> Float.compare(o1.getKmPostVal(),o2.getKmPostVal()))
private List<Station> stationList;
public SortDiagramStation(Simulation simulation) {
List<Station> list = simulation.getRepository().getListByType(MapElement.DeviceType.STATION, Station.class);
stationList = list.stream().sorted((o1, o2) -> Float.compare(o1.getKmPostVal(), o2.getKmPostVal()))
// .filter(d->!d.isDepot())
.collect(Collectors.toList());
.collect(Collectors.toList());
}
public int findIndex(Station station) {
return IntStream.range(0, stationList.size()).filter(d -> Objects.equals(stationList.get(d).getCode(), station.getCode())).findFirst().getAsInt();
}
public Station findLastNotDepotStation(boolean isRight) {
int index = isRight ? stationList.size() - 1 : 0;
Station station = stationList.get(index);
if (station.isDepot()) {
station = findNotDepotStation(isRight, index - (isRight ? 1 : -1));
}
return station;
}
public int findIndex(Station station){
return IntStream.range(0,stationList.size()).filter(d-> Objects.equals(stationList.get(d).getCode(),station.getCode())).findFirst().getAsInt();
public Station findFirstNotDepotStation(boolean isRight) {
int index = isRight ? 0 : stationList.size() - 1;
Station station = stationList.get(index);
if (station.isDepot()) {
station = findNotDepotStation(isRight, index + (isRight ? 1 : -1));
}
return station;
}
public Station findLastNotDepotStation(boolean isRight) {
int index = isRight ? stationList.size() - 1 : 0;
Station station = stationList.get(index);
if (station.isDepot()) {
station = findNotDepotStation(isRight, index - (isRight ? 1 : -1));
}
return station;
private Station findNotDepotStation(boolean isRight, int index) {
Station station = stationList.get(index);
while (station.isDepot()) {
index += isRight ? -1 : 1;
station = stationList.get(index);
}
return station;
}
public Station findFirstNotDepotStation(boolean isRight) {
int index = isRight ? 0 : stationList.size() - 1;
Station station = stationList.get(index);
if (station.isDepot()) {
station = findNotDepotStation(isRight, index + (isRight ? 1 : -1));
}
return station;
}
private Station findNotDepotStation(boolean isRight, int index) {
Station station = stationList.get(index);
while (station.isDepot()) {
index += isRight ? 1 : -1;
station = stationList.get(index);
}
return station;
}
/*public Station findLastNotDepotStation(boolean isRight){
int index =isRight ? stationList.size() - 1 : 0 ;
Station station1 = stationList.get(index);
if(isRight){
if(station1.isDepot()){
return stationList.get(index - 1);
}
}else{
if(station1.isDepot()){
return stationList.get(index + 1);
}
}
return station1;
}
public Station findFirstNotDepotStation(boolean isRight){
int index = isRight ? 0 : stationList.size() - 1;
Station station1 = stationList.get(index);
if(isRight){
if(station1.isDepot()){
return stationList.get(index + 1);
}
}else{
if(station1.isDepot()){
return stationList.get(index - 1);
}
}
return station1;
}*/
public Station findNext(Station station,boolean isRight){
int index = this.findIndex(station);
int findIndex = isRight ? index + 1 : index - 1;
return this.findNotDepotStation(isRight,findIndex);
/*public Station findLastNotDepotStation(boolean isRight){
int index =isRight ? stationList.size() - 1 : 0 ;
Station station1 = stationList.get(index);
if(isRight){
if(station1.isDepot()){
return stationList.get(index - 1);
}
}else{
if(station1.isDepot()){
return stationList.get(index + 1);
}
}
return station1;
}
public Station findFirstNotDepotStation(boolean isRight){
int index = isRight ? 0 : stationList.size() - 1;
Station station1 = stationList.get(index);
if(isRight){
if(station1.isDepot()){
return stationList.get(index + 1);
}
}else{
if(station1.isDepot()){
return stationList.get(index - 1);
}
}
return station1;
}*/
public Station findNext(Station station, boolean isRight) {
int index = this.findIndex(station);
int findIndex = isRight ? index + 1 : index - 1;
return this.findNotDepotStation(isRight, findIndex);
/*if(isRight){
return this.findNotDepotStation(isRight,index + 1);
}else{
@ -90,20 +93,22 @@ public class SortDiagramStation {
return this.findNotDepotStation(isRight,index -1);
}*/
}
public Station findPre(Station station,boolean isRight){
int index = this.findIndex(station);
int findIndex = isRight ? index -1 : index +1;
return this.findNotDepotStation(isRight,findIndex);
}
public Station findPre(Station station, boolean isRight) {
int index = this.findIndex(station);
int findIndex = isRight ? index - 1 : index + 1;
return this.findNotDepotStation(isRight, findIndex);
/*if(isRight){
return this.findNotDepotStation(isRight,index - 1);
}else{
return this.findNotDepotStation(isRight,index + 1);
}*/
}
public Station find(Station station){
int index = this.findIndex(station);
return stationList.get(index);
}
}
public Station find(Station station) {
int index = this.findIndex(station);
return stationList.get(index);
}
}