Skip to content

Commit 5f9f69c

Browse files
committed
util: add getFirstTrainrunSection(trainrun: Trainrun)
Signed-off-by: Louis Greiner <greiner.louis@gmail.com>
1 parent c322bb8 commit 5f9f69c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/app/services/data/trainrun.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,21 @@ export class TrainrunService {
696696
};
697697
}
698698

699+
getFirstTrainrunSection(trainrun: Trainrun): TrainrunSection | undefined {
700+
const sections = this.trainrunSectionService.getAllTrainrunSectionsForTrainrun(
701+
trainrun.getId(),
702+
);
703+
if (sections.length === 0) {
704+
return undefined;
705+
}
706+
// sections[0] does not ensure to be the first section in the trainrun
707+
const iterator = this.getBackwardIterator(sections[0].getTargetNode(), sections[0]);
708+
while (iterator.hasNext()) {
709+
iterator.next();
710+
}
711+
return iterator.current().trainrunSection;
712+
}
713+
699714
getFirstNonStopTrainrunSection(trainrunSection: TrainrunSection): TrainrunSection {
700715
// starts at the target node, goes backwards to find the first section that is not a non-stop section
701716
const iterator = this.getBackwardNonStopIterator(

0 commit comments

Comments
 (0)