中途添加计划车导致报错问题
This commit is contained in:
parent
618c8dc33c
commit
3d86ae0355
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue